|–> (Word)||–> (PDF)||–> (Epub)||–> (Text)|
|–> (XML)||–> (OpenOffice)||–> (XPS)|
|This article has been published 3 years, 292 days ago|
The estimated time to read this article is 3 minutes
This article has been read (599) times.
This article has been read (0) times today.
This article has been read (0) times this month.
This article has been read (0) times this year.
This article has 244 total words. (Including header)
This article has been updated on 12th July'12 at 8:00am
Follow @HeelpBook Tweet
In SQL Server there are two ways to add a column with a default value.
Add Default Value to Existing Column
ALTER TABLE [dbo].[Employees] ADD DEFAULT (getdate()) FOR [DateOfHire]
ALTER TABLE [dbo].[Employees] ADD DEFAULT ((0)) FOR [IsTerminated]
Add New Column with Default Value
ALTER TABLE Employees ADD DateOfHire datetime DEFAULT (GETDATE())
ALTER TABLE Employees ADD IsTerminated datetime DEFAULT (0)
Add Default Value with Create Table
CREATE TABLE [dbo].[Employees]
[EmployeeID] [int] IDENTITY(1,1) NOT NULL,
[FirstName] [varchar](50) NULL,
[LastName] [varchar](50) NULL,
[SSN] [varchar](9) NULL,
[IsTerminated] [bit] NOT NULL DEFAULT ((0)) ,
[DateAdded] [datetime] NULL DEFAULT (getdate()),
[Comments] [varchar](255) NULL,
[DateOfHire] [datetime] NULL