Database design

  • I have the following Data:

    InstructorsCourse ID ClassCompany Room

    Dan Smith100 AJAXAmerican Airlines500

    Dianne Ross200 WPFBoeing 502

    Donna White300 LINQLufthansa500

    Donna White100 AJAXLufthansa501

    There is a one to many relationship between room and course (1 room can have

    many courses)

    There is a one to many relationship between Course and Teacher (1 course can be

    taught by many teachers)

    There is also Many to Many relationship between Company and Class

    How would I design the database?

  • Hmm... This looks an awful lot like homework. Why don't you post what you think the design should look like and maybe someone will critique it?

    Greg

  • DanCafeFood (2/11/2009)


    I

    There is a one to many relationship between room and course (1 room can have

    many courses)

    There is a one to many relationship between Course and Teacher (1 course can be

    taught by many teachers)

    There is also Many to Many relationship between Company and Class

    How would I design the database?

    It looks like you already a have the basic table srtuctures defined in the statement above. You have rooms (table names should always be plural), teachers, courses (I'm assuming courses and classes are the same), and companies. Then you just need to define your relationships. A search on Many To Many relationship in database design will return many resources.

    As Greg said, post what your ideas and folks will comment on them.

  • I wanted to paste the database diagram picture here. Is there a way to paste it.

  • I guess there is no way to paste a database diagram here, so here is my idea:

    CREATE TABLE [dbo].[tblClass](

    [ClassName] [nchar](10) NULL,

    [RoomName] [nchar](10) NULL

    ) ON [PRIMARY]

    GO

    ALTER TABLE [dbo].[tblClass] ADD CONSTRAINT [PK_ClassName] PRIMARY KEY CLUSTERED

    (

    [ClassName] ASC

    )GO

    CREATE TABLE [dbo].[tblCompany](

    [CompanyID] [nchar](10) NULL,

    [CompanyName] [nchar](10) NULL

    ) ON [PRIMARY]

    GO

    ALTER TABLE [dbo].[tblCompany] ADD CONSTRAINT [PK_CompanyID] PRIMARY KEY CLUSTERED

    (

    [CompanyID] ASC

    )GO

    CREATE TABLE [dbo].[tblRooms](

    [RoomName] [nchar](10) NULL

    ) ON [PRIMARY]

    GO

    ALTER TABLE [dbo].[tblCompany] ADD CONSTRAINT [PK_RoomName] PRIMARY KEY CLUSTERED

    (

    [RoomName] ASC

    )GO

    CREATE TABLE [dbo].[tblTeachers](

    [CompanyId] [nchar](10) NULL,

    [Teacher] [nchar](10) NULL

    ) ON [PRIMARY]

    GO

    ALTER TABLE [dbo].[tblTeachers] ADD CONSTRAINT [PK_Teacher] PRIMARY KEY CLUSTERED

    (

    [Teacher] ASC

    )GO

    CREATE TABLE [dbo].[tblCompClass](

    [CompanyId] [nchar](10) NULL,

    [ClassID] [nchar](10) NULL

    ) ON [PRIMARY]

    GO

    ALTER TABLE [dbo].tblCompClass] WITH CHECK ADD CONSTRAINT [FK_tblCompClass_Company] FOREIGN KEY([CompanyID])

    REFERENCES [dbo].[tblCompany] ([CompanyID])

    GO

    ALTER TABLE [dbo].[tblCompClass] CHECK CONSTRAINT [FK_tblCompClass_Company]

    GO

    ALTER TABLE [dbo].[tblCompClass] WITH CHECK ADD CONSTRAINT [FK_tblCompClass_tblClass] FOREIGN KEY([ClassName])

    REFERENCES [dbo].[tblClass] ([ClassName])

    GO

    ALTER TABLE [dbo].[tblCompClass] CHECK CONSTRAINT [FK_tblCompClass_tblClass]

    GO

    ALTER TABLE [dbo].[tblTeacher] WITH CHECK ADD CONSTRAINT [FK_tblTeacher_tblCompany] FOREIGN KEY([CompanyID])

    REFERENCES [dbo].[tblCompany] ([CompanyID])

    GO

    ALTER TABLE [dbo].[tblTeacher] CHECK CONSTRAINT [FK_tblTeacher_tblCompany]

    GO

    ALTER TABLE [dbo].[tblClass] WITH CHECK ADD CONSTRAINT [FK_tblClass_tblRooms] FOREIGN KEY([RoomName])

    REFERENCES [dbo].[tblRooms] ([RoomName])

    GO

    ALTER TABLE [dbo].[tblClass] CHECK CONSTRAINT [FK_tblClass_tblRooms]

    GO

  • Looks like it would work. One of my preferences is to to use an identity column as the primary key (adding a unique constraint on the true primary key) and then use that id column as the foreign key in other tables. If you do not do this and room names can change you need to make sure CASCADE updates on your relationships.

  • Jack,

    Thanks for the reply. It makes sense to add the ID identity column in Rooms table. My question is, does this design looks too normalized?

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply