Day 3 Notes
Day 3 Notes
desc student;
insert into student(id,first_name,last_name,age,course_fee) values
(1,'Madhavi','Kumari',24,40000);
insert into student(id,first_name,last_name,age,course_fee) values
(1,'Madhavi','Kumari',24,40000);
AUTO-INCREMENT
insert into student(id,first_name,last_name,age,course_enrolled,course_fee) values
(2,'Sandhya','Devi',28,'Data Science',50000);
--- Throw error duplicate entry
Primary Key is used to recognize each record in a distinct manner, it will not
accept nulls and there can be only one Primary Key in a table.
Primary Key could be on multiple columns - Composite Primary Key.
___________________________________________________________________________________
____________________________
desc email_registration;
___________________________________________________________________________________
______________
DDL - Create, Alter, Drop, Truncate
DML - Insert, Update and Delete
DQL - Select
Select Statements-
select * from student; it gives all the columns and all the rows/tuples
select first_name, last_name from student; it gives selected columns and all the
rows/tuples
select first_name, last_name from student where course_fee>40000; it gives the
selected columns and rows meeting the where condition
select first_name, last_name from student where first_name = 'sandhya'; - by
default it is not case sensitive
select first_name, last_name from student where binary first_name = 'sandhya'; -
use the binary option to make it case sensitive
select * from student where first_name like '____'; give the names with exactly 4
characters in it
select * from student where first_name like 'a%'; give the names which have the
character 'a' in the first place
Update Statements-
update student set course_fee=35000 where course_enrolled = 'Data Analytics';
update student set course_fee = course_fee-5000;
update student set course_fee = course_fee+(course_fee*0.5) where course_enrolled =
"Data Analytics";
Delete Statements-
delete from student where first_name = 'Ravi'; - delete certian rows which meet
the conditions
delete from student; -deletes all the rows
___________________________________________________________________________________
______
DDL - Drop, Alter, Truncate
Alter Statement-
alter table student add column location varchar(30) not null default 'Hyderabad';
alter table student drop column location;
desc student;
alter table student modify column first_name varchar(50);
desc email_registration;
alter table email_registration drop primary key;
alter table email_registration add primary key(f_name,l_name);
alter table email_registration drop constraint email; --- drop the unique key
constraint
alter table email_registration add constraint unique key(email);