7 Replies - 1036 Views - Last Post: 05 April 2010 - 10:28 AM Rate Topic: -----

#1 mon mon  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 128
  • Joined: 31-December 09

error in syntax in database table

Posted 05 April 2010 - 08:54 AM


insert into S ( E , A , D) values (8,7,'I');
insert into S ( E , A , D) values(16,3,'K');
insert into S ( E , A , D) values(3,2,'J');
insert into S ( E , A , D) values(9,5,'M');
insert into S ( E , A , D) values(8,1,'L');


errors:

1) Msg 547, Level 16, State 0, Line 2
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__S__A__0425A276". The conflict occurred in database "mona", table "dbo.R", column 'A'.
The statement has been terminated.



2)Msg 547, Level 16, State 0, Line 3
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__S__A__0425A276". The conflict occurred in database "mona", table "dbo.R", column 'A'.
The statement has been terminated.


3)Msg 547, Level 16, State 0, Line 4
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__S__A__0425A276". The conflict occurred in database "mona", table "dbo.R", column 'A'.
The statement has been terminated.


4)Msg 547, Level 16, State 0, Line 5
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__S__A__0425A276". The conflict occurred in database "mona", table "dbo.R", column 'A'.
The statement has been terminated.



5)Msg 547, Level 16, State 0, Line 6
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__S__A__0425A276". The conflict occurred in
database "mona", table "dbo.R", column 'A'.
The statement has been terminated.

Is This A Good Question/Topic? 0
  • +

Replies To: error in syntax in database table

#2 Vomster  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 198
  • Joined: 15-May 08

Re: error in syntax in database table

Posted 05 April 2010 - 09:51 AM

It looks like you are trying to set values in a foreign key field that don't exist in the parent table.
Was This Post Helpful? 0
  • +
  • -

#3 mon mon  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 128
  • Joined: 31-December 09

Re: error in syntax in database table

Posted 05 April 2010 - 09:55 AM

what i do
can you see this link
http://www.dreaminco...in-syntax/page_My linkhttp://www.dreamincode.net/forums/topic/166099-error-in-syntax/page__p__979525__fromsearch__1&#entry979525_p__979525__fromsearch__1&#entry979525

This post has been edited by mon mon: 05 April 2010 - 09:57 AM

Was This Post Helpful? 0
  • +
  • -

#4 keakTheGEEK  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 107
  • View blog
  • Posts: 344
  • Joined: 23-February 10

Re: error in syntax in database table

Posted 05 April 2010 - 09:59 AM

View PostVomster, on 05 April 2010 - 08:51 AM, said:

It looks like you are trying to set values in a foreign key field that don't exist in the parent table.


Also, if you do have the foreign key field in your parent table you need to make sure that the record exists there before you try to reference it in the other table you are inserting...
Was This Post Helpful? 0
  • +
  • -

#5 mon mon  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 128
  • Joined: 31-December 09

Re: error in syntax in database table

Posted 05 April 2010 - 10:06 AM

errors:
Msg 1779, Level 16, State 0, Line 1
Table 'S' already has a primary key defined on it.

Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.

Alter table S
add foreign key(A)references R(A)

Alter table S
add primary key (E)
 

insert into S ( E , A , D) values (8,7,'I');
insert into S ( E , D) values(16,'K');
insert into S ( E , D) values(3,'J');
insert into S ( E , D) values(9,'M');
insert into S ( E , A , D) values(8,1,'L');

Was This Post Helpful? 0
  • +
  • -

#6 keakTheGEEK  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 107
  • View blog
  • Posts: 344
  • Joined: 23-February 10

Re: error in syntax in database table

Posted 05 April 2010 - 10:13 AM

That error is because you already created the primary key for S when you created the table. You're trying to add it again with your alter statement.

Sounds like you really need to get up to speed on your Primary/Foreing key relationships. If you just try to add them without really having a solid plan and design for your database, you will run into issues that you don't understand continuously...

Check out this tutorial:
SQL Table Relations, Primary and Foreign Keys, and Normalization
Was This Post Helpful? 1
  • +
  • -

#7 mon mon  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 128
  • Joined: 31-December 09

Re: error in syntax in database table

Posted 05 April 2010 - 10:20 AM

because i beginning in database
i not understand primary key and foreign key correctly
and i read toturial but not understand
so i will read your link
and tables i have
not have names clearly but litters

This post has been edited by mon mon: 05 April 2010 - 10:23 AM

Was This Post Helpful? 0
  • +
  • -

#8 mon mon  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 128
  • Joined: 31-December 09

Re: error in syntax in database table

Posted 05 April 2010 - 10:28 AM

i have two tables have two columns similar
so i can't determine foreign key and primary key
you show tables (R,S)yesterday

This post has been edited by mon mon: 05 April 2010 - 10:29 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1