I have a table in my database in which records conceptually can be children of other rcords. The table has a non-null name field. I need to ensure that each name in a set of children is unique, but not across the entire database. I'd like to enforce this using a constraint inside the Database. What's the best way to accomplish this? I know that I am going to have to do a query at some point in the process like this:
@NameParameter NVARCHAR(512)
Select Name from MyTable
WHERE Name=@NameParameter
The question is where do I put this query?