Adding Constraints in SQL
NOT NULL Constraint :
- Ensures that null values are not permitted for the column
- CREATE TABLE emp(employee_id numeric(6)CONSTRAINT emp_emp_id_pk PRIMARY KEY, first_name varchar(20) NOT NULL,...);
UNIQUE Constraint :- Unique constraint allow only unique values to be inserted in the column.
- No duplicates allowed e.g emailIDs
- CREATE TABLE emp(employee_id numeric(6) CONSTRAINT emp_emp_id_pk PRIMARY KEY, first_name varchar(20) NOT NULL, Email_id varchar(20) UNIQUE,...);
PRIMARY KEY Constraint :- Don’t allow duplicate values
- Don’t allow null values
- Only one primary key can be created per table
- CREATE TABLE emp(employee_id numeric(6) CONSTRAINT emp_emp_id_pk RIMARY KEY, first_name varchar(20),...);
FOREIGN KEY Constraint :- Defined at either the table level or the column level : continued in the next post
No comments:
Post a Comment