Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Database design


Database design

Author
Message
DanCafeFood
DanCafeFood
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
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?
JestersGrind
JestersGrind
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3495 Visits: 1585
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



Jack Corbett
  Jack Corbett
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11054 Visits: 14858
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
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

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
DanCafeFood
DanCafeFood
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 7
I wanted to paste the database diagram picture here. Is there a way to paste it.
DanCafeFood
DanCafeFood
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
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
Jack Corbett
  Jack Corbett
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11054 Visits: 14858
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
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

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
DanCafeFood
DanCafeFood
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
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?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search