how to add data to two table

  • i want to add three table to the datbase out of which two are from one table and one is of another table can anyone please help me with the same.

  • santoshupadhayay87 (10/16/2012)


    i want to add three table to the datbase out of which two are from one table and one is of another table can anyone please help me with the same.

    Its' not clear what you are are trying to convey ...

    ~ demonfox
    ___________________________________________________________________
    Wondering what I would do next , when I am done with this one :ermm:

  • select into will make new table with the same column name and datatype, if you add false condition then only data schema will be copied without ady data

    select * into NEWTABLE from OLDTABLE where 1=0

  • santoshupadhayay87 (10/16/2012)


    i want to add three table to the datbase out of which two are from one table and one is of another table can anyone please help me with the same.

    Do you really think it's possible to answer? That sound like:

    Go to somewhere, I don't know where. And bring me something, I don't know what!

    However here is the trick:

    SELECT TOP (50) PERCENT * INTO NewTable1

    FROM MyOldTable1

    SELECT * INTO NewTable2

    FROM MyOldTable1 ot1

    WHERE NOT EXISTS (SELECT 1

    FROM NewTable1 nt1

    WHERE nt1.[UniqueIdColumn(s)] = ot1.[UniqueIdColumn(s)])

    SELECT * INTO NewTable3

    FROM MyOldTable2

    The above will split data from MyOldTable1 roughly in two half's and create two new tables from you old one 🙂

    And then create third new table from your second old one.

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • Eugene Elutin (10/16/2012)


    santoshupadhayay87 (10/16/2012)


    i want to add three table to the datbase out of which two are from one table and one is of another table can anyone please help me with the same.

    Do you really think it's possible to answer? That sound like:

    Go to somewhere, I don't know where. And bring me something, I don't know what!

    A good one :hehe:

    ~ demonfox
    ___________________________________________________________________
    Wondering what I would do next , when I am done with this one :ermm:

  • sorry everyone i mean the coloumn and not table

  • santoshupadhayay87 (10/16/2012)


    sorry everyone i mean the coloumn and not table

    That is much much more clear. 😉

    Now it's kind of:

    Go to somewhere, but not there, and I still don't know where.

    And bring me something, but not this thing, and I still don't know what!

    Do you want similar answer?

    What you really should do is:

    Please, follow the link at the bottom of my signature. There you will find tips about how to post question on this forum to get most relevant and quickest help.

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • Are you trying to add two columns to one table and one table to another table?

    If so you wnat code like

    ALTER Table1 add ColA type1 columnConstraints1, ColB type2 columnConstraints2;

    ALTER Table2 add ColC type 3 columnConstraints3;

    Obviously you have to provide the right tablenames, columnnames, and types, and also the right column constraints (if you want any). And if you add a column with column constraints that include a NOT NULL domain constraint it must also have a DEFAULT constraint (except that if the table is empty when you add the column you don't have to have a default for it if you don't want one).

    Tom

Viewing 8 posts - 1 through 7 (of 7 total)

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