SQL与多个用户开会,反之亦然

时间:2019-01-05 09:59:34

标签: c#

我正在使用SQL在c#中创建会议程序。我该如何将用户表中的多个用户添加到一个会议,反之亦然(表中的一个用户添加多个会议)

对不起,我是SQL的新手

SQL DB格式:用户

[UserID]     VARCHAR (50) NOT NULL,
[FirstName]  VARCHAR (50) NOT NULL,
[LastName]   VARCHAR (50) NOT NULL,
[Username]   VARCHAR (50) NOT NULL,
[Password]   VARCHAR (50) NOT NULL,
[Exc1]       BIT  NULL,
[Exc2]       BIT  NULL,
[Exc3]       BIT  NULL,
[Exc4]       BIT  NULL,
[Exc5]       BIT  NULL,
[Importance] INT          NOT NULL,
[Meetings]   VARCHAR (50) NULL,
PRIMARY KEY CLUSTERED ([UserID] ASC),
CONSTRAINT [Meetings] FOREIGN KEY ([Meetings]) REFERENCES [dbo].[Meeting] ([MeetingID])

会议

[MeetingID] VARCHAR (50)  NOT NULL,
[Title]     VARCHAR (50)  NOT NULL,
[Date]      DATE          NOT NULL,
[StartTime] TIME (7)      NOT NULL,
[EndTime]   TIME (7)      NOT NULL,
[Location]  VARCHAR (50)  NOT NULL,
[Exc1]      BIT   NULL,
[Exc2]      BIT   NULL,
[Exc3]      BIT   NULL,
[Exc4]      BIT   NULL,
[Exc5]      BIT   NULL,
[Summary]   VARCHAR (MAX) NULL,
[UserID]    VARCHAR (50)  NOT NULL,
PRIMARY KEY CLUSTERED ([MeetingID] ASC),
CONSTRAINT [UserID] FOREIGN KEY ([UserID]) REFERENCES [dbo].[Users] ([UserID])

1 个答案:

答案 0 :(得分:0)

在这种情况下,这是一个n对n的关系,您需要一个额外的表,例如

usermeetings
[UsermeetingsID]
[UserID]
[MeetingID]

您可以从会议表中删除用户ID列,并从用户表中删除会议列