在sql server中设置AS不可编辑的属性 [英] setting an attribute AS uneditable in sql server

查看:93
本文介绍了在sql server中设置AS不可编辑的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张这样的桌子

I have a table like this

create table cus(
username varchar(20) primary key,
password varchar(50)
);



我的业务要求是我无法编辑用户名字段。我的意思是,如果有更新声明,我需要回滚一个事务。

我做的是创建这样的触发器


My business requirement is such that i should not be able to edit the username field. What i mean is i need to rollback a transaction if there is an update statement.
What i do is i create a trigger something like this

create trigger cusonupdate on dbo.cus
for update 
as
rollback
print'The suggested Row cannot be updated'



这将执行所需的操作。但我需要的是我必须有一个更新密码的条款。我应该怎么做?


This will do the required thing. But what i need is i must be having a provision to update the password. How should i do it?

推荐答案

试试这种方式 -



Try this way -

create trigger cusonupdate on dbo.cus
for update
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    IF UPDATE(username)
        BEGIN
            ROLLBACK
            print'The suggested Row cannot be updated'
        END

END


Hello freind你可以使用DENY用你的cus表更新,就像这样...



Hello freind you can use DENY on update with your cus table, something like this...

DENY UPDATE ON dbo.cus (username ) TO <database username>




带有DENY键的
你需要指定你需要DENY更新的sql server用户



Referance:

DENY [ ^ ]


这篇关于在sql server中设置AS不可编辑的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆