Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 5th, 2005, 12:06 PM
punkyclairey punkyclairey is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 4 punkyclairey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!!

Reply With Quote
  #2  
Old January 6th, 2005, 06:56 AM
Dumbo Dumbo is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 29 Dumbo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 27 m 31 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Insert into table problem!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT