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


Is this normalized?


Is this normalized?

Author
Message
Layne-812700
Layne-812700
Grasshopper
Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)

Group: General Forum Members
Points: 10 Visits: 26
I'm trying to help a friend but it's been ages since I last took up my DB normalization course. Have I done the right thing by designing the tables as such, or can you point out if I've created less or more than enough?

Thanks

--student table
create table xStudent
(xID INT identity(1,1),
studentNo char(7) null,
studentName char(100) null)
insert xStudent Values ('0315288','Sam Asiata')
insert xStudent Values ('0315289','John Doe')
insert xStudent Values ('0515111','Mike Jordan')

--class table
create table xClass
(xClassID INT identity(1,1),
ClassCode char(10) null,
ClassName char(17) null)
Insert xClass values ('123456/12','Research')
Insert xClass values ('678910/13','Technology')
Insert xClass values ('123456/13','Crime')
Insert xClass values ('123456/14','Business')
Insert xClass values ('123456/15','Accounting')

--Tutorial table (1 to 12)
create table xTutorial
(xTutId INT identity(1,1),
TutorialCd char(10) null,
TutorialName char(17) null)
Insert xTutorial values ('Tutor1','Tutorial 1')
Insert xTutorial values ('Tutor2','Tutorial 2')
Insert xTutorial values ('Tutor3','Tutorial 3')
Insert xTutorial values ('Tutor4','Tutorial 4')
Insert xTutorial values ('Tutor5','Tutorial 5')

--Student - Class link, to get the classes belonging to a particular student
create table xStudClass
(xTutId INT identity(1,1),
StudentNo char(7) null,
ClassCode char(10) null)

Insert xStudClass values ('0315288','123456/12')
Insert xStudClass values ('0315288','123456/13')
Insert xStudClass values ('0315288','123456/14')
Insert xStudClass values ('0315289','123456/14')
Insert xStudClass values ('0315289','123456/12')

--Link between Tutorial and Classes, to count the number of tutorial for each class/student
create table xTutorClass
(xTutClassId INT identity(1,1),
TutorialCd char(10) null,
ClassCode char(10) null,
xID INT null)
Insert xTutorClass Values ('Tutor2','123456/12',1)
Insert xTutorClass Values ('Tutor3','123456/12',1)
Insert xTutorClass Values ('Tutor5','123456/12',1)
Insert xTutorClass Values ('Tutor5','123456/12',2)
Insert xTutorClass Values ('Tutor2','123456/12',2)
Insert xTutorClass Values ('Tutor5','123456/14',2)
Insert xTutorClass Values ('Tutor5','123456/13',3)

select * from xClass
select * from xTutorial
select * from xStudent
select * from xStudClass
select * from xTutorClass order by 3

--This is to generate count
select b.studentNo, b.StudentName, a.classCode, c.ClassName, count(*) as TutorCount
from xTutorClass a INNER JOIN xStudent b ON a.xID = b.xID
INNER JOIN xClass c ON a.ClassCode = c.ClassCode
group by b.StudentNo, b.StudentName, a.ClassCode, c.ClassName
shamassaeedmr
shamassaeedmr
SSC Rookie
SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)

Group: General Forum Members
Points: 41 Visits: 181
It seems to be OK. Only need is to generate links
steveb.
steveb.
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2856 Visits: 7195
You seem to have a perfectly good natural key in the Student Table of StudentNo, but you have added a column xId to act as the identity column. Is this because StudentNo is not unique?
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: 11034 Visits: 14858
I would say that it is normalized, although I would have FirstName and LastName columns instead of just a StudentName.

I would also echo SteveB's response about the identity columns. If you aren't using them as foreign keys and if the other columns (StudentNo, ClassCd, etc...) are unique, which they have to be to be used a foreign keys, I would make them the primary key and eliminate the identity column(s).



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
John Rowan
John Rowan
SSCarpal Tunnel
SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

Group: General Forum Members
Points: 4074 Visits: 4511
In addition to what everyone else has said, I would also tighten up your use of NULLs. Setting your columns up as NOT NULL by default is a good practice to have. Not that using NOT NULL moves your tables into a new normal form, but it does help identify possible normalization areas. I've seen, too often, developers using NULLable columns in tables because not all rows in the table use that column. This type of use of NULLs usually means that the entity is not normalized because you've got a number of columns that don't depend on the key.

It does not look like this is the case for your tables, but a good practice is to always start off with columns defined as NOT NULL and only change it if there is a good business reason to allow NULL values in that column.

John Rowan

======================================================
======================================================
Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
Carl Federl
Carl Federl
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2342 Visits: 4349
Noticed that the ClassCode values have a slash in the same position which may indicate that the column can be decomposed, such as the values before the slash indicate the department and after the slash, a unique value within the department. If so, then there should be two columns. Another ways of determining if this is a compound column is to search for a query that has "where ClassCode like '123456/%' ". Also look for another table that has a candidate key that matches the values before the slash.

Insert xClass values ('123456/12','Research')
Insert xClass values ('678910/13','Technology')
Insert xClass values ('123456/13','Crime')
Insert xClass values ('123456/14','Business')
Insert xClass values ('123456/15','Accounting')

SQL = Scarcely Qualifies as a Language
Layne-812700
Layne-812700
Grasshopper
Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)

Group: General Forum Members
Points: 10 Visits: 26
steveb (7/29/2009)
You seem to have a perfectly good natural key in the Student Table of StudentNo, but you have added a column xId to act as the identity column. Is this because StudentNo is not unique?


Yeah, I guess I might as well drop the xID because it defeats the purpose of the StudentNo being unique. Thanks
Layne-812700
Layne-812700
Grasshopper
Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)

Group: General Forum Members
Points: 10 Visits: 26
thanks everyone for your very helpful tips and advice. I guess my basic normalization training is still alive and kicking. Smile
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