codesnout.com

SQL Constraints

Google Ads

SQL Constraints


SQL Sample Code - SQL Constraints.

Constraints are used to restrict the type of data that goes into a table.

There are a number of different types of ‘Constraints’;

Constraint Description
NOT NULL Enforces a column not to allow NULL values. (Not allowed to leave empty)
UNIQUE Ensures all values in a column are different.
PRIMARY KEY Primary key columns must contain unique values and a primary key column cannot contain NULL values. Only one column in a table can be a Primary Key
FOREIGN KEY Used to ensure referential integrity of the data.
CHECK Only allows values to be inserted that satisfy a defined criteria.
DEFAULT Defines a default value for a column.

Go to the related Constraint to learn more and see examples.

The constraints above can be specified:

  • When creating a table – CREATE TABLE
  • When altering a table – ALTER TABLE
  • To learn more about CREATE TABLE and ALTER TABLE go to the relevant section.

     


    Related SQL Sample Code:


    About Us | Privacy Policy | Contact Us | ©2010 Thunderousity Information Management Solutions | www.autosnout.com - Car Performance Statistics Website Utilising SQL | SQL Blog |

    SQL Home | SQL Intro | SQL SELECT Statement | DISTINCT | WHERE | SQL Wildcards | AND OR | IN | BETWEEN | LIKE | ORDER BY | GROUP BY | TOP | ALIAS | DELETE | INSERT | UPDATE | CREATE DATABASE | CREATE TABLE | ALTER | INNER JOIN | FULL JOIN | LEFT JOIN | RIGHT JOIN | UNION | CONSTRAINTS | NOT NULL| Aggregate Functions | SUM | AVG | COUNT | MAX | MIN | FIRST | LAST | GROUP BY | HAVING | LIMIT | Microsoft Access Data Types | MySQL Data Types | SQL Server Data Types | ASCII HTML Reference Sheet |