I want to view the table creation statement in TDengine, So I execute the following sql:
SHOW CREATE DATABASE
However, it didn't display the entire row. How do I need to adjust it?
From your description, I think this is what you need.
SHOW CREATE DATABASE\G;
Related
I have two different databases. Let's say 'DbOne' and 'DbTwo'.
Is there any way to do the followings?
Create a view in DbOne
Transfer data in a particular table from DbTwo to the newly created view in DbOne.
I am using SSMS and still figuring out the appropriate query..
Please give me any advice.
You need INSERT / SELECT statement - eg.
INSERT INTO DbOne..NewView
SELECT * FROM DbTwo..SourceTable
However, depending on the structure of both tables, you may need to specify the particular columns in the SELECT statement, to match the structure of the target table. (By the way, note that data is always going into a TABLE - not a VIEW. You can do an INSERT into a VIEW, but only under certain conditions)
I just executed the following update statement on a view:
use [SERVER]
update [TABLE]
set USRN = 14201962
where COLUMN_UID = 4668083
Turns out there was a trigger that deleted that row entirely from the view instead of modifying that specific cell.
How can I get that row back? I'm assuming it might still be in the table that the row is associated with but I do not know what that table is. Is there a way for me to see which tables are part of the view so I can look through each one to try and locate the missing view row? Other suggestions are also welcome.
Thanks
You can right-click the view in SSMS and choose "Script As Create..." and see the query the view uses.
I am trying to update a table from one column to another column and once I executed the script, discovered that not all the rows updated. I was told I needed to write a SQL cursor to populate all missing rows on another table. Issue is, I am not sure how to form a cursor statement. All the how - tos I am reading are rather vague and don't explain anything. Would anyone have some basic hints on this?
Thanks!
Why do you need a cursor? If you want to insert missing tables from one table to another refer to the following post... Insert missing records from one table to another using mysql
I'd like to find out how to update a temporary table before I show the query. This is to avoid making permanent changes to the database.
So far I got the following:
WITH
new_salary AS
(SELECT ID,NAME,DEPT_NAME,SALARY FROM INSTRUCTOR WHERE DEPT_NAME='Comp. Sci.')
SELECT
*
FROM
new_salary
WHERE
DEPT_NAME='Comp. Sci.';
Now here is where it ends. I want to update this temporary table and show the updated version of that table as to avoid changing the actual database. All my attempts at using the UPDATE clause have failed so I am kind of dumbfounded :/
This part I am currently trying to do is not part of homework. It's just me who doesn't want to have to re-do the database over and over.
How would I go about doing this?
I guess you have two options:
You make a procedure, which first checks whether it needs to update the table. After calling that you execute the query.
You create a pipelined function, which does the checking and returning of the data. You could integrate this into the select like this (pipelined function name called pipelined_function_name):
select *
from table(pipelined_function_name)
;
Can I get the whole query which I used for creating a table, like we have sp_helptext to get the query of a stored procedure.
sp_helptext 'procedure_name'
Is there anything like this available for create table also in SQL server express?
I want to view the whole query which I wrote for creating a particular table and not the table structure.
Like if a deleted a table, and again want to create it, then I would have to type the whole query again, so I want a way through which I don't have to write the whole query again, like in mysql there is an option such as SHOW, which shows the table query?
In SQL Server Management Studio you can right-click on a table in the Object Explorer window and choose to generate the CREATE script into a new query window or put it in the clipboard or save it in a file.
Try sp_columns or sp_help. But this will not give you the CREATE TABLE text, you have to create this text for yourself.
You can also have a look at Catalog Stored Procedures