Day 4 - SQL Commands - YouTube
Day 4 - SQL Commands - YouTube
and Truncate)
Create a Department table with the names of all the departments in the company -
create table department(
dept_name varchar(30) primary key,
dept_head varchar(30)
);
Now try inserting a record with a deparment name that is not in the department
table -
insert into employee (f_nm,l_nm,age,dept) values
('priya','darshini',30,'HealthCare');
Suppose, there is no data in employee table with that department, then what would
happen -
delete from employee where dept = 'HR';
Now, the (delete from department where dept_name = "HR";) statement will work.
___________________________________________________________________________________
__________________________
CHECK Constraint:
Eg 2:
CREATE TABLE products ( product_no integer, name text, price numeric CHECK (price >
0) );
insert into products values(1,'apples',100.00),(2,'oranges',200.00);
select * from products;
insert into products values(3,'grapes',-100.00),(4,'plums',200.00); ---- new
row for relation "products" violates check constraint "products_price_check"
insert into products values(3,'grapes',150.00),(4,'plums',200.00);
___________________________________________________________________________________
___________________________
Alter Statement-
To Change the Data Type or Size or the DataType: ALTER TABLE table_name ALTER
COLUMN column_name TYPE datatype;
alter table student alter column first_name type varchar(50);