Copy Existing Table Structure To Existing Table

  • Database = sql server 2005 express edition

    i want to copy Existing table structure of one table to another Existing table.

    why i want to do it?

    i made a software and almost 50 clients are using that software

    my clients started working on that software and input huge data in it.

    now i was working to improve my software and i added some new constraints, triggers, keys, indexes , procedures , views and functions in my database.

    Now function , views and procedures were easy to script and i did that using sql create script method and ran that script on my client's database.

    but i don't know how to copy triggers, constraints, primary keys and indexes.

    i cant use select * into method as i have used identity columns in my database and if i use select * into it will create new ids for my table and the links to other tables will be destroyed.

    and doing it manually is hell of a job soooooo can any one pls tell me how to either copy whole structure of a table or to copy triggers, indexes etc

  • in SQL Server Management Studio, have you tried right clicking on the table and selecting "Script Table As ..."

    Then you can rename the table and the constraints that are part of the definition(so they are unique again).

    let us know if that works for you.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • thanks for the reply

    yes i have checked it and it adds constraints but no triggers or indexes.

    and this is a create method i cant create a new table and rename it

    cause if i do so how am i going to copy customers data in new table and if i use insert tsql to insert data the identity column's data will be change as it will start identity all over again which links to other child tables.

    i know alter changes column name or data types but i dnt know how to add triggers or indexes.

    i have attached a screen shot of a database diagram just to make it easier kindly check it

  • go to the scripting options and check "script indexes" "script "triggers" and anything else you might need scripted,a nds simply rerun the process.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • wow 🙂 that worked well

    thanks for the help bro

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply