Definition of the primary foreign key in SQL Server:
1.
Create Table int Primary Key not NULL into Values (Ten, 'IT '), (+,' Finance'), (+, 'engneer ')
Create Table int Primary Key not NULL int Foreign Key References Dept (DEPT_NO))
The above notation, is the column level definition, defines the column field directly when defining foreign key
2.
create table Dept (dept_no int primary key , Dept_name nvarchar (+) not null Prmary key (dept_no)) Insert into dept values (10, ' IT ' ), (20, ' Finance ' ), (30, Engneer ' )
Create Table int Primary Key not NULL int,constraintforeignkeyreferences dept (DEPT_NO))
This is a table-level definition.
3. You have created a table that does not have a primary foreign key defined, you can use ALTER TABLE to modify
alter table employee add foreign key (DEPT_NO) references Dept (dept_no) alter table employeeadd constraint dept_no_fk Foreign key (dept_no) references Dept (dept_no)
Add primary Key
Alter Table Deptaddconstraintprimarykey(dept_no)
4. Remove the primary key
Alter Table Drop constraint
Remove foreign keys
Alter Table Drop constraint DEPT_NO_FK
The building was deleted, the building was deleted, the hand hurts originally intended to put the MySQL statement also written, the reason is that last night to read about the MySQL video, about check does not work, and their foreign key constraints are also vague, do not know how to write, the original is two ways of writing, which is to see the MySQL video to see. I'm going to have to write MySQL again sometime.