SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 restrict update column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ahmeds08
Constraint Violating Yak Guru

India
425 Posts

Posted - 06/06/2012 :  04:55:37  Show Profile  Send ahmeds08 a Yahoo! Message  Reply with Quote
Hello everyone,
Could anyone tell me how can i restrict user to update columns on a table in sql server.

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 06/06/2012 :  05:24:59  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
You can grant column level permissions - think that came in with v2008 but could be wrong
Trigger?
If you don't want them to be ablle to query the other columns either then a view.


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

ahmeds08
Constraint Violating Yak Guru

India
425 Posts

Posted - 06/06/2012 :  06:10:18  Show Profile  Send ahmeds08 a Yahoo! Message  Reply with Quote
Thanx for the reply.
Can we write a custom trigger to restrict updates on a column??
Go to Top of Page

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 06/06/2012 :  06:30:22  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
yes

create trigger tr_tbl on tbl for update
as

if update (mycolumn)
begin
if exists
(
select * from inserted i
join updated u
on i.pk = u.pk
and (i.mycolumn <> u.mycolumn or (i.mycolumn is null and u.mycolumn is not null) or (i.mycolumn is not null and u.mycolumn is null))
)
begin
rollback tran
raiserror ('cannot update column', 16, -1)
end
end

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

vijays3
Constraint Violating Yak Guru

India
311 Posts

Posted - 06/06/2012 :  16:49:10  Show Profile  Reply with Quote
quote:
Originally posted by nigelrivett

yes

create trigger tr_tbl on tbl for update
as

if update (mycolumn)
begin
if exists
(
select * from inserted i
join updated u
on i.pk = u.pk
and (i.mycolumn <> u.mycolumn or (i.mycolumn is null and u.mycolumn is not null) or (i.mycolumn is not null and u.mycolumn is null))
)
begin
rollback tran
raiserror ('cannot update column', 16, -1)
end
end

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.



nigelrivett,
As I aware of the logical tables of trigger there 
are only two tables inserted and deleted.Updated 
table is not the logical one .Correct me If I am 
wrong .. 


Vijay is here to learn something from you guys.

Edited by - vijays3 on 06/06/2012 16:50:29
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000