jooShin
jooShin

Reputation: 140

SQL Server query making null control

I'm using SQL Server Management Studio. While inserting the data, if I insert less than the suggested columns - for example, there are 4 columns and I'm inserted only 2 pieces of data - then NULL will appear in the other 2 columns.

But when if the column data are protected from the null, do I have to give specific value that I do not want to put value? like 0 or '' something.

Is there any way to assign value automatically for other columns without null?

Upvotes: 2

Views: 77

Answers (1)

I A Khan
I A Khan

Reputation: 8869

In SQL Server Management Studio open your table in design mode and in default value or binding set your required value ..

like below

enter image description here

if you want to create table using query then you can use

CREATE TABLE YourTable
(
   P_Id int NOT NULL,
   Val1 varchar(255),
   Val2 varchar(255),
   Val3 varchar(255),
   Val4 varchar(255) DEFAULT 'YourDefault Value will be Here'
) 

In above example if you does not include val4 in your Insert statement, then in val4 'YourDefault Value will be Here' will be saved, and if you does not include val1, val2,val3 then Null will be saved

Upvotes: 2

Related Questions