|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Insert into table problem!
Hi, I'm trying to add data to 14 tables, and I can insert data to some tables, but not others because of foreign key constraints....and the error message (for example):
Server: Msg 547, Level 16, State 1, Line 1 INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'fk_Gift_Notes'. The conflict occurred in database 'master', table 'Customer', column 'Customer_No'. The statement has been terminated. How do I get around this/what am I doing wrong? I can only insert data into 5/14 tables ![]() Thanx for your help!! |
|
#2
|
|||
|
|||
|
Try changing the order in wich you add records
I think the order in wich you try to add the data is wrong, you must first ad the data to the tables that have colums that are used for foreign keys.
e.g. you may have these 3 tables: products with pro_id, pro_name, pro_price customers with cus_id, cus_name, cus_address orders with ord_id, ord_date, cus_id orderlines with oli_id, ord_id, pro_id, oli_item Clearly I cannot add an orderline record if the corresponding order record, and product record do not exist So if I want to add an order for a new product (or customer) I must first add a record to the product (or customer) table then add the line to the orders table and then I can add the orderlines With 14 tables changing, you probably have a more complicated model, but it is still a question of finding the table(s) that have no dependencies (group A) and then finding the tables with only dependencies on the tables in group A and so on. The error code gives you a hint as to where you should look first, any table using customer_no |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > Insert into table problem! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|