3) check constraint: ==================== => When we want to insert the data into the table based on the certain condition, then we need to use "check constraints". => we can use the check constraints for more than one column within the same table. => check constraints allowed to define in column level as well as in table level. Check constraints in column level: --------------------------------- Syntax: create table table-name ( col1 datatype, col2 datatype check (expression/condition), ...... ); Ex: create table products11 ( sno number(10), product_id int check(product_id > 0), product_name varchar2(50), product_price decimal(10,2) ); insert into products11 values(1,101,'Laptop',59999.00); Check Constraint at table level: -------------------------------- Syntax: create table table-name ( col1 datatype, col2 datatype, constraint identifier-for-constraint check(expression/condition) ); Note: ---- Check constraint allows the duplicated values and null values also for the corresponding columns in the table. create table products12 ( sno number(10), product_id int check(product_id > 0), product_name varchar2(50), product_price decimal(10,2), constraint ch_const check(product_price > 1) ); insert into products12 values(1,1212,'Smart Tv',9999.99); insert into products12 values(2,102102,'Mobile',19999.99); insert into products12 values(3,112212,'Chocolates',199); insert into products12 values(4,120120,'Speakers',9999.99); insert into products12 values(5,null,'Refrigirator',29999.99); insert into products12 values(6,122122,'Cooler',10000); select * from products12; in operator: ------------ => which we can use to check the membership whether the specified element/member is present in the group or not. => if present, in operator can return "true" otherwise, it can return "false". Ex: 'xyz' in ('abc','def','pqr') ==> false 'abc' create table products13 ( sno number(10), product_id int check(product_id > 0), product_name varchar2(50) check(product_name in ('smart phone','TV','Bluetooth','Laptop')), product_price decimal(10,2), constraint ch_const1 check(product_price > 1) ); insert into products13 values(1,112233,'TV',299); 4) Default Constraint: ====================== => When we want to insert the table data with default values we can use "default constraints". => we can allow to define the default constraint at only column level. Syntax: create table table-name ( col1 datatype default(default-value), col2 datatype ); create table employees10 ( employee_id int, employee_name varchar(50), designation varchar(30), location varchar(30), country varchar(20) default('India'), salary decimal(10,2) ); insert into employees10(employee_id,employee_name,designation,location,salary) values(102132,'Santosh','Fullstack Developer','Delhi',55000); insert into employees10(employee_id,employee_name,designation,location,country,salary) values(1012133,'Sathwik','Fullstack Developer','XYZ','USA',65000); insert into employees10(employee_id,employee_name,designation,location,country,salary) values(1012133,'Sathwik','Fullstack Developer','XYZ','USA',65000); insert into employees10(employee_id,employee_name,designation,location,country,salary) values(1012133,'Sathwik','Fullstack Developer','XYZ',null,65000); select * from employees10; Assignment: ----------- 1) Write a SQL query for enabling and disabling the check constraint. Syntax: alter table table-name enable constraint constraint-name; alter table table-name disable constraint constraint-name; 2) Write a SQL query for defining the check constraint for the existing table. Syntax: alter table table-name add constraint constraint-name check(expression); 3) Write a SQL query to accept the price of the product from the given range.