sql 基本语句:
删除:
delete from [表名] where [列名]=XX delete from [表名] where [列名] in (a,b,c,d)
插入:
insert into [表名](列名1,列名2) select a,b union c,d insert into [表名](列名1,列名2) values (a,b),(c,d)
查询:
select b.* from (select * from Relation_RoleFunction where RoleId={0}) a inner join (select * from [Function])b on a.FunctionId=b.FunctionId
降序排列:
select top 10 NId,NTitle,NPublishTime from dt_NewsInfo ORDER BY NId DESC
聚合函数:
select PType,Count(*) from dt_Product group by PType
更新:
update [表名] set [列名1]=a where [列名2] in (a,b,c) update [表名] set [列名1]=a,[列名2u]=b,[列名3]=c where 查询条件
创建表:
CREATE TABLE 学生信息( 学号varchar(14) IDENTITY(1,1) PRIMARY KEY,
姓名varchar(8) UNIQUE NOT NULL,
班级编号varchar(14) REFERENCES '班级信息',
年级int null,
性别varchar(2) CHECK(性别in ('男’','女’)),
民族varchar(20) DEFAULT '未知该生民族',
籍贯varchar(50))
修改表名:
EXEC sp_rename ‘oldname’,’newname’
创建索引:
CREATE INDEX mycolumn_index ON mytable (myclumn)