Reputation: 586
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))
Upvotes: 4
Views: 2316
Reputation:
That is correct. If you had:
CREATE TABLE t_Activities(
f_ID varchar(50),
PRIMARY KEY (f_ID))
It would be the equivalen. The Primary Key constraint does not allow NULL
s.
Upvotes: 1
Reputation: 294217
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.
Upvotes: 4
Reputation: 17540
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.
Upvotes: 1