sql server - Preventing specifying values in a column -


is there way prevent specifying explicit values in column? identity attribute prevents specifying explicit values (as long identity_insert off), type of behavior want.

create table testguid (     id uniqueidentifier default newsequentialid() not null primary key     ,somedate datetime ) 

[constraint or trigger here?]

insert testguid (somedate) values (getdate()) -- ok insert testguid (id, somedate) values (newid(), getdate()) -- not ok 

i want database insert values, want prevent way of specifying them.

you use instead of trigger re-write insert statement, leaving out id column.

create trigger dbo.testguid_beforeinsert instead of insert begin     set nocount on;      insert dbo.testguid(somedate --, other columns     ) select getdate() --, other columns     inserted; end go 

probably want similar update, too.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -