Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to set the permission to insert for a column in a table in SQLServer. Please give an example.

in Details: User can't insert or update a particular column values(i.e. datetime datatype) but it'll insert or update values from current date time of system for every insert or update data. Please give an example.
Posted
Comments
ZurdoDev 4-May-15 12:52pm    
Where are you stuck?
RTK The Limited Edition 4-May-15 13:34pm    
I can't solve this problem. please help with example
ZurdoDev 4-May-15 13:40pm    
Just write code to do it. I'm not sure if SQL natively supports that level of security.

1 solution

You can restrict data insert/update by user through computed column. But for your requirement computed column can not be used as same function returning different result at different time.

So, you can make the column to accept getdate() default value and create an instead of trigger to make sure that whatever the user inserts to that column, it will be replaced by current datestamp.

In case you need help with code, please let me know :)
 
Share this answer
 
Comments
RTK The Limited Edition 4-May-15 15:41pm    
If I use instead of trigger then after insert into statement it's never contain any data.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900