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)
 SQL 05 - Making a column unusable

Author  Topic 

coreHP418
Starting Member

1 Post

Posted - 2011-01-27 : 14:40:01
I've got a table.

MyTable (oldPK, NewPK, Name)

We've recently restructured several of our tables to use a new primary key. I want to be able to select data using the oldPK column but I no longer want to allow inserts into that column.

Is there a way to disable the column?

I was thinking of marking it as unused however that will remove any chance of selecting / restoring that historical data.


Update ** I also thought about maybe trying to make the column ReadOnly.. Can this be done without using a trigger/job?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-01-27 : 14:47:37
There is no feature in SQL Server for that. You can use an INSTEAD OF trigger, but really the job to do the right insert is for the stored procedure/prepared statement/inline SQL.


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-01-28 : 01:50:31
One more option is to use a view that excludes oldPK and use that for insertion. To query using oldPK use the actual table

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -