SQL Query: Copy a Table structure from a existing Table
Tip: The SELECT INTO statement can be used to create a new, empty table using the schema of another. Just add a WHERE clause that causes the query to return no data:
SELECT *
INTO newtable
FROM table1
WHERE 1=0;
INTO newtable
FROM table1
WHERE 1=0;
Note that this will not copy indexes, keys, etc.
If you want to copy the entire structure, you need to generate a Create Script of the table. You can use that script to create a new table with the same structure. Then, you can also dump the data into the new table if you need to.
If you are using Enterprise Manager, just right-click the table and select copy to generate a Create Script.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home