How can I create a table from another table without copying any values from the old table?
Answers were Sorted based on User's Feedback
Answer / mohammadali.info
CREATE TABLE new_table
AS (SELECT * FROM old_table WHERE 1=2);
For example:
CREATE TABLE suppliers
AS (SELECT * FROM companies WHERE 1=2);
This would create a new table called suppliers that included all columns from the companies table, but no data from the companies table.
| Is This Answer Correct ? | 7 Yes | 3 No |
Answer / amit kumar sharma
Select * into newTable From oldTable where 1=2
The where condition 1=2 will never get true, so only the
column of table will appear and get copied to newTable.
If we remove the where condition table with data will copy
to newtable.
| Is This Answer Correct ? | 3 Yes | 0 No |
What is normalization and what are the advantages of it?
What is the difference between resultset and resultsetmetadata?
What are the different authentication modes in sql server? How can it be changed?
Can you please explain the difference between primary keys and foreign keys?
i have 4 tables.. T1, T2, T3, T4.. these tables have the same structure and they store the information entered in different years.. T1 stored 2002, T2 stored 2003, T3 stored 2004 and T4 stored 2005.. i want to copy contents in T1 to T2, T2 to T3, T3 to T4 and T4 to T1.. how do i do that? Temp tables cannot be used..
Does index slows down insert statements?
What is the difference between count and distinct count?
What is an expression in ms sql server?
How to restore performance issues and how to check?
Can I remove the default constraint columns in SQL SERVER?
What are the benefits and tasks of object explorer? : sql server management studio
Explain transaction server distributed transaction?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)