1)创建表 create table CREATE TABLE [schema.]table (columname datetype [, .]);
2)修改表 alter table "alter table<tablename> modefy (column)
add (column definition...)
drop column column"
3)截取表 truncate table truncate table <tablename>
4)查看表结构 desc <tablename>
5)删除表 drop table <tablename>
6)数据库操作语言 放置选择重复行 distinct
7)事物控制语言 提交并结束事物处理 commit
8)逻辑操作符 与列表中的值匹配 in
9)匹配字符模式 like
10)检查是否为空 is null
11)集合操作符 返回两个查询选定不重复的行 union(联合)
12)合并两个查询选定的所有行,包括重复的行 union all(联合所有)
13)返回两个查询都有的行 intersect(交集)
14)连接操作符 用于将两个或者多个字符串合并成一个字符串 || SELECT ('供应商'|| venname || '的地址是' || venaddress) FROM vendor_master
15)常用数据类型 char 固定长度字符串,长度 1~2000个字节
varchar2 可变长度字符串,长度 1~4000个字节
long 可变长度字符串,最多能存储 2GB
16)语法和数据对象 insert "INSERT INTO 表名(字段名1, 字段名2, ……) VALUES ( 值1, 值2, ……);
INSERT INTO 表名(字段名1, 字段名2, ……)
SELECT 字段名1, 字段名"
17)delete DELETE FROM表名 WHERE 条件
18)update UPDATE表名 SET 字段名1=值1, 字段名2=值2, …… WHERE 条件
19)查询语句嵌套 SELECT …… FROM (SELECT …… FROM表名1, [表名2, ……] WHERE 条件) WHERE 条件2;
20)分组查询 SELECT字段名1, 字段名2, …… FROM 表名1, [表名2, ……] GROUP BY字段名1 [HAVING 条件] ;
21)两个表之间的连接查询 SELECT 字段名1, 字段名2, …… FROM 表名1, [表名2, ……] WHERE 表名1.字段名 = 表名2. 字段名 [ AND ……] ;
22)索引 index
23)子查询 单行子查询 select * from emp where sal > (select sal from emp where empno = 7566);
24)多行子查询 select * from emp where sal > all(select avg(sal) from emp group by deptno);
select * from emp where sal > any(select avg(sal) from emp group by deptno);
select * from emp where job in (select job from emp where ename = 'MARTIN' or ename = 'SMITH');
25)exists select * from t1 where exists ( select null from t2 where y = x )
26)高级查询 处理空值排序 select * from emp order by comm desc nulls last(first);
27)查询跳过表中的偶数行 select ename from (select row_number() over (order by ename) rn,ename from emp) x where mod(rn,2)=1;
28)连续求和 select ename,sal,sum(sal) over(), sum(sal) over(order by ename) from emp;
sum(sal) over(order by ename)指的是连续求和.是以ename来排序的。若有两个这样的窗口函数,以后面的排序为主。
分部门连续求和 select deptno,sal ,sum(sal) over (partition by deptno order by ename) as s from emp;分部门连续求和
29)查询表中的所有字段 select * from all_tab_columns where table_name='EMP';
30)查出表的索引列 select * from sys.all_ind_columns where table_name='EMP';
31)改变表结构 修改字段 alter table table2 rename column result to result2
32)删除字段 alter table student drop column age
33)清空表中数据 Truncate table student;
34)删除表 drop table student
35)重命名表 rename student to student1
36)复制旧表结构: create table verifySlaves like slaves;
37)复制旧表结构和数据:insert into 新表 select * fron 旧表
38)查看旧表结构:desc slaves;
39)查看表结构: show create table slaves;
mysql常用命令
最新推荐文章于 2025-05-17 18:11:58 发布