Results 1 to 2 of 2

Thread: Default Value

  1. #1
    Join Date
    Dec 2003
    Posts
    44

    Unanswered: Default Value

    How do you give a Column a default value when creating a DB Table?

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Code:
    USE Northwind
    GO
    
    CREATE TABLE myTable99(
    	  Col1 int IDENTITY(1,1)
    	, Col2 char(1)  DEFAULT 'Y'
    	, Col3 datetime DEFAULT GetDate()
    	, Col4 sysname DEFAULT USER
    	, Col5 varchar(255) 
    	, CONSTRAINT Col2_Check CHECK (Col2 IN ('Y','N'))
    	, CONSTRAINT Col1_PK PRIMARY KEY(Col1)
    )
    GO
    
    
    INSERT INTO myTable99(Col5) SELECT 'TEST ROW 1'
    
    SELECT * FROM myTable99
    GO
    
    DROP TABLE myTable99
    GO
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •