SQL Server Constraints in the table

A SQL Server Database could have multiple tables and each table that has to be stored based on some rules. These rules are the possible checks & conditions which allows you to ensure the data validations before it is being inserted into a specific table.

SQL Server Constraints Types

SQL server constraints can be divided primarily into :

  1. SQL Server Table level constraints
  2. SQL Server Column level constraints
S. NoSQL Server Constraint Table / Column LevelDescription
1NOT NULL Column LevelColumn value cannot be specified as NULL
2UNIQUEColumn Levelall values in the column need to be UNIQUE
3CHECKColumn Level all values in a column satisfies a specific condition
4DEFAULTColumn Levelspecifies a DEFAULT value for the column
5INDEXTable Levelapply indexes make the data retrieval fast
6 PRIMARY KEYColumn LevelUnique identifier for the column. Combination of NOT NULL and UNIQUE values
7 FOREIGN KEYColumn LevelIdentifies the Column with Unique values in another table referenced in another table.

SQL Server Constraints can be applied :

  1. Create Table
  2. Alter Table

Syntax: SQL Server ADD Constraints in Table

CREATE TABLE table_name (
table_col1 datatype constraint,
table_col2 datatype constraint,
table_col3 datatype constraint,n
….

table_col3 datatype constraint
);

CREATE TABLE oracleappshelpStudents
(
    StudentId 		INT 					IDENTITY PRIMARY KEY,
    UserId 			INT 					REFERENCES oracleappshelpUsers (UserId),
    Email 			VARCHAR(256) ,
	CreatedBy 			VARCHAR(128) 		NOT NULL,
	UpdatedBy 			VARCHAR(128) 		NOT NULL,
	CreatedDate			DATETIME			NOT NULL,
	UpdatedDate			DATETIME			NOT NULL
)

We will be discussing in separate blog for each Constraint . Please refer the below given links

http://oracleappshelp.com/2020/04/22/sql-server-unique-not-null-constraint-in-table/

http://oracleappshelp.com/2020/04/23/sql-server-primary-key-foreign-key-constraints-in-the-table/

http://oracleappshelp.com/2020/04/23/sql-server-constraint-check-default/

Bookmark and Share