foreign key constraint in ms sql 1

foreign key constraint in ms sql

/*Creating Foreign Key Constraint*/
ALTER TABLE ForeignKeyTable ADD CONSTRAINT ForeignKeyTable_foreignKeyColumn_FK
FOREIGN KEY (foreignKeyColumn) REFERENCES PrimaryKeyTable (PrimaryKeyColumn)

Here is what the above code is Doing:
1. Creating a table called PrimaryKeyTable with a Primary Key column called PrimaryKeyColumn
2. Creating a table called ForeignKeyTable with a Foreign Key column called foreignKeyColumn
3. Creating a Foreign Key Constraint on the ForeignKeyTable table that references the PrimaryKeyTable table

Similar Posts