|
Custom Search
| |
|
How to Enforce Default Constraint and Nullability Constraint Default Constraint is defined by creating a default value for a column. The default constraint provides a default value when no value is provide when inserting a new record in the table. Each column can have only one default constraint. Default constraint can be altered or removed. For example, when inserting the record South Park Machinery, if we don't add a value for ContactName then the default value Unknown will be inserted automatically.
The example below illustrates how to add a DEFAULT constraint in Customers table.
Nullability Constraint Nullability Constraint is defined by allowing NULL or NOT NULL values for a column. It defines that when insert or update a column, null values (the absence of a value) are allowed. If NOT NULL is defined for a column, no null values can be saved in the column. In other words, a specific value which conforms to the data type defined for the column must be entered for each record. Note that NULL is not equal to empty or zero. Empty is a value of string type of data. Zero is a value of integer type of data. In practice, I always try to avoid using ALLOW NULL in a column. To deal with the situation where users don't provide a value for a record in the column, I create a meaningful default value where possible such as NA or 0. There are good reasons behind this practice of avoiding the use of NULLable columns.
Sometimes when providing a default value is not practical, we have to use ALLOW NULL.
On next page, we are going to look at How to enforce Primary Key constraint and Unique constraint. Other tutorials in this category 1. How to Design Relational Database |
Copyright © 2024 GeeksEngine.com. All Rights Reserved. This website is hosted by HostGator. No portion may be reproduced without my written permission. Software and hardware names mentioned on this site are registered trademarks of their respective companies. Should any right be infringed, it is totally unintentional. Drop me an email and I will promptly and gladly rectify it. |
Home | Feedback | Terms of Use | Privacy Policy |