MySQL语法大全(新)

所需积分/C币:28 2018-07-28 17:00:29 194KB PDF

MySQL语法最新修正版,内容包括从命令行连接MySQL,到导入.sql文件等。适用于有关MySQL开发的技术人员,日常帮助文档。
#先判断表是否存在存在先删除 drop table if exists student #创建表 create table student( id int auto increment primary key, name varchar(50) sex varchar (20) date varchar(50) content varchar(100) )default charset=utf8 删除表 drop table student; #查看表的结构 describe student;#可以简写为 desc student; 插入数据 insert into student values(null, aa 931988-10-211....) insert into student values(null, bb 1889-03-6,.. insert into student values(null, 'cc31889-08-8,1..) insert into student values(null,'dd't1889-12-8 ..) insert into student values(null, 'ee 3,1889-09-61...) insert into student values(null, 'ff, 'null,1889-09-6, ..) #查询表中的数据 select from student select id, name from student #修改某一条数据 update student set sex='55 where id=4 #删除数据 delete from student where id=5 #and且 select from student where date>1988-1-2'and date<1988 12-1; #or或 select from student where date < 1988-11-2' or date>1988-12- #between select from student where date between 1988-1-2' and 1988 12-1 #in查询制定集合内的数据 select from student where id in(1, 3, 5) #排序asC升序desc降序 select x from student order by id asc #分组查询#聚合函数 select max(id), name, sex from student group by sex select min(date) from student select avg(id)as求平均 from student select count(*) from student;#统计表中总数 select count(sex) from student;#统计表中性别总数若有一条数据 中sex为空的话,就不予以统计 select sum(id) from student #查询第条以后到第条的数据(不包括第条) select* from student limit25;#显示3-5条数据 巩固练习 create table c( id int primary key auto increment name varchar (10) not null sex varchar(50) # DEFAULT 93 age int unsigned,#不能为负值(如为负值则默认为0) sno int unique#不可重复 drop table c desc c insert into c( (d, name, sex, age,sno) values(nu涛哥,男,68,1) insert into c(id, name, sex, age,sno)values(null,'aa, 2, 68, 2) insert into c(d,name, sex,age sno) values(nu平平"男35,3) select x from c #修改数据 update c set age=66 where id=2, update c set name=花花,age=21,sex=女 where id=2 delete from c where age=21 #常用查询语句 select name, age id from c select x from c where age >40 and age 60, and select* from c where age <40 or age < 60: #or select from c where age between 40 and 60 #between select from c where age in(30486899);#in查询指定集合内 的数据 select* from c order by age deso;# order by(ac升序des降 序) #分组查询 select name max(age) from c group by sex;#按性别分组查年龄最 大值 #聚合函数 select min(age) from Cr select avg(age)as'平均年龄' from c select count(*) from o;#统计表中数据总数 select sum(age) from Cr #修改表的名字 #格式: alter table tbl name rename to new name alter table c rename to a #表结构修改 create table test id int not null auto increment primary key,#设定主键 name varchar(20) not null default noname',#设定默认值 department id int not null position id int not null, unique( department id, position id)#设定唯一值 修改表的名字 格式: alter table tbl name rename to new name alter table test rename to test rename #向表中增加一个字段(列) #RgIt alter table tablename add columnname type; /alter table tablename add (columnname type) alter table test add columnname varchar(20) 修改表中某个字段的名字 alter table tablename change columnname newcolumnname ype;#修改一个表的字段名 alter table test change name uname varchar(50) select from test #表 position增加列test alter table position add(test char (10)): #表 position修改列test alter table position modify test char(20)not null #表 position修改列test默认值 alter table position alter test set default system #表 position去掉test默认值 alter table position alter test drop default #表 position去掉列test alter table position drop column test #表 depart pos删除主键 alter table depart pos drop primary key #表 depart pos增加主键 alter table depart pos add primary key pk depart pos (department id, position id) #用文本方式将数据装入数据库表中(例如D/ mysql.txt) load data local infile D /mysql. txt" into table mytable #导入sq文件命令(例如D:/mysq.sql) source o:/ mysql.so#或者/.d:/ mysql.sq

...展开详情
试读 8P MySQL语法大全(新)
img

关注 私信 TA的资源

上传资源赚积分,得勋章
    最新推荐
    MySQL语法大全(新) 28积分/C币 立即下载
    1/8
    MySQL语法大全(新)第1页
    MySQL语法大全(新)第2页
    MySQL语法大全(新)第3页

    试读已结束,剩余5页未读...

    28积分/C币 立即下载 >