Define a default of zero for our Salary : sp_bindefault « System Functions « SQL Server / T-SQL Tutorial






9> CREATE TABLE Employees (
10>     EmployeeID int IDENTITY (1, 1) NOT NULL ,
11>     LastName nvarchar (20) NOT NULL ,
12>     FirstName nvarchar (10) NOT NULL ,
13>     Title nvarchar (30) NULL ,
14>     TitleOfCourtesy nvarchar (25) NULL ,
15>     BirthDate datetime NULL ,
16>     HireDate datetime NULL ,
17>     Address nvarchar (60) NULL ,
18>     City nvarchar (15) NULL ,
19>     Region nvarchar (15) NULL ,
20>     PostalCode nvarchar (10) NULL ,
21>     Country nvarchar (15) NULL ,
22>     HomePhone nvarchar (24) NULL ,
23>     Extension nvarchar (4) NULL ,
24>     Photo image NULL ,
25>     Notes ntext NULL ,
26>     Salary int NULL ,
27>     PhotoPath nvarchar (255) NULL
28>
29> )
30> GO
1>
2>    CREATE DEFAULT SalaryDefault
3>       AS 0
4> GO
1>    EXEC sp_bindefault 'SalaryDefault', 'Employees.Salary'
2>
3> GO
Default bound to column.
1>
2> drop DEFAULT SalaryDefault;
3>
4> drop table Employees;
5> GO
Msg 3716, Level 16, State 3, Server J\SQLEXPRESS, Line 2
The default 'SalaryDefault' cannot be dropped because it is bound to one or more column.








25.24.sp_bindefault
25.24.1.The system procedure sp_bindefault is used to bind the defined default value to specific columns.
25.24.2.Define a default of zero for our Salary