Mega Code Archive

 
Categories / MSSQL / Constraints
 

Define Primary key and foreign key

1> CREATE TABLE Matches ( 2>    Society_Group_Id int NOT NULL , 3>    Match_Id         int IDENTITY (1, 1) NOT NULL PRIMARY KEY CLUSTERED, 4>    Points_Against   smallint NOT NULL 5> ) 6> GO 1> 2> CREATE TABLE Match_Scores ( 3>    Match_Id     int NOT NULL PRIMARY KEY CLUSTERED, 4>    Player_Id    int NOT NULL , 5>    Score_Points tinyint NULL 6> ) 7> GO 1> 2> ALTER TABLE Match_Scores 3>    ADD CONSTRAINT [FK_Match_Scores_Matches] FOREIGN KEY (Match_Id) 4>    REFERENCES [Matches] ([Match_Id]) 5> GO 1> 2> drop table Matches 3> GO 1> 2> drop table Match_scores 3> GO 1>