SQL Server Constraints Across Tables

Posted by chama on Stack Overflow See other posts from Stack Overflow or by chama
Published on 2010-05-05T20:07:35Z Indexed on 2010/05/05 20:48 UTC
Read the original article Hit count: 289

I have a SQL Server database with an Apartment table (which has columns FloorNum and BuildingID) and an ApartmentBuilding table (with column NumFloors). Is there any way to set up a constraint (using the SQL Server UI) to check that Apartment.FloorNum is greater than ApartmentBuilding.NumFloors?

I tried this:

FloorNum > ApartmentBuilding.NumFloors

but now I realize that I somehow have to join the columns on the BuildingID, but I have no idea how to do that within a constraint.

Thanks for your help!

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about constraints