March 16, 2017 at 3:44 am
I have a column for ID in remarks table which is linked to customers table ID column
The primary key is auto increment, but how to make foreign key auto incremental .
March 16, 2017 at 5:20 am
You don't.
Insert the row into the remarks table, obtain the ID assigned to that row, put that into the customer table.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 16, 2017 at 10:42 am
GilaMonster - Thursday, March 16, 2017 5:20 AMobtain the ID assigned to that row,
Wats this ID u meant here.
March 16, 2017 at 10:49 am
Unforutnatedba - Thursday, March 16, 2017 10:42 AMGilaMonster - Thursday, March 16, 2017 5:20 AMobtain the ID assigned to that row,Wats this ID u meant here.
The customer ID. From your original post, it appears you're saying that the remarks table has a foreign key that refers to the customer table. Thus the Customer ID field in the Remarks table needs to contain the ID for the assigned customer for that remark. It does not auto increment.
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
March 16, 2017 at 11:12 am
A foreign key is a link to a specific record in another table (or another record in the same table). Creating a foreign key field that is auto-incrementing would create a link to an arbitrary (and possibly non-existent) record, which would defeat the whole purpose of having a foreign key in the first place.
What problem are you trying to solve that you think that you need to do this?
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy