Click here to Skip to main content
15,921,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want when to use insert query empty fields get default value instead of null
Posted

Then define given columns to :
- not accept null values
- have a default one

Example :

SQL
CREATE TABLE Dummy (
   DummyId int NOT NULL IDENTITY(1,1)
  ,IntColumn int NOT NULL DEFAULT 0
  ,StringColumn nvarchar(8) NOT NULL DEFAULT ""
  ,StringColumn2 nchar(3) NOT NULL DEFAULT "xxx"
  ,DateTimeColumn datetime NOT NULL DEFAULT GETDATE()
  -- etc...
)
 
Share this answer
 
Hi,
add a default consraint to that column, either when creating the table:
SQL
CREATE TABLE CUSTOMERS(
       ID   INT              NOT NULL,
       NAME VARCHAR (20)     NOT NULL,
       AGE  INT              NOT NULL,
       ADDRESS  CHAR (25) ,
       SALARY   DECIMAL (18, 2) DEFAULT 5000.00,       
       PRIMARY KEY (ID)
);


or later:

SQL
ALTER TABLE CUSTOMERS
   MODIFY SALARY  DECIMAL (18, 2) DEFAULT 5000.00;


SQL - DEFAULT Constraint [^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900