Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Database design Expand / Collapse
Author
Message
Posted Wednesday, February 11, 2009 9:11 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, February 12, 2009 2:12 PM
Points: 4, Visits: 7
I have the following Data:

Instructors Course ID Class Company Room
Dan Smith 100 AJAX American Airlines 500
Dianne Ross 200 WPF Boeing 502
Donna White 300 LINQ Lufthansa 500
Donna White 100 AJAX Lufthansa 501


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?
Post #654968
Posted Wednesday, February 11, 2009 9:17 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, May 14, 2013 1:42 PM
Points: 3,487, Visits: 1,581
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




Post #654975
Posted Wednesday, February 11, 2009 9:31 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Thursday, July 24, 2014 9:07 AM
Points: 11,157, Visits: 12,899
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.




Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #654996
Posted Wednesday, February 11, 2009 9:52 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, February 12, 2009 2:12 PM
Points: 4, Visits: 7
I wanted to paste the database diagram picture here. Is there a way to paste it.
Post #655027
Posted Wednesday, February 11, 2009 10:25 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, February 12, 2009 2:12 PM
Points: 4, Visits: 7
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
Post #655066
Posted Wednesday, February 11, 2009 10:46 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Thursday, July 24, 2014 9:07 AM
Points: 11,157, Visits: 12,899
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 Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #655091
Posted Wednesday, February 11, 2009 10:50 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, February 12, 2009 2:12 PM
Points: 4, Visits: 7
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?
Post #655095
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse