Page 1 of 27
Tony LoCoco
ITCO333 – Unit 2
August 29, 2013
REQUIREM ENT S
• This database must contain examples of one
• I will compare your Unit 1 ERD with the Unit 2 database diagram. If there are differences, explain why.
• Present your SQL statements in the order in which they were executed.
• Put your database diagram at the top of your document (see my sample).
Each of your t
sample data (p
REL AT IONS HIP S
Relationship
Type
Entity #1 Entity #2
one-to-one (1:1) Advisors Employees
one-to-many (1:M) Employees Departments
one-to-many (1:M) Advisors Students
This database must contain examples of one-to-one, one-to-many and many-to-many relationships.
I will compare your Unit 1 ERD with the Unit 2 database diagram. If there are differences, explain why.
Present your SQL statements in the order in which they were executed.
Put your database diagram at the top of your document (see my sample).
tables must contain at least eight records of
per the assignment requirements).
Entity #2 Description / Justification
Employees An Advisor is an Employee with additional data
attributes. An Employee may or may not be an Advisor.
Departments A Department may have 0, 1 or many Employees
Employee is assigned to just one Department.
An Advisor may be assigned to 0, 1 or many Students and
a Student is assigned to just one Advisor.
many relationships.
I will compare your Unit 1 ERD with the Unit 2 database diagram. If there are differences, explain why.
An Advisor is an Employee with additional data
attributes. An Employee may or may not be an Advisor.
many Employees and an
An Advisor may be assigned to 0, 1 or many Students and
Page 2 of 27
many-to-many
(M:N)
Students Courses A Student be take 0 , 1 or many Courses and a Course can
contain 0, 1 or many Students.
Relational Databases can not support many-to-many
relationships. These M:N must be broken down into two
one-to-many relationships with a bridge entity
connecting the M:N entities. In this case, Student_Courses
is that bridge entity.
Page 3 of 27
D AT ABASE D IAGR AM
Page 4 of 27
UNIT 1 ERD
Emloyees
PK Employee_ID
Last_Name
First_Name
Birth_Date
Employment_Start_Date
Hourly_Pay
FK1 Department_ID
Manager_ID
Departments
PK Department_ID
Department_Name
Students
PK Student_ID
Last_Name
First_Name
Birth_Date
Enroll_Date
Status_Code
Total_Hours
FK1,FK2 Advisor_ID
Advisors
PK,FK1 Employee_ID
Certification_Level
Courses
PK Course_ID
Course_Code
Course_Name
Credit_Hours
Sessions
PK Session_ID
Session_Name
Session_Start_Date
Student_Courses
PK,FK1 Session_ID
PK,FK3 Course_ID
PK,FK2 Student_ID
Earned_Grade
Page 5 of 27
SQL D D L T O CREAT E D AT ABASE
USE [master]
GO
CREATE DATABASE ITCO333Database
GO
Page 6 of 27
CREAT E T ABL ES, F IEL D S , P RIM ARY K EY S & FOREIGN K EY / CREAT E D M L
USE .
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Page 1 of 27 Tony LoCoco ITCO333 – Unit 2 August 2.docx
1. Page 1 of 27
Tony LoCoco
ITCO333 – Unit 2
August 29, 2013
REQUIREM ENT S
• This database must contain examples of one
• I will compare your Unit 1 ERD with the Unit 2 database
diagram. If there are differences, explain why.
• Present your SQL statements in the order in which they were
executed.
• Put your database diagram at the top of your document (see
my sample).
Each of your t
sample data (p
REL AT IONS HIP S
2. Relationship
Type
Entity #1 Entity #2
one-to-one (1:1) Advisors Employees
one-to-many (1:M) Employees Departments
one-to-many (1:M) Advisors Students
This database must contain examples of one-to-one, one-to-
many and many-to-many relationships.
I will compare your Unit 1 ERD with the Unit 2 database
diagram. If there are differences, explain why.
Present your SQL statements in the order in which they were
executed.
Put your database diagram at the top of your document (see my
sample).
tables must contain at least eight records of
per the assignment requirements).
Entity #2 Description / Justification
Employees An Advisor is an Employee with additional data
attributes. An Employee may or may not be an Advisor.
Departments A Department may have 0, 1 or many Employees
3. Employee is assigned to just one Department.
An Advisor may be assigned to 0, 1 or many Students and
a Student is assigned to just one Advisor.
many relationships.
I will compare your Unit 1 ERD with the Unit 2 database
diagram. If there are differences, explain why.
An Advisor is an Employee with additional data
attributes. An Employee may or may not be an Advisor.
many Employees and an
An Advisor may be assigned to 0, 1 or many Students and
Page 2 of 27
many-to-many
(M:N)
Students Courses A Student be take 0 , 1 or many Courses and a
Course can
contain 0, 1 or many Students.
4. Relational Databases can not support many-to-many
relationships. These M:N must be broken down into two
one-to-many relationships with a bridge entity
connecting the M:N entities. In this case, Student_Courses
is that bridge entity.
Page 3 of 27
D AT ABASE D IAGR AM
Page 4 of 27
UNIT 1 ERD
7. PK,FK2 Student_ID
Earned_Grade
Page 5 of 27
SQL D D L T O CREAT E D AT ABASE
USE [master]
GO
CREATE DATABASE ITCO333Database
GO
Page 6 of 27
CREAT E T ABL ES, F IEL D S , P RIM ARY K EY S &
FOREIGN K EY / CREAT E D M L
8. USE [ITCO333Database]
GO
CREATE TABLE [dbo].[Departments](
[Department_ID] [int] NOT NULL PRIMARY KEY,
[Department_Name] [nvarchar](50) NULL
)
GO
USE [ITCO333Database]
GO
INSERT [dbo].[Departments] ([Department_ID],
[Department_Name])
VALUES (1, N'Academics'),
(2, N'Finance'),
(3, N'Student Advisors'),
(4, N'Marketing'),
(5, N'Recruitment'),
(6, N'Office of Provost'),
(7, N'Information Technology')
Page 7 of 27
GO
9. Page 8 of 27
USE [ITCO333Database]
GO
CREATE TABLE [dbo].[Sessions]
(
[Session_ID] [int] NOT NULL PRIMARY KEY,
[Session_Name] [nvarchar](50) NULL,
[Session_Start_Date] [date] NULL
)
GO
USE [ITCO333Database]
GO
INSERT [dbo].[Sessions] ([Session_ID], [Session_Name],
[Session_Start_Date])
VALUES (10, N'1201-A', '2012-01-12'),
(11, N'1201-B', '2012-02-15'),
(12, N'1202-A', '2012-04-01'),
(13, N'1202-B', '2012-05-15'),
(14, N'1203-A', '2012-07-01'),
10. (15, N'1203-B', '2012-08-15'),
(16, N'1204-A', '2012-10-01'),
(17, N'1204-B', '2012-11-15')
GO
Page 9 of 27
Page 10 of 27
USE [ITCO333Database]
GO
CREATE TABLE [dbo].[Courses]
(
[Course_ID] [int] NOT NULL PRIMARY KEY,
[Course_Code] [nvarchar](50) NULL,
[Course_Name] [nvarchar](50) NULL,
[Credit_Hours] [int] NULL
)
GO
11. USE [ITCO333Database]
GO
INSERT [dbo].[Courses] ([Course_ID], [Course_Code],
[Course_Name], [Credit_Hours])
VALUES (1, N'ITD200', N'Database I', 4),
(2, N'ITD300', N'Database II', 4),
(3, N'ITD400', N'Advanced Databases', 4),
(4, N'ITN200', N'Networking I', 4),
(5, N'ITN300', N'Networking II', 4),
(6, N'ITN400', N'Advanced Networking', 4),
(7, N'ITP200', N'Intro to Programming', 4),
(8, N'ITP300', N'Programming II', 4),
(9, N'ITP400', N'Advanced Programming', 4)
GO
Page 11 of 27
Page 12 of 27
USE [ITCO333Database]
18. Page 21 of 27
FUL L SQL
Perform TASKS > GENERATE SCRIPTS. Copy and paste the
full database script here.
Refer to the “Generate Scripts for Entire Database.pdf” in the
Instructor Files area.
USE [master]
GO
/****** Object: Database [ITCO333Database] Script Date:
08/29/2013 19:08:35 ******/
CREATE DATABASE [ITCO333Database] ON PRIMARY
( NAME = N'ITCO333Database', FILENAME = N'c:Program
Files (x86)Microsoft SQL
ServerMSSQL10_50.SQLEXPRESSMSSQLDATAITCO333D
atabase.mdf' , SIZE = 2304KB , MAXSIZE =
UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'ITCO333Database_log', FILENAME =
N'c:Program Files (x86)Microsoft SQL
ServerMSSQL10_50.SQLEXPRESSMSSQLDATAITCO333D
atabase_log.LDF' , SIZE = 576KB , MAXSIZE
= 2048GB , FILEGROWTH = 10%)
19. GO
ALTER DATABASE [ITCO333Database] SET
COMPATIBILITY_LEVEL = 100
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [ITCO333Database].[dbo].[sp_fulltext_database]
@action = 'enable'
end
GO
ALTER DATABASE [ITCO333Database] SET
ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [ITCO333Database] SET ANSI_NULLS
OFF
GO
ALTER DATABASE [ITCO333Database] SET
ANSI_PADDING OFF
GO
ALTER DATABASE [ITCO333Database] SET
ANSI_WARNINGS OFF
GO
ALTER DATABASE [ITCO333Database] SET ARITHABORT
OFF
GO
ALTER DATABASE [ITCO333Database] SET AUTO_CLOSE
ON
GO
ALTER DATABASE [ITCO333Database] SET
AUTO_CREATE_STATISTICS ON
GO
ALTER DATABASE [ITCO333Database] SET AUTO_SHRINK
OFF
GO
ALTER DATABASE [ITCO333Database] SET
AUTO_UPDATE_STATISTICS ON
20. GO
ALTER DATABASE [ITCO333Database] SET
CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [ITCO333Database] SET
CURSOR_DEFAULT GLOBAL
GO
ALTER DATABASE [ITCO333Database] SET
CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [ITCO333Database] SET
NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [ITCO333Database] SET
QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [ITCO333Database] SET
RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [ITCO333Database] SET
ENABLE_BROKER
Page 22 of 27
GO
ALTER DATABASE [ITCO333Database] SET
AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [ITCO333Database] SET
DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [ITCO333Database] SET
TRUSTWORTHY OFF
21. GO
ALTER DATABASE [ITCO333Database] SET
ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [ITCO333Database] SET
PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [ITCO333Database] SET
READ_COMMITTED_SNAPSHOT OFF
GO
ALTER DATABASE [ITCO333Database] SET
HONOR_BROKER_PRIORITY OFF
GO
ALTER DATABASE [ITCO333Database] SET READ_WRITE
GO
ALTER DATABASE [ITCO333Database] SET RECOVERY
SIMPLE
GO
ALTER DATABASE [ITCO333Database] SET MULTI_USER
GO
ALTER DATABASE [ITCO333Database] SET PAGE_VERIFY
CHECKSUM
GO
ALTER DATABASE [ITCO333Database] SET DB_CHAINING
OFF
GO
USE [ITCO333Database]
GO
/****** Object: Table [dbo].[Departments] Script Date:
08/29/2013 19:08:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Departments](
[Department_ID] [int] NOT NULL,
22. [Department_Name] [nvarchar](50) NULL,
PRIMARY KEY CLUSTERED
(
[Department_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE
= OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS =
ON) ON [PRIMARY]
) ON [PRIMARY]
GO
INSERT [dbo].[Departments] ([Department_ID],
[Department_Name]) VALUES (1, N'Academics')
INSERT [dbo].[Departments] ([Department_ID],
[Department_Name]) VALUES (2, N'Finance')
INSERT [dbo].[Departments] ([Department_ID],
[Department_Name]) VALUES (3, N'Student
Advisors')
INSERT [dbo].[Departments] ([Department_ID],
[Department_Name]) VALUES (4, N'Marketing')
INSERT [dbo].[Departments] ([Department_ID],
[Department_Name]) VALUES (5,
N'Recruitment')
INSERT [dbo].[Departments] ([Department_ID],
[Department_Name]) VALUES (6, N'Office of
Provost')
INSERT [dbo].[Departments] ([Department_ID],
[Department_Name]) VALUES (7, N'Information
Technology')
/****** Object: Table [dbo].[Courses] Script Date:
08/29/2013 19:08:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Courses](
34. GO
/****** Object: ForeignKey
[FK__Advisors__Employ__117F9D94] Script Date:
08/29/2013
19:08:36 ******/
ALTER TABLE [dbo].[Advisors] WITH CHECK ADD
FOREIGN KEY([Employee_ID])
REFERENCES [dbo].[Employees] ([Employee_ID])
GO
/****** Object: ForeignKey
[FK__Students__Adviso__164452B1] Script Date: 08/29/2013
19:08:36 ******/
ALTER TABLE [dbo].[Students] WITH CHECK ADD
FOREIGN KEY([Advisor_ID])
REFERENCES [dbo].[Advisors] ([Employee_ID])
GO
/****** Object: ForeignKey
[FK__Student_C__Cours__1BFD2C07] Script Date:
08/29/2013
19:08:36 ******/
ALTER TABLE [dbo].[Student_Courses] WITH CHECK ADD
FOREIGN KEY([Course_ID])
REFERENCES [dbo].[Courses] ([Course_ID])
GO
/****** Object: ForeignKey
[FK__Student_C__Sessi__1B0907CE] Script Date:
08/29/2013
19:08:36 ******/
ALTER TABLE [dbo].[Student_Courses] WITH CHECK ADD
FOREIGN KEY([Session_ID])
REFERENCES [dbo].[Sessions] ([Session_ID])
GO
/****** Object: ForeignKey
[FK__Student_C__Stude__1CF15040] Script Date:
08/29/2013
19:08:36 ******/
35. ALTER TABLE [dbo].[Student_Courses] WITH CHECK ADD
FOREIGN KEY([Student_ID])
REFERENCES [dbo].[Students] ([Student_ID])
GO
{Your Name}
ITCO333 – Unit 2
{date}
Hint: Refer to the Unit 2 - LoCoco – Sample.pdf in the
Instructor Files area for an example.
Requirements
· This database must contain examples of one-to-one, one-to-
many and many-to-many relationships.
· I will compare your Unit 1 ERD with the Unit 2 database
diagram. If there are differences, explain why.
· Present your SQL statements in the order in which they were
executed.
· Put your database diagram at the top of your document (see
my sample).
· You must provide proof (via a screen shot) that your SQL
statement executed.
Relationships (from Unit 1)
Include corrections based on the feedback you received.
Relationship Type
Entity #1
Entity #2
Description / Justification
36. one-to-one (1:1)
one-to-many (1:M)
one-to-many (1:M)
many-to-many (M:N)
Your Unit 1 ERD
Include corrections based on the feedback you received.
Database Diagram
Refer to: http://www.youtube.com/watch?v=wMbPRHeYvMU
SQL DDL to create database
37. Create tables, Fields, Primary Keys & Foreign Key
DML to populate the database
Full SQL
Perform TASKS > GENERATE SCRIPTS. Copy and paste the
full database script here.
Refer to the “Generate Scripts for Entire Database.pdf” in the
Instructor Files area.
Page 5 of 5