2

I have a SQL Server table. I need to create the same table in another database. How would I see what the Create Table query was that created the table so I can just run that.

    CREATE TABLE .. 
Nate Pet
  • 41,226
  • 116
  • 259
  • 398
  • Take a look at this post : http://stackoverflow.com/questions/21547/in-sql-server-how-do-i-generate-a-create-table-statement-for-a-given-table – aleroot Mar 08 '12 at 20:17
  • Do you really want the exact same table in another database? If there are FKs that could be a problem. It might be easier to query into the existing database. – rjdevereux Mar 08 '12 at 20:26

2 Answers2

5

In SSMS you can right click the table and select Script Table as Create to New Query Window.

Robert Kaucher
  • 1,811
  • 3
  • 21
  • 42
1

Let's assume SQL Server 2005 or greater, since you did not specify. In Management Studio, simply right-click on the table, select Script Table As --> Drop and Create --> To New Query Editor Window.

For SQL Server 2000, in Enterprise Manager, right-click the table and you'll have a similar option to script the table creation to a file. I forget the exact menu option text, but it's easy enough.

HardCode
  • 6,320
  • 4
  • 30
  • 53