Can I make an identity field span multiple tables in SQL Server?
        Posted  
        
            by johnnycakes
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by johnnycakes
        
        
        
        Published on 2010-03-11T20:04:16Z
        Indexed on 
            2010/03/11
            20:09 UTC
        
        
        Read the original article
        Hit count: 276
        
sql-server
|identity-column
Can I have an "identity" (unique, non-repeating) column span multiple tables? For example, let's say I have two tables: Books and Authors.
Authors
  AuthorID
  AuthorName
Books
  BookID
  BookTitle
The BookID column and the AuthorID column are identity columns. I want the identity part to span both columns. So, if there is an AuthorID with a value of 123, then there cannot be a BookID with a value of 123. And vice versa.
I hope that makes sense.
Is this possible?
Thanks.
Why do I want to do this? I am writing an APS.NET MVC app. I am creating a comment section. Authors can have comments. Books can have comments. I want to be able to pass an entity ID (a book ID or an author ID) to an action and have the action pull up all the corresponding comments. The action won't care if it's a book or an author or whatever. Sound reasonable?
© Stack Overflow or respective owner