1.创建数据库 create database 数据名
2.创建表 create table 表名(列名 列类型)
3默认值约束 create table 表名(列名 列类型 default 值)
4.check约束 create table 表名 (列名 列类型 check (表达式))
5.主键约束 create table 表名(列名 列类型 primary key)
6.外键约束 create table 表名(列名 列类型 foreign key references 主键表名(主键列名))
7.唯一约束 create table 表名(列名 列类型 unique)
8.查询 select 列名 from 表名//查看一个字段 select 列名1,列名2 from 表名//查看多个字段 select * from 表名//查看所有字段
条件 select * from 表名 where 条件
多重条件 select * from 表名 where 条件1 and(or) 条件2
查询中的字符连接 select '字符串'+列名1+'字符串'+列名2 from 表名//要实现字符相加,必须保证所引用的列名类型一致
别名 select 列名 as 别名 from 表名
显示行数 select top 显示的行数 列名 from 表名
聚合函数 sum 总合 select sum(列名) from 表名//列名必须为数值类型,并且返回值一定是单行单列数值
平均值 select avg(列名) from 表名//列名必须为数值类型,并且返回值一定是单行单列数值
行总数 select count(*) from 表名
最大值 select max(列名) from 表名
最小值 select min(列名) from 表名
分组 select 列名1 from 表名 group by 列名1
模糊查询 select * from 表名 where 列名 like '%值%'
在什么之内 select * from 表名 where 列名 in(值1,值2,值3)
在什么之间 select * from 表名 where 列名 between 值1 and 值2
自联 select a.电话 from 职员表 as a inner join 职员表 as b on a.部门=b.部门 and? b.姓名='张三' and a.职务='经理'
select 电话 from 职员表 where 职务='经理' and 部门 in(select 部门 from 职员表 where 姓名='张三')
插入数据 insert into 表名 values(值1,....) ?扩展 : insert into 表名(字段1,字段2) values(值1,值2)
修改数据
update 表名 set 字段1=值 where 条件
删除数据 delete from 表名 where 条件
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|