SQL Server 2005 - 将列设置为只读 [英] SQL Server 2005 - Setting a column as readonly
问题描述
我在 SQL Server 2005 数据库的表中有一个InsertTime"字段,当第一次将记录插入数据库时,该字段默认为getDate()".我想确保不会再次更新此列.
I have a "InsertTime" field in a table in a SQL Server 2005 database which is defaulted to "getDate()" when the record is first inserted into the database. I want to ensure that this column is not updated again.
可以将此列设置为只读还是有更好的方法来做到这一点,而无需为开发人员编写所有 sql?
Can this column be set to readonly or is there a better way to do this without writing all of the sql for the developers?
推荐答案
编写一个存储过程来执行此表中的更新,并确保它不会触及 InsertTime 字段.然后设置所有用户的权限,这样他们自己就不能对这个表进行原始更新,但可以调用存储过程.
Write a stored procedure to do the Update in this table, and make sure it doesn't touch the InsertTime field. Then set all your users' permissions so they can't themselves do a raw Update on this table, but can call the stored procedure.
这篇关于SQL Server 2005 - 将列设置为只读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!