2017-3-10 SQL server T-sql语句 高级查询

来源:互联网 发布:mac终端修改时间date 编辑:程序博客网 时间:2024/05/16 09:57

条件修改:
update 表名 set 列名 = 值 where 列名 = 值
条件删除:
delete from 表名 where 列名 = 值
高级查询
条件查询
 查列 *改为要查看的列,多列逗号隔开
 筛选条件 where 列名 = >= <= > < 值 and or
模糊查询
select * from 表名 where 列名 like '%值%' %通配符
排序查询
select * from 表名 where order by 列名 asc / desc
去重查询
select distinct 列名 from 表名
分组查询
select 某一列名 from 表名 group by 对应的列名
子查询
将查询语句当做值来使用

 

alter table 外键表名 add constraint 约束名称 foreign key(外键字段) references 主键表名(约束列名)

 

如表A中的Ids是主键,要约束表B中的Aid列,那么语句应该是:

alter table B add constraint A_B_Ids foreign key(Aid) references A(Ids)

0 0