If you were building a database with tables Documents, Clients, Users and Firms, where in Firms you would store the companies that use the software how would you design the first three tables to support multiple Firms to store in them? So, in Documents we want to store documents for all the firms, of course, we need to tell them appart somehow, so we would need a column like FirmID. We can also put this in Clients and Users.
Now the next requirement is that each firm can have its own IDs for documents, clients, because obviosuly when we add a new firm, their IDs for whatever they create should start at 1.
I was thinking something like this but it requires manual construction of all the fields but RowID.
CREATE TABLE [dbo].[ClientTest](
[RowID] [int] IDENTITY(1,1) NOT NULL,
[FirmID] [int] NOT NULL,
[ClientFirmID] [int] NOT NULL,
[ClientFirmPrettyID] [varchar](10) NOT NULL,
CONSTRAINT [PK_ClientTest] PRIMARY KEY CLUSTERED
(
[RowID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
RowID will run automatically in this case but it's useless for us because for everything we do we need to use ClientFirmID and ClientFirmPrettyID. Is there a way to automate the creation of these two ?