Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 dont update a specific column

Author  Topic 

sebastian11c
Posting Yak Master

129 Posts

Posted - 2012-02-13 : 17:14:07
hi there i have a table
with 4 columns

idclient name lastname id



i have an aplication where i can modify the 3 columns (name, lastname and id) and update the table, that i want to do is that the column "id" will never be updated , doesnt matter if in my asp application i change the value of the column id




example ,
in my table i have this record

idclient name lastname id
156 peter fox 323265


that i want is ,,,, if my mates change the value of the id,, raise an error saying cannot update id

or something like that




visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-13 : 18:15:49
you can create a trigger on table to avoid updates

for update it will be likw


update table
set name= @name, lastname = @Lastname
where idclient = @idclient


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-02-13 : 18:18:44
Depending on your scenario, you might need to implement a (before) trigger on the table. But, perhaps there are other ways to solve the issue, like a foreign key constraint? But, given the information you provided, a trigger looks to solve that problem.
Go to Top of Page

sebastian11c
Posting Yak Master

129 Posts

Posted - 2012-02-14 : 07:10:57
hi visakh16
thanks for always answer my threads,
and thanks Lamprey

could you give me an example with my case
or a similar one,,,
i dont know too much about triggers


thanks in advanced
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-14 : 09:52:25
quote:
Originally posted by sebastian11c

hi visakh16
thanks for always answer my threads,
and thanks Lamprey

could you give me an example with my case
or a similar one,,,
i dont know too much about triggers


thanks in advanced


i've given a sample trigger stub here

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=171322

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -