您现在的位置:首页 >> 前端 >> 内容

sql语法

时间:2016/11/28 9:24:00 点击:

  核心提示:mysql -u root -p进入数据库source d:/sql.sql导入数据show databases;显示数据库列表use shujuku进入数据库show tables;显示表列表des...
mysql -u root -p
进入数据库


source d:/sql.sql
导入数据


show databases;
显示数据库列表


use shujuku
进入数据库


show tables;
显示表列表


desc biao
查看表结构


select * from biao
显示表内容


create table biao(
字段名 类型 约束,
字段名 类型 约束
);
创建表


select * from emp where shuxin=1;
查询表中属性为1的条目


select * from emp order by empno ASC;
查询以 empno 升序排列列表


select * from emp order by empno DASC;
查询以 empno 降序排列列表


select ename,empno,deptno from emp where job='销售员'
查询工作为销售员的ename empno deptno属性


select * from emp where comm>sal;
查询属性comm大于属性sal的条目


select distinct job from emp where comm is not null;
找出 comm 不是空的 job 不能重复
(找出有奖金的工种)


select * from emp where comm is null or comm < 1000;
找出 comm 为空或者小于1000的条目
(无奖金或奖金低于1000的员工)


select * from emp where hiredate like '2000%';
模糊查询 hiredate 中含有2000的条目
(查询2000年入职的员工)


insert into table_name values();
insert into table_name (字段名1,字段名2) values (值1,值2);


update table_name set 字段名1 = 值1,字段名2 = 值2 where 条件



delete from table_name where 条件



4. select distinct * | 字段名 as 别名 | 聚集函数:count() sum() avg() max() min()
1. from table_name
2. where
< > != = <= >=
and or //and优先级高于or
in //在那几个选项范围内
between and //在区间内
like //模糊查询,占位符使用百分号(%) 或者 下划线(_)


3. gruop by 字段名 having 聚集函数条件判断
5. order by asc|desc
6. limit [index,[length]] //只有一个参数,表示,取前几个;两个参数,第一个是索引值,第二个是向后取值个数

Tags:SQ QL L语 语法 
作者:网络 来源:caiyuanyyy