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 2005 Forums
 Transact-SQL (2005)
 Can I create a foreign key on a view?

Author  Topic 

SupaHoopsa
Starting Member

1 Post

Posted - 2007-11-20 : 06:09:55
I have a table with a locationID field that is currently constrained by a foreign Key to an Airport table. However I now need to be able to put an alternate location in this table that breaks the FK constraint.

What I was wondering was could I change the FK constraint so that rather than looking at the Airport table, I pointed at a view that contains all the airport data and the alternate locations?

Is this possible?

hitman
Starting Member

23 Posts

Posted - 2007-11-20 : 06:26:32
I don't think it's possible to point a foreign key from a table to a view.

"Msg 1768, Level 16, State 0, Line 1
Foreign key 'fk_to_vw' references object 'vw_view' which is not a user table."

-----------------------
http://www.sqltips.info
-----------------------
Go to Top of Page
   

- Advertisement -