none
SQL - Create duplicate table with default valie RRS feed

  • Question

  • Dear Friends

    i use

    select * into indsalary from salary

    for create a duplicate table.

    indsalary is created as per salary structure, but default value is not copied.  why? how can i copy the default value.

    Pls help me

    C.Anburose

    Wednesday, October 24, 2018 5:46 AM

All replies

  • Hi,

    Select * into statement does not have such a function, just simple to generate the table, does not include the primary key, default value, etc.

    If you want to be the same as the source table, you can generate the Create Table script of the source table, modify the table name, key name, constraint name, etc., first create table2, and then use insert into table2 select * from table1 to copy the data.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, October 24, 2018 6:15 AM
  • The following is a slight twist to Alex's reply.

    First use DBCC CLONEDATABASE then populate data with INSERT INTO SELECT statement.

    https://support.microsoft.com/en-us/help/3177838/how-to-use-dbcc-clonedatabase-to-generate-a-schema-and-statistics-only


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, October 24, 2018 11:23 AM
    Moderator