I wanted to create mockup schema based on existing database. I was trying to insert some simple data into pretty complex tables flooded with NOT NULL columns. Unfortunately in MS SQL there's no easy way how to disable NULL checks temporarily so I had to do it permanently. To simplify this task I've used following script generating set of ALTER TABLE commands that removes NULL checks from a table.
USE [YourDatabaseName]; SELECT 'ALTER TABLE [' + TABLE_SCHEMA + '].[' + TABLE_NAME + '] ALTER COLUMN [' + COLUMN_NAME + '] ' + DATA_TYPE + COALESCE('(' + CAST(CHARACTER_MAXIMUM_LENGTH AS VARCHAR) + ')', '') + ' NULL;' FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'YourTableSchema' AND TABLE_NAME = 'YourTableName' AND IS_NULLABLE = 'NO';
This is just a raw solution with few flaws that has to be solved by hand. For example alter commands are generated for identity columns which cannot exist without NULL check.