SQL Constraint

SQL constraints are used to enforce rules on the data stored in a database. Some common constraints are:

  1. NOT NULL: This constraint specifies that a column cannot contain a NULL value. Syntax:

Example:

  1. UNIQUE: This constraint specifies that the values in a column must be unique. Syntax:

Example:

  1. PRIMARY KEY: This constraint specifies that a column is a primary key. A primary key is a unique identifier for a row in a table. Syntax:

Example:

  1. FOREIGN KEY: This constraint specifies that a column references the primary key of another table. Syntax:

Example:

  1. CHECK: This constraint specifies a condition that a column must meet. Syntax:

Example:

  1. DEFAULT: This constraint specifies a default value for a column. Syntax:

Example:

  1. CREATE INDEX: This statement creates an index on a column or set of columns. An index is used to improve the performance of queries by allowing the database to quickly find the rows that match a query. Syntax:

Example:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top