+ Reply to Thread
Results 1 to 5 of 5

copy of existing table and data

  1. copy of existing table and data

    My query is very simple, I am new to SQL.

    I want to create copy of existing table and data.
    Pls suggest a command !

    Thanks in advance
    Sanjay



  2. Re: copy of existing table and data

    Everything in the database? If so, I suggest backup and restore. If not, check out some of the tools
    at http://www.karaszi.com/SQLServer/inf...ate_script.asp

    --
    Tibor Karaszi, SQL Server MVP
    http://www.karaszi.com/sqlserver/default.asp
    http://sqlblog.com/blogs/tibor_karaszi


    "SANJAY PAWAR" wrote in message news:%23n7D6speHHA.3960@TK2MSFTNGP02.phx.gbl...
    > My query is very simple, I am new to SQL.
    >
    > I want to create copy of existing table and data.
    > Pls suggest a command !
    >
    > Thanks in advance
    > Sanjay
    >



  3. Re: copy of existing table and data

    Hello,

    SELECT * INTO NEW_TABLE FROM OLD_TABLE

    THis will copy the table structure and data into NEW_TABLE. You may need to
    craete the Indexes manually to NEW_TABLE.

    Thanks
    Hari


    "SANJAY PAWAR" wrote in message
    news:%23n7D6speHHA.3960@TK2MSFTNGP02.phx.gbl...
    > My query is very simple, I am new to SQL.
    >
    > I want to create copy of existing table and data.
    > Pls suggest a command !
    >
    > Thanks in advance
    > Sanjay
    >




  4. Re: copy of existing table and data

    Thanks for the prompt response.
    I think, i have failed to pass on my message.

    I want to create a new table using existing table with its structure and
    records.

    Sanjay

    "Tibor Karaszi" wrote in
    message news:OYKfdypeHHA.4300@TK2MSFTNGP02.phx.gbl...
    > Everything in the database? If so, I suggest backup and restore. If not,
    > check out some of the tools at
    > http://www.karaszi.com/SQLServer/inf...ate_script.asp
    >
    > --
    > Tibor Karaszi, SQL Server MVP
    > http://www.karaszi.com/sqlserver/default.asp
    > http://sqlblog.com/blogs/tibor_karaszi
    >
    >
    > "SANJAY PAWAR" wrote in message
    > news:%23n7D6speHHA.3960@TK2MSFTNGP02.phx.gbl...
    >> My query is very simple, I am new to SQL.
    >>
    >> I want to create copy of existing table and data.
    >> Pls suggest a command !
    >>
    >> Thanks in advance
    >> Sanjay
    >>

    >




  5. Re: copy of existing table and data

    Also...

    As well as indexes Primary Keys, Foreign Keys, CHECK constraints are not
    transferred, but Identities are!!! E.g

    CREATE TABLE MyMaster ( id int not null identity constraint PK_MyMaster
    PRIMARY KEY,
    Value int not null )

    CREATE TABLE Mydetail (
    id int not null identity constraint PK_Mydetail PRIMARY KEY,
    master_id int not null constraint FK_MyMaster FOREIGN KEY REFERENCES
    MyMaster ( id ),
    Value int not null CONSTRAINT CK_value CHECK ( value > 10 ))

    INSERT INTO MyMaster ( value )
    SELECT 1
    UNION ALL SELECT 2
    UNION ALL SELECT 3
    UNION ALL SELECT 4


    INSERT INTO Mydetail ( Master_id, value )
    SELECT 1, 100
    UNION ALL SELECT 2, 20
    UNION ALL SELECT 3, 30
    UNION ALL SELECT 4, 40
    UNION ALL SELECT 4, 400

    SELECT * INTO MyOtherMaster FROM MyMaster
    EXEC sp_help MyMaster
    EXEC sp_help MyOtherMaster


    SELECT * INTO MyOtherDetail FROM MyDetail
    EXEC sp_help MyDetail
    EXEC sp_help MyOtherDetail

    John

    "Hari Prasad" wrote:

    > Hello,
    >
    > SELECT * INTO NEW_TABLE FROM OLD_TABLE
    >
    > THis will copy the table structure and data into NEW_TABLE. You may need to
    > craete the Indexes manually to NEW_TABLE.
    >
    > Thanks
    > Hari
    >
    >
    > "SANJAY PAWAR" wrote in message
    > news:%23n7D6speHHA.3960@TK2MSFTNGP02.phx.gbl...
    > > My query is very simple, I am new to SQL.
    > >
    > > I want to create copy of existing table and data.
    > > Pls suggest a command !
    > >
    > > Thanks in advance
    > > Sanjay
    > >

    >
    >
    >


+ Reply to Thread