Home

The Default Value of a Column

 

Introduction

Sometimes most records under a certain column may hold the same value although just a few would be different. In such a case, you can assist the user by automatically providing a value for that column. The user would then simply accept the value and change it only in the rare cases where the value happen to be different. To assist the user with this common value, you create what is referred to as a default value.

 

Creating a Default Value

When creating a column, to specify its default value, after specifying the other pieces of information of the column, type DEFAULT followed by an empty space and followed by the desired value. Here are examples:

SQL> CREATE TABLE Employees
  2  (
  3     EmployeeNumber nchar(6),
  4     FirstName nvarchar2(20) DEFAULT 'John',
  5     LastName nvarchar2(20) DEFAULT 'Doe',
  6     HourlySalary number(6, 2) DEFAULT 12.50
  7  );

Table created.

During data entry, 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.

Author Note If the user provides a value for a column that has a default value and then deletes the value, the default value rule would not apply anymore: The field would simply become empty
 
 
 
     
 

Home Copyright © 2009-2010 FunctionX, Inc.