Urgent Help: Validating Updation of a column

  • if OBJECT_ID('..test')>0 drop table test

    create table test

    (id int ,

    name varchar(2)

    );

    Go

    insert into test

    select 1,'a'

    union all

    select 2,'b'

    union all

    select 3,'c'

    Go:

    Select * from Test

    >>> Gives Result.

    idname

    1a

    2b

    3c

    Now, What i want is the to create a trigger or any constraint that we cannot update Column 'Name' of the table. But allowed to update Column 'ID'.

    Need Urgent Help:

  • You will need to create a trigger check if the column has been updated

    If the column has been updated, you can do a ROLLBACK in the trigger with a possible error message.


    Kingston Dhasian

    How to post data/code on a forum to get the best help - Jeff Moden
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • Kingston Dhasian (4/26/2013)


    You will need to create a trigger check if the column has been updated

    If the column has been updated, you can do a ROLLBACK in the trigger with a possible error message.

    That is exactly what i was thinking, but How.? its Syntax

    a complete Answer will be highly appreciated.

  • Mr. Kapsicum (4/26/2013)


    That is exactly what i was thinking, but How.? its Syntax

    a complete Answer will be highly appreciated.

    You might appreciate a complete answer but it will not help you in the long run

    It would be great for you if you try something yourself and we will be ready to help you in case you get stuck

    I will give you a link to the UPDATE() function in SQL Server, try some code yourself and get back to us in case you are facing any troubles.

    http://msdn.microsoft.com/en-us/library/ms187326%28v=sql.105%29.aspx

    BTW, It almost has what you want.


    Kingston Dhasian

    How to post data/code on a forum to get the best help - Jeff Moden
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • Kingston Dhasian (4/26/2013)


    Mr. Kapsicum (4/26/2013)


    That is exactly what i was thinking, but How.? its Syntax

    a complete Answer will be highly appreciated.

    You might appreciate a complete answer but it will not help you in the long run

    It would be great for you if you try something yourself and we will be ready to help you in case you get stuck

    I will give you a link to the UPDATE() function in SQL Server, try some code yourself and get back to us in case you are facing any troubles.

    http://msdn.microsoft.com/en-us/library/ms187326%28v=sql.105%29.aspx

    BTW, It almost has what you want.

    Thank you Sir,

    Tried something and Got the answer.

    And it is a great help.

    Thank you very much.

    :Wow:

  • Thats great. Glad to hear 🙂

    If you don't mind, can you post your trigger code?

    We will check and let you know of improvements if any..


    Kingston Dhasian

    How to post data/code on a forum to get the best help - Jeff Moden
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply