Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server - 'NOT NULL' Constraint redundant on Primary Key?

In the below SQL code is 'NOT NULL' redundant since f_ID is a primary key and thus can't be null for any record?

CREATE TABLE t_Activities(
    f_ID varchar(50) NOT NULL,
    PRIMARY KEY (f_ID))
like image 884
kernanb Avatar asked Oct 29 '25 22:10

kernanb


2 Answers

What if you later drop the primary key constraint? Should the column allow nulls or not after that? Yes, no, maybe? The two constraints are different. PK constraint requires a NOT NULL, but does not implies one.

like image 51
Remus Rusanu Avatar answered Oct 31 '25 15:10

Remus Rusanu


It may be redundant, but I prefer this method of creating a primary key (or Identity column). It shows that the person making the table understands and intends the column to be NOT NULL as well as the Primary Key for the table.

like image 31
Adam Wenger Avatar answered Oct 31 '25 13:10

Adam Wenger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!