sqlserver copy table structure

Today encounter a situation, it is to copy the table structure mssql table to the new table which, in the online search some information, the solution is as follows:

1, select * into the database name .dbo. The new table names from the database name .dbo. Original name of the table where 1 = 0

2, hit Oldtable -> All Tasks -> Generate SQL Scripts -> Options -> Select "Writing a primary key, foreign key, default values and check constraints script" -> Settings Format -> just check "for the each object is generated CREATE <Object> command "-> General -> preview -> then copy the SQL statement to see -> Off -> click on the toolbar tools -> SQL query analyzer - > paste -> is modified oldtable NewTable -> press F5 to execute -> complete

. 3, CREATE TABLE SELECT * FROM new table Old table WHERE 1 = 2 or new table CREATE TABLE LIKE old table

After measurement.

1, only copy table field, Remarks fields, default values, etc. are copied, however, and give up.

2, generate SQL scripts -> Options, this option did not find where, give up.

3, this is available on Oracle, in mssql is reported grammatical mistakes, give up.

Later, to find a solution on MSDN, as shown below, it has been tested and is available now to share out the following steps.

Copy the table
  1. Make sure you're connected to where you want to create a table in the database and select the database in the Object Explorer.

  2. In Object Explorer, right-click the "Table" and then click "New Table" .

  3. In Object Explorer, right-click the table you want to copy, then click the "Design" .

  4. Select the column in an existing table, in the "Edit" menu, click "Copy" .

  5. Switch back to the new table and select the first row.

  6. In the "Edit" menu, click "Paste" .

  7. In the "File" menu, click "Save name the Table" .

  8. In the "Select name" dialog box, type a name for the new table and click "OK" .

 

Reproduced in: https: //www.cnblogs.com/ushou/archive/2013/04/23/3037929.html

Guess you like

Origin blog.csdn.net/weixin_34044273/article/details/93162384