Jump to content

Recommended Posts

Posted

I have a tables  XYZ   , MON

 

i want to insert a ,b ,c in XYZ and       B,c,d in MON where  b in foriegn key..

 

 

using join how can insert into both tables at a time ?

 

a,b,c r values inserted into the table(XYZ).. like insert table name colo,colp, colq values 'a','b','c'

 

Can i insert both the values into those table in same script...with join statement 

  • Replies 45
  • Created
  • Last Reply

Top Posters In This Topic

  • suthivelu

    12

  • rapchik

    9

  • AFDBAbhimanini

    9

  • k2s

    6

Popular Days

Top Posters In This Topic

Posted

LTT

Posted

From which tables r u pulling cols a,b,c,d

those r values inserted into the table.. like insert table name colo,colp, colq values 'a','b','c'

Posted

those r values inserted into the table.. like insert table name colo,colp, colq values 'a','b','c'


Ne question inkocham clear ga cheppu mayya may be I am missing something
Posted

I have a tables  XYZ   , MON

 

i want to insert a ,b ,c in XYZ and       B,c,d in MON where  b in foriegn key..

 

 

using join how can insert into both tables at a time ?

 

a,b,c r values inserted into the table(XYZ).. like insert table name colo,colp, colq values 'a','b','c'

 

Can i insert both the values into those table in same script...with join statement 

Select ki join vinna kani.. Insert ki doubt eee broo.. avvadu anukunta,... 

 

Check this

 http://stackoverflow.com/questions/175066/sql-server-is-it-possible-to-insert-into-two-tables-at-the-same-time

Posted

Bhayya,

 

I don't think you can insert into two tables at the same time using a single sql statement.  You can do it using one transaction though.

 

sql server lo cheyyalev. You can do it in postgres.

 

 

Posted

I have a tables  XYZ   , MON

 

i want to insert a ,b ,c in XYZ and       B,c,d in MON where  b in foriegn key..

 

 

using join how can insert into both tables at a time ?

 

a,b,c r values inserted into the table(XYZ).. like insert table name colo,colp, colq values 'a','b','c'

 

Can i insert both the values into those table in same script...with join statement 

 

ok i guess ur trying to insert a,b,c,d into target table ABC below is the query;

 

insert into ABC(a, b, c, d)

select (a, b, c, d from XYZ, MON where XYZ.b = MON .b)

Posted

Select ki join vinna kani.. Insert ki doubt eee broo.. avvadu anukunta,... 

 

Check this

 http://stackoverflow.com/questions/175066/sql-server-is-it-possible-to-insert-into-two-tables-at-the-same-time

 

 

Bhayya,

 

I don't think you can insert into two tables at the same time using a single sql statement.  You can do it using one transaction though.

 

sql server lo cheyyalev. You can do it in postgres.

 

 

then what if one table is dependent on other.,..... it says 

 

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_T_Division_T_USERS". The conflict occurred in database "AMP_DBDev", table "dbo.T_USERS", column 'USER_ID'.
 
 
here the table which i am trying to insert is having a forieny key for  other table....which is empty on other table
Posted

 

then what if one table is dependent on other.,..... it says 

 

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_T_Division_T_USERS". The conflict occurred in database "AMP_DBDev", table "dbo.T_USERS", column 'USER_ID'.
 
 
here the table which i am trying to insert is having a forieny key for  other table....which is empty on other table

 

A, B ane tables vunnayi anukondi.. 

A has the primary key which is a foreign key in Table B.

 

 You cannot insert directly in table B because it will fail through a constraint error. Mundhu table A lo insert chesi then Table B lo insert cheyyali.. alane. you cannot delete from A without deleting from B.. 

 

Correct me if I am wrong..

Posted

Ne question inkocham clear ga cheppu mayya may be I am missing something

 

 

ok i guess ur trying to insert a,b,c,d into target table ABC below is the query;

 

insert into ABC(a, b, c, d)

select (a, b, c, d from XYZ, MON where XYZ.b = MON . B)

i might be not clear ...

 

 

Here is the thing...

Assume 3 blank tables

 

I am trying to insert the values into a table1 which is having a foriegn key in table 2 ...so when i try to insert value sinto 1...Its terminated saying

 

"The INSERT statement conflicted with the FOREIGN KEY constraint "FK_T_Division_T_USERS". The conflict occurred in database "AMP_DBDev", table "dbo.T_USERS", column 'USER_ID'.

The statement has been terminated.
 
then i try to insert in T2...it has key in T3...Same statement repeats.... so how to do this kind of insertion
 

"

Posted

A, B ane tables vunnayi anukondi.. 

A has the primary key which is a foreign key in Table B.

 

 You cannot insert directly in table B because it will fail through a constraint error. Mundhu table A lo insert chesi then Table B lo insert cheyyali.. alane. you cannot delete from A without deleting from B.. 

 

Correct me if I am wrong..

yes/....correct adhe chedham anukuntuna kani A table kuda C table ki linked undhi...so adhi allow cheyaledhu... 

 

its A---b --C--- A ..... so dentlo chesina conflict avuthundhi FK vala

Posted

i might be not clear ...

 

 

Here is the thing...

Assume 3 blank tables

 

I am trying to insert the values into a table1 which is having a foriegn key in table 2 ...so when i try to insert value sinto 1...Its terminated saying

 

"The INSERT statement conflicted with the FOREIGN KEY constraint "FK_T_Division_T_USERS". The conflict occurred in database "AMP_DBDev", table "dbo.T_USERS", column 'USER_ID'.

The statement has been terminated.
 
then i try to insert in T2...it has key in T3...Same statement repeats.... so how to do this kind of insertion
 

"

 

constraints tesesi insert chey after everything is inserted constraints pettu

Posted

 

then what if one table is dependent on other.,..... it says 

 

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_T_Division_T_USERS". The conflict occurred in database "AMP_DBDev", table "dbo.T_USERS", column 'USER_ID'.
 
 
here the table which i am trying to insert is having a forieny key for  other table....which is empty on other table

 

 

Bhayya,

 

You must Insert Data into the parent table, containing the Primary Key, before attempting to insert data into the child table containing the Foreign Key.
 
First parent table lo insert cheyyi primary key tho...and then foreign key unna table lo insert cheyyi
×
×
  • Create New...