set identity_insert students on;
insert into students(id,name,age,high,gender,cls_id)values('3','老李', 18, 188.88,'man', 0);
set identity_insert students off;
-- 修改表-修改字段:不重命名版
-- alter table 表名 modify 列名 类型及约束;
alter table students modify birthday date;
-- 修改表-修改字段:重命名版
-- alter table 表名 change 原名 新名 类型及约束;
alter table students change birthday birth date default "2000-01-01";
execute sp_rename 'students.birthday','birth';
alter table students alter column birthday date not null;
删除列要指定要说明column
alter table students drop birth;
alter table students drop column birth;
主键列是自动增长,DEFAULT 和 NULL 不允许作为显式标识值。
不支持rlike
两个字段相除保留小数,先将分子转换成浮点数或者小数
select round(convert(float,sum(age))/count(*), 2) from students;
select round(convert(float,sum(age))/count(*), 3) from students;
select round(cast(sum(age)as decimal(5,2))/count(*), 2) from students;
select gender,group_concat(name) from students where gender=1 group by gender;
select gender,
[name] = stuff((
select ',' + [name]
from students t
where t.gender = students.gender
for xml path('')) , 1 , 1 , '')
from students group by gender;
sql server里没有mysql中的limit语法,类似的功能是使用top来实现
select * from students where gender='男' limit 2;
select top 3* from students where gender='男';
select * from students where is_delete=0 limit (n-1)*m,m
select * from students limit 6,2; -- -----> limit (第N页-1)*每个的个数, 每页的个数;
select top m * from 表 where 主键 not in(select top ((n-1)*m) 主键 from 表)
select top 2 * from students where id not in(select top(3*2) id from students);