1.insertinto tb_dept values('D4','公关部','Liming','010-82953306');2.altertable tb_employee altercolumn salary setdefault3500;3.selectcount(*)as'总人数'from tb_employee where
depton=(select depton from tb_dept where dname='销售部');4.createview v_emp asselect eno,ename,age,salary from tb_employee
where depton=(select depton from tb_dept where dname='采购部');5.createuser'Yaoming'@'localhost' identified by'abc123';
二、
1.selectsum(price)as total from tb_commodity where origin='北京'and cname='电视机';2.altertable tb_commodity dropcolumn desc1;3.insertinto tb_commodity(cname,ctype,origin,birth,price)values('钢笔','文具','上海','2012-12-25',25);
4.createview v_bjcommodity asselect*from tb_commodity
where origin='北京';5.createuse'client'@'localhost';grantselect(cno,cname)on tb_commodity to'client'@'localhost'withgrantoption;
constraint charger_id foreignKEY(charger_id)references ClassCharger(id)-- constraint 外键名称 foreign key (主键列)references 主表名称(主表列名称)--切记:作为外键一定要和关联主键的数据类型保持一致1.create tbale Dept1(
depton intprimarykey,
dname varchar(20),
higherdepton intdefaultnull,constraint fk_higher foreignkey(depton)references Dept2(depton));2.insertinto Dept2(depton,dname,higherdep`ton)values(9,'newdept','higherdepton');3.createview SJAVA asselect S.sno,S.sname,SC.grade from
S,SC,C where S.sno=SC.sno and C.cname='JAVA';4.update SC set SC.grade=90where
SC.sno=(select S.sno from S where S.sname='李红')and
SC.cno=(select C.cno from C where C.cname='DB');5.createuser'backupdb'@'localhost' identified by'backup';
五、
1.altertable tb_dept adduniqueindex idx_dept(deptname desc);2.insertinto tb_dept(depton,deptname)values('D4','营销部');3.select name as'姓名',2014-birth as 年龄 from tb_emp;4.createview v_dept(部门负责人姓名,姓名,学历,工资)asselect manager,name,education,salary from
tb_dept,tb_emp where tb_dept.depton=tb_emp.depton
and deptname='市场部';5.createuser'stud'@'localhost';grantselecton tb_emp to'stud'@'localhost'withgrantoption;
六、
1.update tb_book set price=42where bname='MySQL程序设计';2.createview v_book asselect*from tb_book
where publisher='高等教育出版社';3.select bname,publisher,price from tb_book where btype='计算机';4.altertable tb_book dropcolumn desc1;5.createuser'client'@'locathost';grantselect(bno,bname)on tb_book to'client'@'locathost'withgrantoption;
七、
1.altertable tb_student addcolumn ssex char(2)nulldefault'女';2.deletefrom tb_gs where tb_gs.sno=(select sno from tb_student where smajor='计算机');3.createview v_number(smajor,snumber)asselect
smajor,count(distinct tb_gs.sno)from tb_gs,tb_student
where tb_student.sno=tb_gs.sno groupby smajor;4.altertable tb_gs addconstraint fk_dept foreignkey(sno)references
tb_student(sno);altertable tb_gs addconstraint fk_dept foreignkey(sno)references
tb_student(sno);5.createuser'tmpuser'@'localhost' identified by'a12345';grantselect,inserton tb_group to'tmpuser'@'localhost'withgrantoption;
八、
1.altertable tb_book dropcolumn shopDate;2.update tb_reader set sex='女'where readerName='王依然';3.select readerName,bookNo from tb_reader,tb_borrow
where tb_reader.readerNo=tb_borrow.readerNo
and borrowDate>'2014-01-01';4.createview v_borrow(读者编号,借书总册数)asselect readerNo,count(readerNo)from tb_borrow groupby readerNo;5.loaddatainfile'backup.txt'intotable tb_reader1;
1.createtable Emp(empid intprimarykeyauto_increment,
empname char(20)characterset GB12312 notnull,
streetname varchar(50),
cityname varchar(30)notnulldefault'N/A');2.select cname as'课程名',max(grade)as'最高分数'from
Score groupby cname havingAvg(grade)>85;3.select name,stuid,sum(grade)as total from Student,Score
where Student.stuid=Score.stuid groupby stuid orderby total asc;4.createview StuView asselect name,cname,grade from Student,Score
where Student.stuid=Score.stuid;5.grantselect,updateon newtest.*to'abc'@'192.168.1.100';
十一、
1.update student set age='20'where stu_id=2;2.select name from student where sex='M'orderby age Asc;3.select name from student,ordering where student.id=ordering.id
and score<60;4.createuser'stu_user'@'localhost';grantselect,inserton student to'stu_user'@'localhost';5.insertinto ordering(id,cid)values(1,5);
十二、
1.createtable publisher(pub_id intprimarykeyauto_increment,
pub_name char(30)notnull,
pub_address char(30)notnull);2.altertable book addcolumn pub_post int;altertable book addconstraint FK_book_pub_post foreignkey(pub_post)references publisher(pub_id);3.insertinto student(stu_id,stu_name,stu_sex,stu_age)values(8,'试试','男',10);insertinto book(book_id,book_name,price,author)values(6,'发',65,'a啊大大');insertinto reading values(8,6,'wen');4.deletefrom reading where s_id=3;5.select b_name from book where b_id=3;
十三、
1.altertable 学生 addcolumn QQ varchar(20);2.altertable 选课 addconstraint FK_XH foreignkey(学号)references 学生(学号);3.select 学院名称,count(学号)as 总人数 from 学生 groupby 学院名称;4.select 学号,姓名,学院名称 from 学生,选课 where 课程名称='操作系统';5.createview V_信息学院学生(姓名,学号,出生日期)asselect 姓名,学号,出生日期 from 学生 where 学院名称='信息学院';
十四、
1.createindex index_选课学号 on 选课(学号);2.select 课程学分 from 课程 where 课程名称='操作系统';3.select 学号 from 选课 where 课程名称='操作系统'and
学号=(select 学号 from 选课 where 课程名称='C语言程序设计');4.createview V_成绩(课程名称,平均成绩)asselect 课程名称,round(AVG(成绩),2)from 选课 groupby 课程
orderbyAVG(成绩)DESC;5.createuser'test'@'localhost';grantallon xsxk.*to'test'@'localhost';
十五、
1.createtable S(
SNO intprimary ker auto_increment,
SName char(10),
Sex char(1),
Age int,);2.createindex in_stu on student(depton);3.select depton as 系别,avg(score)as 平均成绩 from
student groupby depton;4.select sid,sname,score from stdent where
stdent.depton=(select depton from dept where deptname='数学系');5.createuser'wang'@'192.168.2.12' identified by'test1234';