SQL – Constraints

Prev     Next

  • SQL constraints are nothing but the rules which are applied to the data in tables.
  • Constraints are specified during creating a table or modifying a table. Constraints are used to make sure the data in a table / database are proper and reliable.
  • When the constraints/rules are not met by a data, actions like INSERT/UPDATE/ DELETE etc. will be aborted.
  • There are 2 types of constraints in SQL. They are,
  1. Column level constraints –These are applied to table columns only
  2. Table level constraints – There are applied on the whole table

List of Constraints in SQL:

Below are the list of constraints available in SQL. Please click on each topic to know more about them.

  1. NOT NULL
  2. CHECK
  3. DEFAULT
  4. UNIQUE
  5. PRIMARY KEY & COMPOSITE KEY
  6. FOREIGN KEY
  7. INDEX

Syntax for SQL Constraints (in CREATE TABLE):

Syntax for SQL Constraints CREATE TABLE table_name
(column_name1 data_type(size) constraint_name,
column_name2 data_type(size) constraint_name,
column_name3 data_type(size) constraint_name,
etc…);

Note: To ALTER existing constraints, please refer “SQL – ALTER TABLE” topic in this SQL tutorial to know how to add/modify columns and table properties.

Prev     Next

Share this website !!!
Facebook Twitter Linkedin

1. Online Compilers - Compile & Run your C/C++ programs:

✅ Online Compilers

2. Ask your questions or clarify your/others doubts from,

✅ Online Discussion Forums by Fresh2Refresh.com





Close
We Support JALLIKATTU !!!
We Support JALLIKATTU!
By Fresh2Refresh.com
Show Your Support as well. Thanks!