Are there any major overhead differences between using a UNIQUE constraint on two columns and simply having one column that contains the concatenation of the two column values/GUID and using an index on that? For example, instead of using |John|Smith| (two different columns) as the unique constraint, would it be more efficient to add an extra column that holds JohnSmith or a random GUID?
Are there any major overhead differences between using a UNIQUE constraint on two columns
Share
Concatenating the two columns for use as a key seems silly — the database is perfectly capable of doing that for you when you declare the composite key. Whether it makes sense to add an additional INT or GUID key to the table depends on whether the two columns really are the primary key to the table. If they are, why carry around the extra overhead of an additional column (you still need the index on the first two columns to ensure they stay unique). But if they’re not a real primary key (as in your example, first name and last name cannot be considered a primary key in almost any real world system) then you will need a separate primary key.