DEFAULT Constraints : Default « Constraints « SQL Server / T-SQL Tutorial






5>    CREATE TABLE Shippers
6>    (
7>       ShipperID      int   IDENTITY   NOT NULL
8>          PRIMARY KEY,
9>       ShipperName    varchar(30)      NOT NULL,
10>       DateInSystem   smalldatetime    NOT NULL
11>          DEFAULT GETDATE ()
12>    )
13> GO
1>
2>    CREATE TABLE Customers
3>    (
4>       CustomerNo     int     IDENTITY   NOT NULL
5>          PRIMARY KEY,
6>       CustomerName   varchar(30)        NOT NULL,
7>       Address1       varchar(30)        NOT NULL,
8>       Address2       varchar(30)        NOT NULL,
9>      City            varchar(20)        NOT NULL,
10>      State           char(2)            NOT NULL,
11>      Zip             varchar(10)        NOT NULL,
12>      Contact         varchar(25)        NOT NULL,
13>      Phone           char(15)           NOT NULL,
14>      FedIDNo         varchar(9)         NOT NULL,
15>      DateInSystem    smalldatetime      NOT NULL
16>    )
17>    GO
1>
2>    ALTER TABLE Customers
3>       ADD CONSTRAINT CN_CustomerDefaultDateInSystem
4>          DEFAULT GETDATE() FOR DateInSystem
5> GO
1>
2> drop table Shippers;
3> drop table Customers;
4> GO








7.6.Default
7.6.1.The syntax for defining a default
7.6.2.DEFAULT Constraints
7.6.3.Default int type value and default char type value
7.6.4.Using the system date as a default parameter.
7.6.5.Column with default random value
7.6.6.Insert to a table with default value
7.6.7.Designating Default Column Values: Assign Zeroes Instead of Null Values
7.6.8.Dropping Defaults