Click here to Skip to main content
15,888,060 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I had 2 tables with data..one table with column primarykey+identity key....how can i set this column as forign key to another table as forign key??????????
Posted

1 solution

Here is the sample code where 'album' and 'track' tables. Album ID is the primary identity column.

SQL
CREATE TABLE album(
  id int IDENTITY NOT NULL PRIMARY KEY,
  title VARCHAR(100),
  artist VARCHAR(100)
);

CREATE TABLE track(
  album int,
  dsk INTEGER,
  posn INTEGER,
  song VARCHAR(255),
  FOREIGN KEY (album) REFERENCES album(id)
);
 
Share this answer
 
Comments
Sandeep Mewara 24-Jun-12 3:38am    
Looks good. 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900