Você está na página 1de 3

create database student; use student; create table student_list(stu_name varchar(15),gender char(1),dept varchar(10)); desc student_list; insert into

student_list(stu_name, gender, dept) values(Anbu,M,ECE); Sslect * from student_list; create table student_list1(stu_name varchar(15) not null,gender char(1),dept varchar(10)); create table student_list2(stu_name varchar(15) not null,gender char(1),dept varchar(10)); create table student_list3(stu_name varchar(15) not null,income dec(3,2) not null default 1.00); insert into student_list3(stu_name,income)values(ASJDA,11); insert into student_list3(stu_name,income)values(BSDDB,22); insert into student_list3(stu_name,income)values(CSDA,33); insert into student_list3(stu_name,income)values(QA,44); insert into student_list3(stu_name,income)values(YREA\s,55);

select * from student_list3 where income<>11; select * from student_list3 where stu_name like %DA; select * from student_list3 where stu_name like _A; select * from student_list3 where income between 22 and 44; select * from student_list3 where not stu_name like C% and not stu_name like Q%; delete from student_list3 where income=44; update student_list3 set income=444 where income=44; update student_list3 set income=income+1; where income=11or income=22or income=33; show create table student_list3; create table student_list4(id int not null,name varchar(20),primary key(id)); create table student_list4(id int not null auto_increment,name varchar(20),primary key(id)); insert into student_list4(id,name)values(null,Ant); insert into student_list4(id,name)values(1,Ant); insert into student_list4(id,name)values(,Bear); insert into student_list4(id,name)values(Cat); insert into student_list4(id,name)values(88,Zebra); select * from student_list4 where id=1 or 2 or 3; use IN, instead of all ors select * from student_list4 where id in(1, 88); select * from student_list4 where id not in(1, 88); select id from student_list4 where not id between 2 and 4; update student_list4 set id=55,name=Ezhil;

alter table student_list4 add column age int not null auto_increment first,add primary key(age); alter table student_list4 add column income int after id; alter table student_list4 rename to studentlist4; alter table studentlist4 change column income salary int; alter table studentlist4 change column id st_id int,change column name st_name varchar(20); alter table studentlist4 modify column st_name varchar(25); alter table studentlist4 drop column st_id; create table loc(location varchar(10)); insert into loc values('chennai'); insert into loc values('chennai'); insert into loc values('madurai'); insert into loc values('salem'); insert into loc values('vellore'); select * from loc; alter table loc add column name varchar(10); update loc set name='aa' where location='chennai'; update loc set name='bb' where location='madurai'; update loc set name='cc' where location='salem'; update loc set name='dd' where location='vellore'; select * from loc; select right(location,2) from loc; select left(location,4) from loc; select substring_index(location,'a',1)from loc; select substring_index(location,'a',2)from loc; alter table loc add column state varchar(5); update loc set state=right(location,2); update loc set state=right('chennai',2); update loc set state=right('TN',2); update loc set state=right('TAMILNADU',2); update loc set state=case when location='chennai' then 'India' when name='bb' then 'India' else 'China' end; select location,name,state from loc where state like 'C%' and name='cc' order by state; select location,name,state from loc where state='China'order by state; select * from loc order by state; select * from loc order by name,state; select * from loc order by name desc; alter table loc add column no int not null auto_increment,add primary key (no);

select sum(no) from loc; select name,sum(no) from loc group by state; select *,avg(no) from loc; select *,avg(no) from loc group by state; select name,max(no) from loc; select name,min(no) from loc; select name,max(no) from loc group by state; select name,min(no) from loc group by state; select count(no) from loc; select distinct state from loc; alter table loc modify column state varchar(10); insert into loc(location,name,state) values('mumbai','ee','Russia'); select * from loc; select *,sum(no) from loc order by sum(no)desc limit 2; alter table loc add column salary int; update loc set location='chennai', name='ff',state='china',salary='300'where id=5; select *,sum(no) from loc group by state order by sum(no) desc limit 2; select *,sum(no) from loc group by state order by sum(no) desc limit 0,3; select * from aa limit 0,3; select * from aa limit 3,6;

COLUMN ALIASES: select location as loct from loc; CARTESIAN JOIN: select loc.location as ll,st.name as ss from loc cross join st;

Você também pode gostar