A primary Key is a
constraint uniquely identity each row in a table. It does create a
Cluster index by default. A primary key can have one or multiple column. You can have only 1 primary key per table. A primary cannot have NULL value.
NOT NULL is a
constraint that will not avoid any NULL value in a column.
Here an example when you create a table.
CREATE TABLE myTable
(
myTablePK INT PRIMARY KEY,
myTableNotNull INT NOT NULL
)
So let' try to insert a value in our table
example 1:
INSERT INTO myTable(NULL,2)
This will trow an error because the PK cannot be NULL.
example 2:
INSERT INTO myTable(1,2)
This will work cause myTablePK= 1 doesn't exist.
example 3:
INSERT INTO myTable(1,2)
This won't work because myTablePK= 1 already exist. PK must be unique.
example 4:
INSERT INTO myTable(2,NULL)
This won't work because myTableNotNull cannot be NULL.
example 5:
INSERT INTO myTable(2,2)
This will work !
Have a good week-end guys !