数据库基操
-- 创建数据库
create database 库名
-- 删除数据库
drop database 库名
-- 数据库名修改
alter database 修改前 modify name=修改后
字段操作
-- 添加字段
alter table 表名 add 字段名 数据类型
-- 删除字段
alter table 表名 drop column 字段名
--修改字段
execute sp_rename '表名.列名', '修改后列名'
concat连接
将字符串与字段连接
update customer set tel = concat('027-', tel), address = '武汉市' where address like '%武汉市%'
去重distinct
去掉重复的数据
select distinct customerID from customer
top排序去前方数据
倒序排列前三id数据
select top 3 * from customer order by customerID desc
多行子查询
in
当子查询返回多个数值时,则需要用in
去判断条件
select * from business.product where areaID in
(select customerID from customer where address = '武汉市')
all
声明:
本文采用
BY-NC-SA
协议进行授权,如无注明均为原创,转载请注明转自
N0tssss' Note
本文地址: T-SQL
本文地址: T-SQL