Create Script of table... with data?



    In SQL Server Management Studio, I can right-click a table and choose:


    Script Table as > CREATE To > New Query Editor Window


    When I run the script on another database, it creates the table without the data. Is there an option to bring the data (i.e. the contents of the table) along with the table definition?



    Tuesday, October 09, 2007 9:28 PM


All replies

  • You need to use the SELECT * INTO command, or use the Copy Database Wizard (right click on db > Tasks > Copy Database...

    Tuesday, October 09, 2007 11:04 PM
  • Best  method will be Backup /Restore. Take the backup and restore it with New Name. Select * into will create table but all other constraints of the tables (PK/FK/CK/Indexes) will be missing.. so it will not be the method you are looking for. As mentioned, Detach/attach or Copy database also can do the trick.


    From BOL

    E. Make a copy of a database using BACKUP and RESTORE

    This example uses both the BACKUP and RESTORE statements to make a copy of the Northwind database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY.

    BACKUP DATABASE Northwind 
       TO DISK = 'c:\Northwind.bak'
       FROM DISK = 'c:\Northwind.bak'
       FROM DISK = 'c:\Northwind.bak'
       WITH MOVE 'Northwind' TO 'c:\test\testdb.mdf',
       MOVE 'Northwind_log' TO 'c:\test\testdb.ldf'





    Wednesday, October 10, 2007 1:52 AM
  • You can download Database Publishing Wizard and install it.

    In Database Publishing Wizard you can script table with design and its datas.
    Wednesday, October 10, 2007 2:21 AM
  • Thank you very much... it was saved my time...
    Friday, August 28, 2009 7:00 AM