I have two tables which both have a ‘Name’ column. The tables are not related to each other. I’d like to enforce uniqueness across these two columns.
I’ve been trying to create an indexed view out of the two columns but have found out that I cannot use a union all nor a full join to get the full list of names. I feel like I’m missing an obvious alternative which would allow me to add the unique index.
Assuming both of your base tables have a unique constraint on ‘Name’ then the only way uniqueness can be violated is if the same name is in both tables.
i.e. you expect a join against them to return zero rows. So you can cross join the result of that join against a table with 2 rows and create a unique index against that.