79586260

Date: 2025-04-22 11:00:14
Score: 0.5
Natty:
Report link

In SQL Server:

  1. When a Primary Key is dropped, SQL Server:

    • Removes the NOT NULL constraint from the column if it was only enforced via the PK.

    • It does not automatically change any values to NULL.

  2. So how did the NULLs get there?

    • Those rows were probably already there, but the column had default values (e.g., autogenerated or inserted earlier).

    • Once you dropped the PK and altered the column to allow NULLs (or SQL Server did that for you), subsequent operations (like inserts) may have inserted NULL into those rows — especially if:

      • There was no default value set.

      • Your application/data import inserted rows without setting a value for that column.

What to do now:

🔹 1. Check how many NULLs you have:

SELECT COUNT(*)

FROM YourTableName

WHERE YourColumnName IS NULL;

2. Inspect some of those rows

SELECT* FROM YourTableName

WHERE YourColumnName IS NULL;

3. Remove them

Delete FROM YourTableName

WHERE YourColumnName IS NULL;

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: AKASH AWASTHI