Skip to content
Advertisement

SQL Server: Drop all Not Null constraints in all DB tables

How do I drop all Not Null Constraints in All Columns in every table using SQL Server ?

Would like to loop run this query in all tables and columns, How to remove not null constraint in sql server using query

Note: requirement is for all non-primary key columns.

Similar Question:

How to drop all Foreign Key constraints in all tables?

Advertisement

Answer

You can use the following query to generate the alter statements for each column. And use the generated statements to alter table. This won’t alter the primary key columns, but it doesn’t take into account other foreign key constraints.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement