标签:row 回滚 wro public action OLE 指定 所有权限 所有权
C:\Users\asus\AppData\Roaming\Microsoft\SQL Server Management Studio\14.0\SqlStudio.bin
select * from Student s2 where SUBSTRING(s2.sname,2,1)=SUBSTRING(s2.sname,3,1)
1 创建用户
create login names with password='pwd' , default_database=test;
create user names for login names with default_schema=dbo;
2 增删改查授权
grant select,insert,UPDATE,DELETE on 表 to names
3 创建表
grant create table to names
GRANT ALTER ON SCHEMA::dbo TO names;
4 存储过程授权
GRANT EXECUTE ON 存储过程名 TO username
5 禁止对表授权
DENY UPDATE ON 表 TO username CASCADE;
6 回收权限
REVOKE DELETE ON 表 FROM username
7 删除表
truncate table a
delete from dbo.a
drop table a
8 修改列
alter table a add sa nvarchar(10) not null
Alter Table a Add Constraint PK_Course_Cno Primary Key(id)
ALTER TABLE a ALTER COLUMN id int
ALTER TABLE a DROP CONSTRAINT PK_a
alter table a drop column sa
9 创建一个简单的登录,登录名为:newlogin;登录密码:123456;默认数据库:master,默认数据库也可以不指定。
EXEC sp_addlogin 'newlogin','123456','master'
10 创建用户
EXEC sp_adduser 'newlogin'
EXEC sp_adduser 'newlogin','newuser'
EXEC sp_addrole 'newrole'
EXEC sp_adduser 'newlogin','newuser','newrole'
GRANT ALL ON jobs TO newrole
GRANT SELECT,UPDATE ON sales TO newrole
DENY INSERT ON employees TO newrole
EXEC sp_grantdbaccess 'newlogin','newuser'
EXEC sp_addrolemember 'newrole','newuser'
EXEC sp_revokedbaccess 'newuser';
EXEC sp_droplogin 'newlogin'
EXEC sp_droprole 'newrole'
EXEC sp_droprolemember 'newrole', 'newuser'
CREATE LOGIN mylogin WITH PASSWORD = '123456' MUST_CHANGE;
CREATE LOGIN mylogin WITH PASSWORD = '123456',
CREDENTIAL = mycredential;
CREATE LOGIN [jack\xiangzhao] FROM WINDOWS;
CREATE USER myuser FOR LOGIN mylogin
CREATE ROLE myrole AUTHORIZATION myuser;
CREATE ROLE myrole AUTHORIZATION db_role
1 创建雇佣日期规则 hire_date_rule
CREATE RULE hire_date_rule
AS @hire_date>='1980-01-01' and @hire_date<=getdate()
2 创建性别规则sex_rule
CREATE RULE sex_rule
AS @sex in ('男','女')
3 -创建评分规则grade_rule
CREATE RULE grade_rule
AS @value between 1 and 100
4 创建字符规则my_character_rule
Create rule my_character_rule
As @value like '[a-z]%[0-9]'
5 sp_helptext 查看规则,查看规则hire_date_rule的文本信息
EXECUTE sp_helptext hire_date_rule
6 sp_bindrule绑定规则
EXEC sp_bindrule hire_date_rule, 'employee.hire_date'
EXEC sp_addtype pat_char,'varchar(10)','NOT NULL'
EXEC sp_bindrule my_character_rule, pat_char, 'futureonly';
7 sp_unbindrule 解除规则的绑定
EXEC sp_unbindrule 'employee.hire_date';
* DROP RULE语句删除当前数据库中的一个或多个规则
DROP RULE sex_rule,hire_date_rule
select * from (
select * ,ROW_NUMBER() over(order by sid) as rowcindex --增加索引
from Student) as t
where t.rowcindex between 1 and 3;
select s.sid,s.sname,
max(case c.cname when '语文' then sc.score end) as '语文',
min(case c.cname when '数学' then sc.score end) as '数学',
sum(case c.cname when '英语' then sc.score end) as '英语',
max(case c.cname when '化学' then sc.score else 0 end) as '化学'
from (Student as s inner join SC as sc on s.sid=sc.sid
inner join Course as c on c.cid=sc.cid)
group by s.sid,s.sname;
1 全局变量
select @@VERSION --数据库版本
insert into Course values('',''); select @@IDENTITY --获取最近insert语句的标识
print @@servername --服务器名称
print @@rowcount--返回受影响的行数
2 选择语句
declare @id int
set @id =10
if @id>5
begin
print 'ok'
end
else
begin
print 'no'
end
3 循环语句
declare @id int
set @id=1
while @id<10
begin
print @id
set @id=@id+1
end
4 异常
begin try
delete from SC--不能成功
end try
begin catch
print @@error --判断错误信息 0对
end catch
5 事务:回滚函数
begin try
begin transaction --开启事务
--错误SQL
commit tran --提交事务
end try
begin catch
rollback tran --回退事务
end catch
6 锁:同步
begin tran --锁上
--修改操作
rollback tran --开锁 commit tran
标签:row 回滚 wro public action OLE 指定 所有权限 所有权
原文地址:https://www.cnblogs.com/purple910/p/11830313.html