var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: Enforcing a relationship
I'd like to create a relationship between two tables in sql server 2005, where a User can be a Partner and a Partner must be a User. So it 0-1 and 1-1. How do I enforce this relationship?
I will also be creating a view from this, will there be any problems when inserting data into the view?
I might aswell add that I'm actually working on asp.net's new membership and roles, so I don't want to change the default tables.
You can create a foreign key in the Partners table referencing the Users table.
You can use the following script for a sample.
CREATE TABLE [dbo].[W_Users](
[UserId] [int] IDENTITY(1,1) NOT NULL,
[FirstName] [nvarchar](50) NULL,
[LastName] [nvarchar](50) NULL,
CONSTRAINT [W_PK_Users] PRIMARY KEY CLUSTERED
CREATE TABLE [dbo].[W_Partners] (
[PartnerId] [int] NOT NULL,
[UserId] [int] NOT NULL,
CONSTRAINT [W_PK_Partners] PRIMARY KEY CLUSTERED
ALTER TABLE [dbo].[W_Partners] WITH CHECK ADD CONSTRAINT [W_FK_Partners_Users] FOREIGN KEY([UserId]) REFERENCES [dbo].[W_Users] ([UserId])