Send Us a Sign! (Contact Us!)
SQL Server - Add Column Default Value –> (Word) SQL Server - Add Column Default Value –> (PDF) SQL Server - Add Column Default Value –> (Epub) SQL Server - Add Column Default Value –> (Text)
SQL Server - Add Column Default Value –> (XML) SQL Server - Add Column Default Value –> (OpenOffice) SQL Server - Add Column Default Value –> (XPS)
This article has been published 1 year, 284 days ago
The estimated time to read this article is 3 minutes

SQL Server – Add Column Default Value
  • 0.00 / 5 5
0 votes, 0.00 avg. rating (0% score)

In SQL Server there are two ways to add a column with a default value.

Add Default Value to Existing Column
  • Add default to existing column DateOfHire:
  • ALTER TABLE [dbo].[Employees] ADD  DEFAULT (getdate()) FOR [DateOfHire]
  • Add default value to existing column IsTerminated
  • ALTER TABLE [dbo].[Employees] ADD  DEFAULT ((0)) FOR [IsTerminated]
    Add New Column with Default Value
  • Add new column DateOfHire with default
  • ALTER TABLE Employees ADD DateOfHire datetime DEFAULT (GETDATE())
  • Add new column IsTerminated with default
  • 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,
  • Add default of zero
  • [IsTerminated] [bit] NOT NULL DEFAULT ((0)) ,
  • Add default of getdate()
  • [DateAdded] [datetime] NULL DEFAULT (getdate()),
    [Comments] [varchar](255) NULL,
    [DateOfHire] [datetime] NULL
    )

    SQL Server – Add Column Default Value
    • 0.00 / 5 5
    0 votes, 0.00 avg. rating (0% score)

    SOURCE

    LINK (sqlserverplanet.com)

    LANGUAGE
    ENGLISH
    SQL Server - Add Column Default Value SQL Server - Add Column Default Value
    Facebook Twitter Email Plusone Linkedin Stumbleupon Delicious Digg
    Add Comment Register



       
    © 2011 - 2013 HeelpBook - Today is: 23/4/2014 Last updated: April 26, 2012 at 14:15 pm Get helped -