Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
Administration
»
Database design
Database design
Rate Topic
Display Mode
Topic Options
Author
Message
DanCafeFood
DanCafeFood
Posted Wednesday, February 11, 2009 9:11 AM
Forum 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
JestersGrind
JestersGrind
Posted Wednesday, February 11, 2009 9:17 AM
Hall of Fame
Group: General Forum Members
Last Login: Monday, May 07, 2012 12:48 PM
Points: 3,302,
Visits: 1,456
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
Jack Corbett
Jack Corbett
Posted Wednesday, February 11, 2009 9:31 AM
SSChampion
Group: General Forum Members
Last Login: Today @ 3:50 PM
Points: 10,309,
Visits: 11,504
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
DanCafeFood
DanCafeFood
Posted Wednesday, February 11, 2009 9:52 AM
Forum 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
DanCafeFood
DanCafeFood
Posted Wednesday, February 11, 2009 10:25 AM
Forum 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
Jack Corbett
Jack Corbett
Posted Wednesday, February 11, 2009 10:46 AM
SSChampion
Group: General Forum Members
Last Login: Today @ 3:50 PM
Points: 10,309,
Visits: 11,504
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
DanCafeFood
DanCafeFood
Posted Wednesday, February 11, 2009 10:50 AM
Forum 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 »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.