Sunday, February 19, 2012

Copy the table structures of all the tables

CREATE TABLE table_name AS SELECT STATEMENT WHERE rownum = 0;
this query will copy the table structure of one table without copying the data. I need to copy the table structures of all the tables in a particular database without copying the data.
suggest me on this.any body from microsoft|||gee I almost worked for microsoft. is that good enough?

in SQL2k, right click on your database in the Enterprise Mangler and choose Generate SQL script.|||rownum = 0?

What version are you talking about|||SQL Server 2000|||SQL Server 2000
Are you running this statement in sql server 2000? I don't think so...

CREATE TABLE table_name AS SELECT STATEMENT WHERE rownum = 0;

Please check your requirement,
That will not work at all,but this will

SELECT TOP 0 * INTO NewTable FROM OldTable

well Thrasymachus has already given you the solution.|||You can try an app I wrote for this called scriptdb. It will create scripts for ALL objects, not just tables, a separate file for each.

the source is freely available so you can modify it to suit your needs if you know C#.

get it here: http://www.elsasoft.org/tools.htm

EDIT: and I used to be a dev on the ms sql team, but no longer. does that count? :)

No comments:

Post a Comment