The Default Value of A Record: Default 'NSW', DEFAULT '2000', DEFAULT 'Australia'

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Microsoft SQL Server Topics: The Default Value of a Record

<a

href="http://c.casalemedia.com/c?s=56757&f=2&id=2055836723.9382691" target="_blank"><img src="http://as. casalemedia.com/s?s=56757&u=http%3A//functionx.com/sqlserver/records/default. htm&f=2&id=2055836723.9382691&if=0" width="728" height="90" border="0"></a>

The Default Value of a Record


Introduction
To specify the default value in a SQL statement, when creating the column, before the semi-colon or the closing parenthesis of the last column, assign the desired value to the DEFAULT keyword. Here are examples: CREATE TABLE Employees ( FullName VARCHAR(50), Address VARCHAR(80), City VARCHAR(40), State VARCHAR(40) >DEFAULT = 'NSW', PostalCode VARCHAR(4) DEFAULT = '2000', Country VARCHAR(20) DEFAULT = 'Australia' ); GO After creating the table, the user does not have to provide a value for a column that has a default. If the user does not provide the value, the default would be used when the record is saved.

Visually Creating a Default Value


You can create a default value of a column when creating a table. To specify the default value of a column, in the top section, click the column. In the bottom section, click Default Value or Binding, type the desired value following the rules of the column's data type: It the Data Type is Text-based (char, varchar, text, and their variants) Intructions Enter the value in single-quotes Enter the value as a number but following the rules of the data type. For example, if you enter a value higher than 255 for a tinyint, you would receive an error Enter the date as either MM/DD/YYYY or YYYY/MM/DD. You can optionally include the date in single-quotes. Enter the time following the rules set in the Control Panel (Regional Settings). Enter the value as 0 for FALSE or any other long integer value for TRUE

Numeric-based

Date or Time

Bit

Home

Copyright 2007 FunctionX, Inc.

file:///C|/Documents%20and%20Settings/michael.musyoki/Desktop/SS/default.htm11/26/2008 5:12:41 PM

You might also like