Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3224566
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:14:18+00:00 2026-05-17T16:14:18+00:00

I am seeing too frequently not null primary key in scripts creating tables in

  • 0

I am seeing too frequently “not null primary key” in scripts creating tables in TSQL in blogs, articles, books, forums, here in SO, etc.

For example, BING gives 630,000 results ((just in English) if to search against “not null” NEAR “primary key” “sql server”:
http://www.bing.com/search?q=%22not+null%22+NEAR+%22primary+key%22+%22sql+server%22&go=&form=QBRE&filt=lf

I always perceived “NOT NULL” as inseparable part of definition of PRIMARY KEY, at least in SQL Server.
I tried to create a tables with Primary KEYs with and without “NOT NULL” in SQL Server but could not grasp the possible difference.

Why do all use “NOT NULL” for creating a primary key even in fast (short) illustrations?


Update:
How can NULL identify anything or be unique (as well as preventing multiple NULLs if one is permitted)? It is unspecified, missing, not applicable value

My question also implied subquestions:
if one defines “NOT NULL” for PK, why then UNIQUE is not specified?
And what is the definition of PK. IS it UNIQUE CONSTRAINT + NOT NULL or UNIQUE INDEX (then why NOT NULL)?
Plz give me link to msdn docs on it.

Update2: @Damien_The_Unbeliever

Why is not synonym without “NOT NULL”?

CREATE TABLE T3 
(
    PK int -- NOT NULL commented out
    , nonPK int -- to double-check my sanity 
    , constraint PK_vgv8 PRIMARY KEY (PK) on [PRIMARY]
) 

still does not permit NULL giving:


  • Microsoft SQL Server Management Studio


    No row was updated.

    The data in row 2 was not committed.
    Error Source: .Net SqlClient Data Provider.
    Error Message: Cannot insert the value NULL into column ‘PK’, table ‘TestData.dbo.T3’; column does not allow nulls. INSERT fails.

    The statement has been terminated.

    Correct the errors and retry or press ESC to cancel the change(s).


    OK Help


Update3:
This, concepts and terms definition, might appear as impractical nuisance.
It is not, some wrong statement (in the opinion of other(s) during communication/discussion) on a basic notion is enough to be considered a moron and create barriers in professional interaction and communication.

I forgot to tell, NOT NULL is scripted by SSMS for PK!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:14:19+00:00Added an answer on May 17, 2026 at 4:14 pm

    Edited for clarity

    According to the SQL Specification, a primary key can not contain NULL. This means that decorating a column with either “NOT NULL PRIMARY KEY” or just “PRIMARY KEY” should do the same thing. But you are relying on the SQL engine in question correctly following the SQL standard. As an example due to an early bug, SQL Lite does not correctly implement the standard and allows null values in non-integer primary keys (see sqlite.org/lang_createtable.html). That would mean for (atleast) SQLLite the two statements do two different things.

    As “NOT NULL PRIMARY KEY” clearly indicates intent and continues to enfore non-null values even if the primary key is removed, that should be the prefered syntax.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It's probably something simple I am not seeing because I've stared at it too
Update : My bad...I have an primary key on those tables..I meant no further
Q1: Is there something like too much ajax?? Explanation: I have been seeing programmers
Okay, the title is not saying too much, sorry. Essentially it's an Architecture Question
I'm seeing a bug/feature in my Ruby 1.9.2 applications. Any changes to views (not
This is complicated. I'm not too familiar with Access and I am a programmer
I basically have something like this: <div id=slide-1 style=display:none;> Not too important stuff </div>
I'm seeing an issue in IE7 and IE8 (but not other browsers) with a
I am seeing this message, too often when I try to refactor my code
Seeing various locking related question and (almost) always finding the 'loop because of spurious

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.