Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

how to add data to two table Expand / Collapse
Author
Message
Posted Tuesday, October 16, 2012 5:00 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, October 16, 2012 6:17 AM
Points: 2, Visits: 2
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.
Post #1373133
Posted Tuesday, October 16, 2012 5:20 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Saturday, May 31, 2014 9:19 PM
Points: 1,128, Visits: 1,162
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
Post #1373149
Posted Tuesday, October 16, 2012 5:26 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, July 17, 2014 6:47 AM
Points: 223, Visits: 1,718
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

Post #1373154
Posted Tuesday, October 16, 2012 5:28 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, July 4, 2014 3:55 AM
Points: 2,836, Visits: 5,062
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!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1373155
Posted Tuesday, October 16, 2012 5:51 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Saturday, May 31, 2014 9:19 PM
Points: 1,128, Visits: 1,162
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



~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one
Post #1373171
Posted Tuesday, October 16, 2012 6:18 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, October 16, 2012 6:17 AM
Points: 2, Visits: 2
sorry everyone i mean the coloumn and not table
Post #1373190
Posted Tuesday, October 16, 2012 6:54 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, July 4, 2014 3:55 AM
Points: 2,836, Visits: 5,062
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!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1373212
Posted Tuesday, October 16, 2012 2:07 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 7:29 PM
Points: 8,562, Visits: 9,063
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
Post #1373516
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse