SlideShare a Scribd company logo
Structured Query Language for Data Management 2
Sructured Query Language for Data Management 6
Table of Contents
Phase 1- Database Design and DDL 3
Business Rules & Entity Tables 3
Entity Tables: 4
SQL CODE: 4
Screenshots: 8
Phase 2 – Security and DML 13
Task 1 14
Task 2 15
Task 3 16
Task 4 17
Task 5 18
Phase 3 - DML (Select) and Procedures 19
Task 1 19
Task 2 20
Task 3 21
Task 4 22
Task 5 23
Phase 4 – Architecture, Indexes 27
Step 1: CREATE TABLE [Degrees] 27
Step 2: Re-create ‘Classes’ TABLE to add ‘DegreeID’ column
and INSERT 6 classes 29
Step 3: ALTER TABLE [Students] 31
Step 5: DML script to INSERT INTO the ‘Students’ table
‘DegreeID’ data 33
Step 6: Display ERD 36
Phase 5 – Views, Transactions, Testing and Performance37
References 38
Phase 1- Database Design and DDL
My team was recently contracted to design and develop a
database for CTU that will store personal and confidential
university data. This database is expected to provide the back-
end architecture for a front-end web application with an
intuitive User/Interface (U/I) to be used by the university HR
department. We’ve decided to use Microsoft SQL Server 2012
given the nature of data to be stored because it will be more
secure, and it also provides a suite of server maintenance tools
to be left behind with the IT Department once the database and
web application have been tested and accepted by university
stakeholders.
During our preliminary meetings, CTU’s requirements were
defined and adequately scoped to begin creation of the database.
The following sections contain the business rules and entity
tables developed during the preliminary meetings, as well as
copies of all the SQL code used to build the database and create
the Entity Relationship Diagram (ERD). Business Rules &
Entity Tables
Business Rules:
· A student has a name, a birth date, and gender.
· You must track the date the student started at the university
and his or her current GPA, as well as be able to inactivate him
or her without deleting information.
· For advising purposes, store the student's background/bio
information. This is like a little story.
· An advisor has a name and an e-mail address.
· Students are assigned to one advisor, but one advisor may
service multiple students.
· A class has a class code, name, and description.
· You need to indicate the specific classes a student is
taking/has taken at the university. Track the date the student
started a specific class and the grade earned in that class.
· Each class that a student takes has 4 assignments. Each
assignment is worth 100 points.Entity Tables:
SQL CODE:
Create Database:
CREATE DATABASE [Cameron_CTU]
CONTAINMENT = NONE
ON PRIMARY
( NAME = N'Cameron_CTU', FILENAME = N'c:Program
FilesMicrosoft SQL
ServerMSSQL11.SCAMERON_CTUMSSQLDATACameron_
CTU.mdf' , SIZE = 3072KB , FILEGROWTH = 1024KB )
LOG ON
( NAME = N'Cameron_CTU_log', FILENAME = N'c:Program
FilesMicrosoft SQL
ServerMSSQL11.SCAMERON_CTUMSSQLDATACameron_
CTU_log.ldf' , SIZE = 1024KB , FILEGROWTH = 01% )
GO
ALTER DATABASE [Cameron_CTU] SET
COMPATIBILITY_LEVEL = 110
GO
ALTER DATABASE [Cameron_CTU] SET
ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [Cameron_CTU] SET ANSI_NULLS OFF
GO
ALTER DATABASE [Cameron_CTU] SET ANSI_PADDING
OFF
GO
ALTER DATABASE [Cameron_CTU] SET ANSI_WARNINGS
OFF
GO
ALTER DATABASE [Cameron_CTU] SET ARITHABORT OFF
GO
ALTER DATABASE [Cameron_CTU] SET AUTO_CLOSE OFF
GO
ALTER DATABASE [Cameron_CTU] SET
AUTO_CREATE_STATISTICS ON
GO
ALTER DATABASE [Cameron_CTU] SET AUTO_SHRINK
OFF
GO
ALTER DATABASE [Cameron_CTU] SET
AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [Cameron_CTU] SET
CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [Cameron_CTU] SET
CURSOR_DEFAULT GLOBAL
GO
ALTER DATABASE [Cameron_CTU] SET
CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [Cameron_CTU] SET
NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [Cameron_CTU] SET
QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [Cameron_CTU] SET
RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [Cameron_CTU] SET
DISABLE_BROKER
GO
ALTER DATABASE [Cameron_CTU] SET
AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [Cameron_CTU] SET
DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [Cameron_CTU] SET
PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [Cameron_CTU] SET
READ_COMMITTED_SNAPSHOT OFF
GO
ALTER DATABASE [Cameron_CTU] SET READ_WRITE
GO
ALTER DATABASE [Cameron_CTU] SET RECOVERY
SIMPLE
GO
ALTER DATABASE [Cameron_CTU] SET MULTI_USER
GO
ALTER DATABASE [Cameron_CTU] SET PAGE_VERIFY
CHECKSUM
GO
ALTER DATABASE [Cameron_CTU] SET
TARGET_RECOVERY_TIME = 0 SECONDS
GO
USE [Cameron_CTU]
GO
IF NOT EXISTS (SELECT name FROM sys.filegroups WHERE
is_default=1 AND name = N'PRIMARY') ALTER DATABASE
[Cameron_CTU] MODIFY FILEGROUP [PRIMARY]
DEFAULT
GO
Create Students Table:
CREATE TABLE [dbo].[Students]
(
[StudentID] [int] IDENTITY(1,1) PRIMARY KEY NOT
NULL,
[FistName] [varchar](255) NOT NULL,
[LastName] [varchar](255) NOT NULL,
[BirthDate] [date] NOT NULL,
[Gender] [char](1) NOT NULL,
[StartDate] [date] NOT NULL,
[GPA] [numeric](4, 0) NOT NULL,
[IsActive] [varchar](50) NOT NULL,
[Bio] [varchar](255) NOT NULL,
[AdvisorID] [int] NOT NULL,
)
Create Advisors Table:
CREATE TABLE [dbo].[Advisors]
(
[AdvisorID] [int] IDENTITY(1,1) PRIMARY KEY NOT
NULL,
[FirstName] [varchar](50) NOT NULL,
[LastName] [varchar](50) NOT NULL,
[EmailAddr] [varchar](100) NOT NULL,
)
Create Classes Table:
CREATE TABLE [dbo].[Classes]
(
[ClassID] [int] IDENTITY(1,1) PRIMARY KEY NOT
NULL,
[ClassCode] [varchar](50) NOT NULL,
[ClassName] [varchar](100) NOT NULL,
[Description] [varchar](300) NOT NULL,
)
Create Students_Classes Table and make ‘AdvisorID’ and
‘DegreeID’ FOREIGN KEYS, and make ‘StudentID’ a
FOREIGN KEY on the Students_Classes table.
USE Cameron_CTU
CREATE TABLE Students
(StudentID INT IDENTITY PRIMARY KEY NOT NULL,
FirstName VARCHAR(35) NOT NULL,
LastName VARCHAR(30) NOT NULL,
BirthDate DATE NOT NULL,
Gender CHAR(1) NOT NULL,
StartDate DATE,
GPA DECIMAL(4,2),
IsActive CHAR(3) NOT NULL,
Bio VARCHAR(3000),
AdvisorID [int],
DegreeID [int] NOT NULL,
)
ALTER TABLE Students
ADD FOREIGN KEY (AdvisorID)
REFERENCES Advisors ([AdvisorID])
GO
ALTER TABLE Students
ADD FOREIGN KEY ([DegreeID])
REFERENCES Degrees ([DegreeID])
GO
ALTER TABLE Students_Classes
ADD FOREIGN KEY (StudentID)
REFERENCES Students(StudentID)
Once the relationships have been established, the ERD can be
created
New DML script to add required constraints for GPA, Gender,
and Assignments1 – Assignments4
USE Cameron_CTU
ALTER TABLE Students
ADD CONSTRAINT chkGPA
CHECK (GPA BETWEEN 0.00 and 4.00);
ALTER TABLE Students
ADD CONSTRAINT chkGender
CHECK (Gender IN ('M', 'F'));
ALTER TABLE Students_Classes
ADD CONSTRAINT chkAssignment1
CHECK (Assignment1 BETWEEN
0 AND 100);
ALTER TABLE Students_Classes
ADD CONSTRAINT chkAssignment2
CHECK (Assignment2 BETWEEN
0 AND 100);
ALTER TABLE Students_Classes
ADD CONSTRAINT chkAssignment3
CHECK (Assignment3 BETWEEN
0 AND 100);
ALTER TABLE Students_Classes
ADD CONSTRAINT chkAssignment4
CHECK (Assignment4 BETWEEN
0 AND 100);
(Fehily, 2008)
This section contains screenshots of the query windows once the
code was executed successfully.Screenshots:
Create Database:
Create Students Table with FOREIGN KEYS:
Create Advisors Table:
Create Classes Table:
Create Students_Classes Table:
Alter [Students_Classes] & [Students] Tables to assign Foreign
Keys to them, which are PRIMARY KEYS on the referenced
tables. Once the relationships have been established, the ERD
can be created
New DML script to add required constraints for GPA, Gender,
and Assignments1 – Assignments4
New Database Diagram: ERD
Phase 2 – Security and DML
Carrying on from Phase 1 tasks of creating our university
database, with the four tables of Students, Advisors, Classes,
and Students_Classes, Phase 2 calls for data to be inserted,
deleted, and updated. The INSERT statement has two ways to
enter. The positional insert inserts ordered values into a new
row in the same order of the table columns. A named-column
insert names the exact column where each value’s inserted into
a new row. Its good practice to use a named-column insert,
which allows your SQL code to work if the table’s columns are
reordered or a new column is added. You would use INSERT
VALUES to specify column values, and INSERT SELECT to
insert rows from another table. Some DBMS don’t make it
mandatory to use the INTO keyword after the INSERT
statement; however, you should use it for its portability
capabilities. (Fehily, 2008)
The UPDATE statement is used to change values in a table’s
existing rows. You need to be very cautious when using the
update statement because if you forget to add the ‘WHERE’
clause, you will update all rows instead of just your target rows.
Remember that each updated value has to have the same data
type or be totally convertible to the same type as its column.
(Fehily, 2008)
The DELETE statement is a little more powerful because its
used to delete an entire row, not jjust a column or columns.
You can delete just one or all rows of a table, so be cautious
with the delete statement also. Without the WHERE clause, all
table rows will be deleted. (Fehily, 2008)
Task 1
The first task was to insert data into four rows of the Classes
table. The following SQL code is what I used to accomplish the
task, followed by the screenshot of the query being executed
successfully.
INSERT INTO [Cameron_CTU].[DBO].[Classes]
( [ClassCode], [ClassName], [Description] )
VALUES
( 'ACCT306', 'Accounting 1', 'This course introduces
accounting concepts and explores the accounting environment.
It covers the basic structure of accounting, how to
maintain accounts, use account balances to prepare financial
statements, and complete the accounting cycle. It
also introduces the concept of internal control and how to
account for assets.' ),
( 'CS362', 'Structured Query Language for Data
Management', 'This course gives complete coverage of SQL,
with an emphasis on storage,
retrieval, and manipulation of data.' ),
( 'ENGL115', 'English Composition', 'In this course,
students focus on developing writing skills through practice and
revision.
Students will examine expository, critical, and
persuasive essay techniques.' ),
( 'FIN322', 'Investments', 'This course focuses on
investments and investment strategies. Various investment
vehicles such as stocks,
bonds, and commodities are examined. Students
will explore the principles of security analysis and valuation.' )
(Fehily, 2008)
Task 2
The second task was to insert data into three rows of the
Advisors table. The following SQL code is what I used to
accomplish the task, followed by the screenshot of the query
being executed successfully.
INSERT INTO [dbo].[Advisors]
( [FirstName],
[LastName],
[EmailAddr] )
VALUES
( 'Fred', 'Stone', '[email protected]' ),
( 'Bob', 'Gordon', '[email protected]' ),
( 'Jack', 'Simpson', '[email protected]')
(Fehily, 2008)
Task 3
The third task was to insert data into four rows of the Students
table. The following SQL code is what I used to accomplish the
task, followed by the screenshot of the query being executed
successfully.
INSERT INTO [dbo].[Students]
( [FirstName],
[LastName],
[BirthDate],
[Gender],
[StartDate],
[GPA],
[IsActive],
[Bio],
[AdvisorID] )
VALUES
( 'Craig', 'Franklin', '1970-03-15', 'm', '2010-05-30', 3.10, 'Yes',
'', 3 ),
( 'Harriet', 'Smith', '1982-04-15', 'f', '2010-05-30', 3.22, 'Yes',
'', 1 ),
( 'George', 'David', '1984-11-05', 'm', '2010-10-01', 0.00, 'Yes',
'', 3 ),
( 'Ben', 'Jefferson', '1976-09-25', 'm', '2009-02-21', 1.80, 'No',
'The student has gone on temporary leave to pursue other
opportunities but plans on returning in 1 year.', 3 )
(Fehily, 2008)Task 4
The fourth task was to delete the course named Investments
from the system, and the following SQL code is what I used to
accomplish the task, followed by the screenshot of the query
being executed successfully.
DELETE FROM Classes
WHERE ClassID = 'FIN322';
(Fehily, 2008)
Task 5
The fifth and final task called for changing 2 columns in a row
on the Students table, and the following SQL code is what I
used to accomplish the task, followed by the screenshot of the
query being executed successfully.
UPDATE Students
SET BirthDate = '1982-04-25',
GPA = 3.25
WHERE StudentID = '2';
(Fehily, 2008)
Phase 3 - DML (Select) and Procedures
Phase 3 has seven tasks that call for retrieving data using
the SELECT and FROM Statements. The SELECT clause calls
for which column or columns to display, and the FROM clause
identifies the table or tables the columns belong to. You can
also use the AS clause in order to create column aliases, which
I’ll go over in the last few tasks. You can also sort rows with
the ORDER BY clause, which I’ll also hit on in the tasks. The
WHERE clause filters unwanted rows. Without it, you results
would be every row on your queried table. Some other
statement clauses include AND, OR, ORDER BY GROUP BY,
JOIN. There are two types of JOIN clauses. They are Implicit
and explicit. Implicit is used a lot, and you may not even
realize your using it because there is no actual JOIN clause with
JOIN in it; its implied when you’re querying more than one
table. Lets get started with the tasks now, shall we?
(Fehily, 2008) The first thing I’m going to do is fix my SQL
statement in the Phase 2 section, Task 5. I fixed it by using
StudentID in the SELECT clause.
Task 1
The first task calls for a list of all active male students
assigned to Advisors 1 or 3.
So, we want to query the Advisor. Advisor ID, FirstName and
LastName columns along with theStudents.AdvisorID,
FirstName, LastName, Birthdate, Gender, and GPA columns of
the Students and Advisors tables. We use an implicit JOIN with
the WHERE clause to JOIN the two tables of Student.AdvisorID
and Advisor.AdvisorId together. Below, you’ll find the SQL
Statement I used to retrieve the required data, and screenshot
that shows a successful query.
SELECT Gender, IsActive, AdvisorID
FROM Cameron_CTU.dbo.Students
WHERE Gender = 'm'
AND IsActive = 'yes'
AND AdvisorID IN (1,3)
Task 2
The second task asks for a list of students without a
biography. Here’s the SQL Statement I used, and screenshot
that shows a successful query.
Task 3
Task 3 is a very simple statement asking what classes are in the
English Department. This SQL statement involves a wild card
just after the L in the word “English”. The SQL statement and
its associated screenshot are below.
SELECT ClassCode, ClassName
FROM Cameron_CTU.dbo.Classes
WHERE ClassName LIKE 'ENGL%'
Task 4
Task 4 calls for a list of all students and their advisors, and
sorted by Advisors, and a few columns from the Students table
SELECT A.AdvisorID, A.FirstName, A.LastName,
S.AdvisorID, S.FirstName, S.LastName,BirthDate, Gender,
GPA
FROM Cameron_CTU.dbo.Students S,
Cameron_CTU.dbo.Advisors A
WHERE S.AdvisorID = A.AdvisorID
ORDER BY A.LastName, S.LastName ASC;
SELECT A.CustomerID, A.FirstName, A.LastName,
S.AdvisorID, S.FirstName, S.LastName,BirthDate, Gender,
GPA
FROM Cameron_CTU.dbo.Students S,
Cameron_CTU.dbo.Advisors A
WHERE S.AdvisorID = A.AdvisorID
ORDER BY A.LastName, S.LastName ASC;
Task 5
The fifth task calls for the number of students born in the 80s.
Below, you’ll find the SQL Statement I used to retrieve the
required data, and screenshot that shows a successful query.
SELECT COUNT (StudentID) as Students_born_in_the_80s
FROM Cameron_CTU.dbo.Students
WHERE BirthDate between '1980-01-1' AND '1989-12-31';
Task 6
Task 6 wanted to know the average GPA score sorted by
men and women. Here is the SQL code and screenshot.
Task 7
Task 7 is looking for all of the advisors with only 1
student. Here’s the SQL code and screenshot.
SELECT A.firstname, A.LastName,
COUNT (A.AdvisorID) AS Total_Active_Students
FROM Cameron_CTU.dbo.Students S,
Cameron_CTU.dbo.Advisors A
WHERE A.AdvisorID = S.AdvisorID AND S.IsActive = 'yes'
GROUP BY A.FirstName, A.LastName
HAVING COUNT (S.StudentID) = '1';
Phase 4 – Architecture, Indexes
Phase 4 calls for a way to track classes required for degrees,
and which degree students are pursuing. We were given the
task of creating a table for tracking degrees with Degree Name
and Degree Description. However, the best way to track the
classes required for degrees is to create a table labeled
‘Degrees’ with columns labeled ‘DegreeID’, ‘DegreeName’ and
‘DegreeDescription’, and ‘DegreeCode’. Also adding a column
to the ‘Classes’ table, labeled DegreeID will help link the
‘Degrees’ and ‘Classes’ tables. After the tables have been
created, I’ll need to test the architecture to ensure it can render
the results I’m looking for in queries.
(Fehily, 2008)
However, I just received my grade for my Phase 1 IP with
identified errors. See Phase 1 section for fixed errors. The
errors that need corrected are:
- Considerations regarding my data types and field lengths:
FirstName and LastName too long
- Fix constraints for assignments 1 through 4 to ensure only 0-
100 can be input.
- Fix GPA Constraint to ensure input of only 0.00 – 4.00, and
permit only 3 total digits after decimal.
- Constrain ‘Gender’ to either M or F, and IsActive to either
Yes or No.
Step 1: CREATE TABLE [Degrees]
I’ll start by creating the table, ‘Degrees’ with the following
DDL script, followed by a screenshot of the query being
completed successfully, and the table structure that displays the
table columns to include the PRIMARY KEY, ‘DergeeID’.
USE [Cameron_CTU]
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Degrees]
(
[DegreeID] [int] IDENTITY(1,1) PRIMARY KEY NOT
NULL,
[DegreeName] [varchar](50) NOT NULL,
[DegreeDescription] [varchar](1000) NOT NULL,
[DegreeCode] [varchar](50) NOT NULL,
)
Step 2: Re-create ‘Classes’ TABLE to add ‘DegreeID’ column
and INSERT 6 classes
The next step is to delete and re-create the ‘Classes’ table,
and ensure that the ‘DegreeID’ column is included in the
creation, and made a FOREIGN KEY. Also, ensure you re-
insert the original 3 classes, and add 3 new classes into the
‘Classes’ table required by different degrees. And since you’ve
re-created the ‘Classes’ table with ‘DegreeID’ as a FOREIGN
KEY, make sure you add it to the INSERT INTO DDL script or
you’ll receive an error regarding the ‘DegreeID’ column.
Below are the following DDL scripts, followed by a screenshot
of the queries being completed successfully, and the table
structure that displays the table columns with ‘DegreeID’ as a
FOREIGN KEY, and the query results of the SELECT * FROM
Classes query.
USE [Cameron_CTU]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Classes]
(
[ClassID] [int] IDENTITY(1,1) PRIMARY KEY NOT
NULL,
[DegreeID] [int] NOT NULL,
[ClassCode] [varchar](50) NOT NULL,
[ClassName] [varchar](100) NOT NULL,
[Description] [varchar](1000) NOT NULL,
)
ALTER TABLE [dbo].[Classes]
ADD FOREIGN KEY([DegreeID])
REFERENCES [dbo].[Degrees]([DegreeID])
GO
INSERT INTO [Cameron_CTU].[DBO].[Classes]
( [DegreeID], [ClassCode], [ClassName], [Description] )
VALUES
( '4', 'ACCT306', 'Accounting 1', 'This course
introduces accounting concepts and explores the accounting
environment. It covers the basic structure of accounting, how to
maintain
accounts, use account balances to prepare financial
statements, and complete the accounting cycle. It also
introduces the concept of internal control and how to account
for assets.' ),
( '5', 'CS362', 'Structured Query Language for Data
Management', 'This course gives complete coverage of SQL,
with an emphasis on storage, retrieval, and manipulation of
data.' ),
( '3', 'ENGL115', 'English Composition', 'In this
course, students focus on developing writing skills through
practice and revision. Students will examine expository,
critical, and persuasive
essay techniques.' ),
( '3', 'BHVS205', 'Managerial Psychology', 'This
course introduces Psyhology concepts that will serve as the
foundation to other concepts, such as Motivation and Emotion
and Interpersonal
Communications and Dynamics.' ),
( '4', 'CSS150', 'Introduction to Computer Security',
'This course covers Computer Security Principles, such as
Policy letters, Remote Logins, and Network Security.' ),
( '5', 'CS126', 'UNIX Fundamentals', 'This course
teaches you thed origins of the UNIX Operating System, and
teaches you how to build directories.' )
Step 3: ALTER TABLE [Students]
As the paragraph title implies, the next step is to add the
‘DegreeID’ column to the ‘Students’ table, and make it a
FOREIGN KEY. Below is the following DDL script used to add
the column, and make it a FOREIGN KEY, and the screenshot
of the successful command.
USE [Cameron_CTU]
GO
ALTER TABLE Students
ADD DegreeID [int] NOT NULL
GO
ALTER TABLE Students
ADD FOREIGN KEY (DegreeID)
REFERENCES Degrees(DegreeID)
Step 4: DML script to insert 3 test records in [Degrees]
The next step is to insert degree data into the ‘Degrees’
table. Below is the DML script used, and a screenshot of the
successful command along with an inset of the results for a
SELECT * FROM Degrees statement.
INSERT INTO [Cameron_CTU].[DBO].[Degrees]
( [DegreeCode], [DegreeName], [DegreeDescription] )
VALUES
( 'BSIP', 'Bachelor of Science in Psychology', 'The Bachelor’s
degree in General Psychology is designed to prepare students to
successfully navigate in the 21st century workplace, in a variety
of careers that focus on the business of people, including but
not limited to work in management, administration, research,
and sales. It is positioned to provide an overview of the major
psychological concepts, perspectives, and skills that explain
human behavior. ' ),
( 'BSIS', 'Bachelor of Science in Information Security', 'The
Bachelors of Science in Information Assurance and Security
degree allows undergraduate learners to acquire and apply
various processes, tools, technologies, and methods of securing
an enterprise; including security policies, social engineering,
access control, authentication, perimeter security, disaster
recovery and business continuity, risk management, incident
response, viruses, malware, spam, encryption, and other
infrastructure security techniques that include governance and
strategic alignment of IT and business. ' ),
( 'BSIT', 'Bachelor of Science in Information Technology', 'The
Bachelor of Science in Information Technology (BSIT)
curriculum includes both a common core, as well as
specialization-specific courses. The BSIT core provides a strong
foundation in the key information technology areas of
programming, systems administration, security, architecture,
databases, and ethics.' )
Step 5: DML script to INSERT INTO the ‘Students’ table
‘DegreeID’ data
The next step is to add the ‘DegreeID’ to 4 records
applicable to each of the 4 students. Below is the DML script
used to execute the command and a screenshot showing it was
successful.
INSERT INTO [Cameron_CTU].[dbo].[Students]
( [FirstName],
[LastName],
[BirthDate],
[Gender],
[StartDate],
[GPA],
[IsActive],
[Bio],
[AdvisorID],
[DegreeID] )
VALUES
( 'Craig', 'Franklin', '1970-03-15', 'm', '2010-05-30', 3.10, 'Yes',
NULL, 3, 3 ),
( 'Harriet', 'Smith', '1982-04-15', 'f', '2010-05-30', 3.22, 'Yes',
NULL, 1, 4 ),
( 'George', 'David', '1984-11-05', 'm', '2010-10-01', 0.00, 'Yes',
NULL, 3, 5 ),
( 'Ben', 'Jefferson', '1976-09-25', 'm', '2009-02-21', 1.80, 'No',
'The student has
gone on temporary leave to pursue other opportunities but
plans on returning in 1 year.', 3, 3 )
The last step is to execute a SELECT statement with an
implicit JOIN clause to show what degree each student is
pursuing.
USE Cameron_CTU
SELECT FirstName, LastName, Students.DegreeID,
Degrees.DegreeName
FROM Cameron_CTU.dbo.Students,
Cameron_CTU.dbo.Degrees
WHERE Students.DegreeID = Degrees.DegreeID;
Step 6: Display ERD
Phase 5 – Views, Transactions, Testing and Performance
References
Fehily, C. (2008) Visual QuickStart Guide SQL, Third Edition,
[CourseSmart e-Book reader version] Retrieved from
http://wow.coursesmart.com/9781256745129/firstsection

More Related Content

Similar to Structured Query Language for Data Management 2 Sructu.docx

Oracle OCP 1Z0-007题库
Oracle OCP 1Z0-007题库Oracle OCP 1Z0-007题库
Oracle OCP 1Z0-007题库
renguzi
 
Database queries
Database queriesDatabase queries
Database queries
laiba29012
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SabrinaShanta2
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SaiMiryala1
 
Databricks Data Analyst Associate Exam Dumps 2024.pdf
Databricks Data Analyst Associate Exam Dumps 2024.pdfDatabricks Data Analyst Associate Exam Dumps 2024.pdf
Databricks Data Analyst Associate Exam Dumps 2024.pdf
SkillCertProExams
 
chap 7.ppt(sql).ppt
chap 7.ppt(sql).pptchap 7.ppt(sql).ppt
chap 7.ppt(sql).ppt
arjun431527
 
Sql server T-sql basics ppt-3
Sql server T-sql basics  ppt-3Sql server T-sql basics  ppt-3
Sql server T-sql basics ppt-3
Vibrant Technologies & Computers
 
21 ijaprr vol1-3-12-17juni
21 ijaprr vol1-3-12-17juni21 ijaprr vol1-3-12-17juni
21 ijaprr vol1-3-12-17juni
ijaprr_editor
 
Web Cloud Computing SQL Server - Ferrara University
Web Cloud Computing SQL Server  -  Ferrara UniversityWeb Cloud Computing SQL Server  -  Ferrara University
Web Cloud Computing SQL Server - Ferrara University
antimo musone
 
Data Manipulation(DML) and Transaction Control (TCL)
Data Manipulation(DML) and Transaction Control (TCL)  Data Manipulation(DML) and Transaction Control (TCL)
Data Manipulation(DML) and Transaction Control (TCL)
MuhammadWaheed44
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using Oracle
Farhan Aslam
 
Based on the materials for this week, create your own unique Datab.docx
Based on the materials for this week, create your own unique Datab.docxBased on the materials for this week, create your own unique Datab.docx
Based on the materials for this week, create your own unique Datab.docx
JASS44
 
dbms-unit-_part-1.pptxeqweqweqweqweqweqweqweq
dbms-unit-_part-1.pptxeqweqweqweqweqweqweqweqdbms-unit-_part-1.pptxeqweqweqweqweqweqweqweq
dbms-unit-_part-1.pptxeqweqweqweqweqweqweqweq
wrushabhsirsat
 
SQL Tunning
SQL TunningSQL Tunning
SQL Tunning
Dhananjay Goel
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
Vibrant Technologies & Computers
 

Similar to Structured Query Language for Data Management 2 Sructu.docx (20)

Oracle OCP 1Z0-007题库
Oracle OCP 1Z0-007题库Oracle OCP 1Z0-007题库
Oracle OCP 1Z0-007题库
 
Database queries
Database queriesDatabase queries
Database queries
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
 
Sql xp 06
Sql xp 06Sql xp 06
Sql xp 06
 
Databricks Data Analyst Associate Exam Dumps 2024.pdf
Databricks Data Analyst Associate Exam Dumps 2024.pdfDatabricks Data Analyst Associate Exam Dumps 2024.pdf
Databricks Data Analyst Associate Exam Dumps 2024.pdf
 
chap 7.ppt(sql).ppt
chap 7.ppt(sql).pptchap 7.ppt(sql).ppt
chap 7.ppt(sql).ppt
 
Sql server T-sql basics ppt-3
Sql server T-sql basics  ppt-3Sql server T-sql basics  ppt-3
Sql server T-sql basics ppt-3
 
21 ijaprr vol1-3-12-17juni
21 ijaprr vol1-3-12-17juni21 ijaprr vol1-3-12-17juni
21 ijaprr vol1-3-12-17juni
 
Web Cloud Computing SQL Server - Ferrara University
Web Cloud Computing SQL Server  -  Ferrara UniversityWeb Cloud Computing SQL Server  -  Ferrara University
Web Cloud Computing SQL Server - Ferrara University
 
Data Manipulation(DML) and Transaction Control (TCL)
Data Manipulation(DML) and Transaction Control (TCL)  Data Manipulation(DML) and Transaction Control (TCL)
Data Manipulation(DML) and Transaction Control (TCL)
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using Oracle
 
Based on the materials for this week, create your own unique Datab.docx
Based on the materials for this week, create your own unique Datab.docxBased on the materials for this week, create your own unique Datab.docx
Based on the materials for this week, create your own unique Datab.docx
 
Db presn(1)
Db presn(1)Db presn(1)
Db presn(1)
 
01 basic orders
01   basic orders01   basic orders
01 basic orders
 
dbms-unit-_part-1.pptxeqweqweqweqweqweqweqweq
dbms-unit-_part-1.pptxeqweqweqweqweqweqweqweqdbms-unit-_part-1.pptxeqweqweqweqweqweqweqweq
dbms-unit-_part-1.pptxeqweqweqweqweqweqweqweq
 
SQL Tunning
SQL TunningSQL Tunning
SQL Tunning
 
Chap 7
Chap 7Chap 7
Chap 7
 
mis4200notes4_2.ppt
mis4200notes4_2.pptmis4200notes4_2.ppt
mis4200notes4_2.ppt
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
 

More from johniemcm5zt

Student answer  The French and the German were a bit different w.docx
Student answer  The French and the German were a bit different w.docxStudent answer  The French and the German were a bit different w.docx
Student answer  The French and the German were a bit different w.docx
johniemcm5zt
 
Student Answer and Work Form Unit 4 Ver. AStudent Name (required.docx
Student Answer and Work Form Unit 4 Ver. AStudent Name (required.docxStudent Answer and Work Form Unit 4 Ver. AStudent Name (required.docx
Student Answer and Work Form Unit 4 Ver. AStudent Name (required.docx
johniemcm5zt
 
Student 1 Random Student Mrs. Wilson Expository W.docx
Student 1 Random Student  Mrs. Wilson Expository W.docxStudent 1 Random Student  Mrs. Wilson Expository W.docx
Student 1 Random Student Mrs. Wilson Expository W.docx
johniemcm5zt
 
Student Answer and Work Form Unit 3 Ver. CStudent Name ________.docx
Student Answer and Work Form Unit 3 Ver. CStudent Name ________.docxStudent Answer and Work Form Unit 3 Ver. CStudent Name ________.docx
Student Answer and Work Form Unit 3 Ver. CStudent Name ________.docx
johniemcm5zt
 
Student answer A. (1) Use Mancur Olsons theory to explain the b.docx
Student answer A. (1) Use Mancur Olsons theory to explain the b.docxStudent answer A. (1) Use Mancur Olsons theory to explain the b.docx
Student answer A. (1) Use Mancur Olsons theory to explain the b.docx
johniemcm5zt
 
Student 1StudentProfessor ENG 10827 June 2014Instruments.docx
Student 1StudentProfessor ENG 10827 June 2014Instruments.docxStudent 1StudentProfessor ENG 10827 June 2014Instruments.docx
Student 1StudentProfessor ENG 10827 June 2014Instruments.docx
johniemcm5zt
 
Student Project There is no extension of the due date for t.docx
Student  Project   There is no extension of the due date for t.docxStudent  Project   There is no extension of the due date for t.docx
Student Project There is no extension of the due date for t.docx
johniemcm5zt
 
Studding abroad has become a major priority to for the higher educ.docx
Studding abroad has become a major priority to for the higher educ.docxStudding abroad has become a major priority to for the higher educ.docx
Studding abroad has become a major priority to for the higher educ.docx
johniemcm5zt
 
Student 1Student ENG 11008 March 2015The King of Equalit.docx
Student 1Student ENG 11008 March 2015The King of Equalit.docxStudent 1Student ENG 11008 March 2015The King of Equalit.docx
Student 1Student ENG 11008 March 2015The King of Equalit.docx
johniemcm5zt
 
Studcnft Cl.nthiaEdnads fnrtructor HilaryCla Assignmenf W2H.docx
Studcnft Cl.nthiaEdnads fnrtructor HilaryCla Assignmenf W2H.docxStudcnft Cl.nthiaEdnads fnrtructor HilaryCla Assignmenf W2H.docx
Studcnft Cl.nthiaEdnads fnrtructor HilaryCla Assignmenf W2H.docx
johniemcm5zt
 
Structure!Thesis British politics were changed in such a fa.docx
Structure!Thesis British politics were changed in such a fa.docxStructure!Thesis British politics were changed in such a fa.docx
Structure!Thesis British politics were changed in such a fa.docx
johniemcm5zt
 
Student #1 I have chosen to write about the history of data anal.docx
Student #1 I have chosen to write about the history of data anal.docxStudent #1 I have chosen to write about the history of data anal.docx
Student #1 I have chosen to write about the history of data anal.docx
johniemcm5zt
 
Student answer (a) In US business unionism focuses on benefits t.docx
Student answer (a) In US business unionism focuses on benefits t.docxStudent answer (a) In US business unionism focuses on benefits t.docx
Student answer (a) In US business unionism focuses on benefits t.docx
johniemcm5zt
 
strictman-lPer-)nger,n Ofracedrhfiess the.docx
strictman-lPer-)nger,n Ofracedrhfiess the.docxstrictman-lPer-)nger,n Ofracedrhfiess the.docx
strictman-lPer-)nger,n Ofracedrhfiess the.docx
johniemcm5zt
 
STRIKING A BALANCE BETWEEN PUBLIC INTEREST OFTRANSPARENCY OF.docx
STRIKING A BALANCE BETWEEN PUBLIC INTEREST OFTRANSPARENCY OF.docxSTRIKING A BALANCE BETWEEN PUBLIC INTEREST OFTRANSPARENCY OF.docx
STRIKING A BALANCE BETWEEN PUBLIC INTEREST OFTRANSPARENCY OF.docx
johniemcm5zt
 
Strengths Insight and Action-Planning GuideSURVEY COMPLETION.docx
Strengths Insight and Action-Planning GuideSURVEY COMPLETION.docxStrengths Insight and Action-Planning GuideSURVEY COMPLETION.docx
Strengths Insight and Action-Planning GuideSURVEY COMPLETION.docx
johniemcm5zt
 
Strengths Insight and Action-Planning Guide SURVEY COMPLETION DA.docx
Strengths Insight and Action-Planning Guide SURVEY COMPLETION DA.docxStrengths Insight and Action-Planning Guide SURVEY COMPLETION DA.docx
Strengths Insight and Action-Planning Guide SURVEY COMPLETION DA.docx
johniemcm5zt
 
Strategy Project.DS_Store__MACOSXStrategy Project._.DS_St.docx
Strategy Project.DS_Store__MACOSXStrategy Project._.DS_St.docxStrategy Project.DS_Store__MACOSXStrategy Project._.DS_St.docx
Strategy Project.DS_Store__MACOSXStrategy Project._.DS_St.docx
johniemcm5zt
 
STRAYER BUS475 WEEK 10 QUIZ 10Report this Question as Inappropri.docx
STRAYER BUS475 WEEK 10 QUIZ 10Report this Question as Inappropri.docxSTRAYER BUS475 WEEK 10 QUIZ 10Report this Question as Inappropri.docx
STRAYER BUS475 WEEK 10 QUIZ 10Report this Question as Inappropri.docx
johniemcm5zt
 
Strayer University 2.13 (Discussion #1) Yahoo! CEO Bans Tele.docx
Strayer University  2.13 (Discussion #1) Yahoo! CEO Bans Tele.docxStrayer University  2.13 (Discussion #1) Yahoo! CEO Bans Tele.docx
Strayer University 2.13 (Discussion #1) Yahoo! CEO Bans Tele.docx
johniemcm5zt
 

More from johniemcm5zt (20)

Student answer  The French and the German were a bit different w.docx
Student answer  The French and the German were a bit different w.docxStudent answer  The French and the German were a bit different w.docx
Student answer  The French and the German were a bit different w.docx
 
Student Answer and Work Form Unit 4 Ver. AStudent Name (required.docx
Student Answer and Work Form Unit 4 Ver. AStudent Name (required.docxStudent Answer and Work Form Unit 4 Ver. AStudent Name (required.docx
Student Answer and Work Form Unit 4 Ver. AStudent Name (required.docx
 
Student 1 Random Student Mrs. Wilson Expository W.docx
Student 1 Random Student  Mrs. Wilson Expository W.docxStudent 1 Random Student  Mrs. Wilson Expository W.docx
Student 1 Random Student Mrs. Wilson Expository W.docx
 
Student Answer and Work Form Unit 3 Ver. CStudent Name ________.docx
Student Answer and Work Form Unit 3 Ver. CStudent Name ________.docxStudent Answer and Work Form Unit 3 Ver. CStudent Name ________.docx
Student Answer and Work Form Unit 3 Ver. CStudent Name ________.docx
 
Student answer A. (1) Use Mancur Olsons theory to explain the b.docx
Student answer A. (1) Use Mancur Olsons theory to explain the b.docxStudent answer A. (1) Use Mancur Olsons theory to explain the b.docx
Student answer A. (1) Use Mancur Olsons theory to explain the b.docx
 
Student 1StudentProfessor ENG 10827 June 2014Instruments.docx
Student 1StudentProfessor ENG 10827 June 2014Instruments.docxStudent 1StudentProfessor ENG 10827 June 2014Instruments.docx
Student 1StudentProfessor ENG 10827 June 2014Instruments.docx
 
Student Project There is no extension of the due date for t.docx
Student  Project   There is no extension of the due date for t.docxStudent  Project   There is no extension of the due date for t.docx
Student Project There is no extension of the due date for t.docx
 
Studding abroad has become a major priority to for the higher educ.docx
Studding abroad has become a major priority to for the higher educ.docxStudding abroad has become a major priority to for the higher educ.docx
Studding abroad has become a major priority to for the higher educ.docx
 
Student 1Student ENG 11008 March 2015The King of Equalit.docx
Student 1Student ENG 11008 March 2015The King of Equalit.docxStudent 1Student ENG 11008 March 2015The King of Equalit.docx
Student 1Student ENG 11008 March 2015The King of Equalit.docx
 
Studcnft Cl.nthiaEdnads fnrtructor HilaryCla Assignmenf W2H.docx
Studcnft Cl.nthiaEdnads fnrtructor HilaryCla Assignmenf W2H.docxStudcnft Cl.nthiaEdnads fnrtructor HilaryCla Assignmenf W2H.docx
Studcnft Cl.nthiaEdnads fnrtructor HilaryCla Assignmenf W2H.docx
 
Structure!Thesis British politics were changed in such a fa.docx
Structure!Thesis British politics were changed in such a fa.docxStructure!Thesis British politics were changed in such a fa.docx
Structure!Thesis British politics were changed in such a fa.docx
 
Student #1 I have chosen to write about the history of data anal.docx
Student #1 I have chosen to write about the history of data anal.docxStudent #1 I have chosen to write about the history of data anal.docx
Student #1 I have chosen to write about the history of data anal.docx
 
Student answer (a) In US business unionism focuses on benefits t.docx
Student answer (a) In US business unionism focuses on benefits t.docxStudent answer (a) In US business unionism focuses on benefits t.docx
Student answer (a) In US business unionism focuses on benefits t.docx
 
strictman-lPer-)nger,n Ofracedrhfiess the.docx
strictman-lPer-)nger,n Ofracedrhfiess the.docxstrictman-lPer-)nger,n Ofracedrhfiess the.docx
strictman-lPer-)nger,n Ofracedrhfiess the.docx
 
STRIKING A BALANCE BETWEEN PUBLIC INTEREST OFTRANSPARENCY OF.docx
STRIKING A BALANCE BETWEEN PUBLIC INTEREST OFTRANSPARENCY OF.docxSTRIKING A BALANCE BETWEEN PUBLIC INTEREST OFTRANSPARENCY OF.docx
STRIKING A BALANCE BETWEEN PUBLIC INTEREST OFTRANSPARENCY OF.docx
 
Strengths Insight and Action-Planning GuideSURVEY COMPLETION.docx
Strengths Insight and Action-Planning GuideSURVEY COMPLETION.docxStrengths Insight and Action-Planning GuideSURVEY COMPLETION.docx
Strengths Insight and Action-Planning GuideSURVEY COMPLETION.docx
 
Strengths Insight and Action-Planning Guide SURVEY COMPLETION DA.docx
Strengths Insight and Action-Planning Guide SURVEY COMPLETION DA.docxStrengths Insight and Action-Planning Guide SURVEY COMPLETION DA.docx
Strengths Insight and Action-Planning Guide SURVEY COMPLETION DA.docx
 
Strategy Project.DS_Store__MACOSXStrategy Project._.DS_St.docx
Strategy Project.DS_Store__MACOSXStrategy Project._.DS_St.docxStrategy Project.DS_Store__MACOSXStrategy Project._.DS_St.docx
Strategy Project.DS_Store__MACOSXStrategy Project._.DS_St.docx
 
STRAYER BUS475 WEEK 10 QUIZ 10Report this Question as Inappropri.docx
STRAYER BUS475 WEEK 10 QUIZ 10Report this Question as Inappropri.docxSTRAYER BUS475 WEEK 10 QUIZ 10Report this Question as Inappropri.docx
STRAYER BUS475 WEEK 10 QUIZ 10Report this Question as Inappropri.docx
 
Strayer University 2.13 (Discussion #1) Yahoo! CEO Bans Tele.docx
Strayer University  2.13 (Discussion #1) Yahoo! CEO Bans Tele.docxStrayer University  2.13 (Discussion #1) Yahoo! CEO Bans Tele.docx
Strayer University 2.13 (Discussion #1) Yahoo! CEO Bans Tele.docx
 

Recently uploaded

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 

Recently uploaded (20)

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 

Structured Query Language for Data Management 2 Sructu.docx

  • 1. Structured Query Language for Data Management 2 Sructured Query Language for Data Management 6 Table of Contents Phase 1- Database Design and DDL 3 Business Rules & Entity Tables 3 Entity Tables: 4 SQL CODE: 4 Screenshots: 8 Phase 2 – Security and DML 13 Task 1 14 Task 2 15 Task 3 16 Task 4 17 Task 5 18 Phase 3 - DML (Select) and Procedures 19 Task 1 19 Task 2 20 Task 3 21 Task 4 22 Task 5 23 Phase 4 – Architecture, Indexes 27 Step 1: CREATE TABLE [Degrees] 27 Step 2: Re-create ‘Classes’ TABLE to add ‘DegreeID’ column and INSERT 6 classes 29 Step 3: ALTER TABLE [Students] 31 Step 5: DML script to INSERT INTO the ‘Students’ table ‘DegreeID’ data 33 Step 6: Display ERD 36 Phase 5 – Views, Transactions, Testing and Performance37 References 38 Phase 1- Database Design and DDL
  • 2. My team was recently contracted to design and develop a database for CTU that will store personal and confidential university data. This database is expected to provide the back- end architecture for a front-end web application with an intuitive User/Interface (U/I) to be used by the university HR department. We’ve decided to use Microsoft SQL Server 2012 given the nature of data to be stored because it will be more secure, and it also provides a suite of server maintenance tools to be left behind with the IT Department once the database and web application have been tested and accepted by university stakeholders. During our preliminary meetings, CTU’s requirements were defined and adequately scoped to begin creation of the database. The following sections contain the business rules and entity tables developed during the preliminary meetings, as well as copies of all the SQL code used to build the database and create the Entity Relationship Diagram (ERD). Business Rules & Entity Tables Business Rules: · A student has a name, a birth date, and gender. · You must track the date the student started at the university and his or her current GPA, as well as be able to inactivate him or her without deleting information. · For advising purposes, store the student's background/bio information. This is like a little story. · An advisor has a name and an e-mail address. · Students are assigned to one advisor, but one advisor may service multiple students. · A class has a class code, name, and description. · You need to indicate the specific classes a student is taking/has taken at the university. Track the date the student started a specific class and the grade earned in that class. · Each class that a student takes has 4 assignments. Each assignment is worth 100 points.Entity Tables:
  • 3. SQL CODE: Create Database: CREATE DATABASE [Cameron_CTU] CONTAINMENT = NONE ON PRIMARY ( NAME = N'Cameron_CTU', FILENAME = N'c:Program FilesMicrosoft SQL ServerMSSQL11.SCAMERON_CTUMSSQLDATACameron_ CTU.mdf' , SIZE = 3072KB , FILEGROWTH = 1024KB ) LOG ON ( NAME = N'Cameron_CTU_log', FILENAME = N'c:Program FilesMicrosoft SQL ServerMSSQL11.SCAMERON_CTUMSSQLDATACameron_ CTU_log.ldf' , SIZE = 1024KB , FILEGROWTH = 01% ) GO ALTER DATABASE [Cameron_CTU] SET COMPATIBILITY_LEVEL = 110 GO ALTER DATABASE [Cameron_CTU] SET ANSI_NULL_DEFAULT OFF GO ALTER DATABASE [Cameron_CTU] SET ANSI_NULLS OFF GO ALTER DATABASE [Cameron_CTU] SET ANSI_PADDING OFF GO ALTER DATABASE [Cameron_CTU] SET ANSI_WARNINGS OFF GO ALTER DATABASE [Cameron_CTU] SET ARITHABORT OFF GO ALTER DATABASE [Cameron_CTU] SET AUTO_CLOSE OFF GO ALTER DATABASE [Cameron_CTU] SET AUTO_CREATE_STATISTICS ON GO
  • 4. ALTER DATABASE [Cameron_CTU] SET AUTO_SHRINK OFF GO ALTER DATABASE [Cameron_CTU] SET AUTO_UPDATE_STATISTICS ON GO ALTER DATABASE [Cameron_CTU] SET CURSOR_CLOSE_ON_COMMIT OFF GO ALTER DATABASE [Cameron_CTU] SET CURSOR_DEFAULT GLOBAL GO ALTER DATABASE [Cameron_CTU] SET CONCAT_NULL_YIELDS_NULL OFF GO ALTER DATABASE [Cameron_CTU] SET NUMERIC_ROUNDABORT OFF GO ALTER DATABASE [Cameron_CTU] SET QUOTED_IDENTIFIER OFF GO ALTER DATABASE [Cameron_CTU] SET RECURSIVE_TRIGGERS OFF GO ALTER DATABASE [Cameron_CTU] SET DISABLE_BROKER GO ALTER DATABASE [Cameron_CTU] SET AUTO_UPDATE_STATISTICS_ASYNC OFF GO ALTER DATABASE [Cameron_CTU] SET DATE_CORRELATION_OPTIMIZATION OFF GO ALTER DATABASE [Cameron_CTU] SET PARAMETERIZATION SIMPLE GO
  • 5. ALTER DATABASE [Cameron_CTU] SET READ_COMMITTED_SNAPSHOT OFF GO ALTER DATABASE [Cameron_CTU] SET READ_WRITE GO ALTER DATABASE [Cameron_CTU] SET RECOVERY SIMPLE GO ALTER DATABASE [Cameron_CTU] SET MULTI_USER GO ALTER DATABASE [Cameron_CTU] SET PAGE_VERIFY CHECKSUM GO ALTER DATABASE [Cameron_CTU] SET TARGET_RECOVERY_TIME = 0 SECONDS GO USE [Cameron_CTU] GO IF NOT EXISTS (SELECT name FROM sys.filegroups WHERE is_default=1 AND name = N'PRIMARY') ALTER DATABASE [Cameron_CTU] MODIFY FILEGROUP [PRIMARY] DEFAULT GO Create Students Table: CREATE TABLE [dbo].[Students] ( [StudentID] [int] IDENTITY(1,1) PRIMARY KEY NOT
  • 6. NULL, [FistName] [varchar](255) NOT NULL, [LastName] [varchar](255) NOT NULL, [BirthDate] [date] NOT NULL, [Gender] [char](1) NOT NULL, [StartDate] [date] NOT NULL, [GPA] [numeric](4, 0) NOT NULL, [IsActive] [varchar](50) NOT NULL, [Bio] [varchar](255) NOT NULL, [AdvisorID] [int] NOT NULL, ) Create Advisors Table: CREATE TABLE [dbo].[Advisors] ( [AdvisorID] [int] IDENTITY(1,1) PRIMARY KEY NOT NULL, [FirstName] [varchar](50) NOT NULL, [LastName] [varchar](50) NOT NULL, [EmailAddr] [varchar](100) NOT NULL, ) Create Classes Table: CREATE TABLE [dbo].[Classes] ( [ClassID] [int] IDENTITY(1,1) PRIMARY KEY NOT NULL, [ClassCode] [varchar](50) NOT NULL, [ClassName] [varchar](100) NOT NULL, [Description] [varchar](300) NOT NULL, ) Create Students_Classes Table and make ‘AdvisorID’ and ‘DegreeID’ FOREIGN KEYS, and make ‘StudentID’ a FOREIGN KEY on the Students_Classes table. USE Cameron_CTU CREATE TABLE Students (StudentID INT IDENTITY PRIMARY KEY NOT NULL,
  • 7. FirstName VARCHAR(35) NOT NULL, LastName VARCHAR(30) NOT NULL, BirthDate DATE NOT NULL, Gender CHAR(1) NOT NULL, StartDate DATE, GPA DECIMAL(4,2), IsActive CHAR(3) NOT NULL, Bio VARCHAR(3000), AdvisorID [int], DegreeID [int] NOT NULL, ) ALTER TABLE Students ADD FOREIGN KEY (AdvisorID) REFERENCES Advisors ([AdvisorID]) GO ALTER TABLE Students ADD FOREIGN KEY ([DegreeID]) REFERENCES Degrees ([DegreeID]) GO ALTER TABLE Students_Classes ADD FOREIGN KEY (StudentID) REFERENCES Students(StudentID) Once the relationships have been established, the ERD can be created New DML script to add required constraints for GPA, Gender, and Assignments1 – Assignments4 USE Cameron_CTU ALTER TABLE Students ADD CONSTRAINT chkGPA CHECK (GPA BETWEEN 0.00 and 4.00);
  • 8. ALTER TABLE Students ADD CONSTRAINT chkGender CHECK (Gender IN ('M', 'F')); ALTER TABLE Students_Classes ADD CONSTRAINT chkAssignment1 CHECK (Assignment1 BETWEEN 0 AND 100); ALTER TABLE Students_Classes ADD CONSTRAINT chkAssignment2 CHECK (Assignment2 BETWEEN 0 AND 100); ALTER TABLE Students_Classes ADD CONSTRAINT chkAssignment3 CHECK (Assignment3 BETWEEN 0 AND 100); ALTER TABLE Students_Classes ADD CONSTRAINT chkAssignment4 CHECK (Assignment4 BETWEEN 0 AND 100); (Fehily, 2008)
  • 9. This section contains screenshots of the query windows once the code was executed successfully.Screenshots: Create Database: Create Students Table with FOREIGN KEYS: Create Advisors Table: Create Classes Table: Create Students_Classes Table: Alter [Students_Classes] & [Students] Tables to assign Foreign Keys to them, which are PRIMARY KEYS on the referenced tables. Once the relationships have been established, the ERD can be created
  • 10. New DML script to add required constraints for GPA, Gender, and Assignments1 – Assignments4 New Database Diagram: ERD Phase 2 – Security and DML Carrying on from Phase 1 tasks of creating our university database, with the four tables of Students, Advisors, Classes, and Students_Classes, Phase 2 calls for data to be inserted, deleted, and updated. The INSERT statement has two ways to enter. The positional insert inserts ordered values into a new row in the same order of the table columns. A named-column insert names the exact column where each value’s inserted into a new row. Its good practice to use a named-column insert, which allows your SQL code to work if the table’s columns are reordered or a new column is added. You would use INSERT VALUES to specify column values, and INSERT SELECT to insert rows from another table. Some DBMS don’t make it mandatory to use the INTO keyword after the INSERT statement; however, you should use it for its portability capabilities. (Fehily, 2008) The UPDATE statement is used to change values in a table’s existing rows. You need to be very cautious when using the update statement because if you forget to add the ‘WHERE’ clause, you will update all rows instead of just your target rows. Remember that each updated value has to have the same data type or be totally convertible to the same type as its column. (Fehily, 2008) The DELETE statement is a little more powerful because its used to delete an entire row, not jjust a column or columns. You can delete just one or all rows of a table, so be cautious with the delete statement also. Without the WHERE clause, all table rows will be deleted. (Fehily, 2008)
  • 11. Task 1 The first task was to insert data into four rows of the Classes table. The following SQL code is what I used to accomplish the task, followed by the screenshot of the query being executed successfully. INSERT INTO [Cameron_CTU].[DBO].[Classes] ( [ClassCode], [ClassName], [Description] ) VALUES ( 'ACCT306', 'Accounting 1', 'This course introduces accounting concepts and explores the accounting environment. It covers the basic structure of accounting, how to maintain accounts, use account balances to prepare financial statements, and complete the accounting cycle. It also introduces the concept of internal control and how to account for assets.' ), ( 'CS362', 'Structured Query Language for Data Management', 'This course gives complete coverage of SQL, with an emphasis on storage, retrieval, and manipulation of data.' ), ( 'ENGL115', 'English Composition', 'In this course, students focus on developing writing skills through practice and revision. Students will examine expository, critical, and persuasive essay techniques.' ), ( 'FIN322', 'Investments', 'This course focuses on investments and investment strategies. Various investment vehicles such as stocks, bonds, and commodities are examined. Students will explore the principles of security analysis and valuation.' ) (Fehily, 2008) Task 2 The second task was to insert data into three rows of the Advisors table. The following SQL code is what I used to accomplish the task, followed by the screenshot of the query
  • 12. being executed successfully. INSERT INTO [dbo].[Advisors] ( [FirstName], [LastName], [EmailAddr] ) VALUES ( 'Fred', 'Stone', '[email protected]' ), ( 'Bob', 'Gordon', '[email protected]' ), ( 'Jack', 'Simpson', '[email protected]') (Fehily, 2008) Task 3 The third task was to insert data into four rows of the Students table. The following SQL code is what I used to accomplish the task, followed by the screenshot of the query being executed successfully. INSERT INTO [dbo].[Students] ( [FirstName], [LastName], [BirthDate], [Gender], [StartDate], [GPA], [IsActive], [Bio], [AdvisorID] ) VALUES ( 'Craig', 'Franklin', '1970-03-15', 'm', '2010-05-30', 3.10, 'Yes', '', 3 ), ( 'Harriet', 'Smith', '1982-04-15', 'f', '2010-05-30', 3.22, 'Yes', '', 1 ), ( 'George', 'David', '1984-11-05', 'm', '2010-10-01', 0.00, 'Yes', '', 3 ), ( 'Ben', 'Jefferson', '1976-09-25', 'm', '2009-02-21', 1.80, 'No', 'The student has gone on temporary leave to pursue other
  • 13. opportunities but plans on returning in 1 year.', 3 ) (Fehily, 2008)Task 4 The fourth task was to delete the course named Investments from the system, and the following SQL code is what I used to accomplish the task, followed by the screenshot of the query being executed successfully. DELETE FROM Classes WHERE ClassID = 'FIN322'; (Fehily, 2008) Task 5 The fifth and final task called for changing 2 columns in a row on the Students table, and the following SQL code is what I used to accomplish the task, followed by the screenshot of the query being executed successfully. UPDATE Students SET BirthDate = '1982-04-25', GPA = 3.25 WHERE StudentID = '2'; (Fehily, 2008) Phase 3 - DML (Select) and Procedures Phase 3 has seven tasks that call for retrieving data using the SELECT and FROM Statements. The SELECT clause calls for which column or columns to display, and the FROM clause identifies the table or tables the columns belong to. You can also use the AS clause in order to create column aliases, which I’ll go over in the last few tasks. You can also sort rows with the ORDER BY clause, which I’ll also hit on in the tasks. The WHERE clause filters unwanted rows. Without it, you results would be every row on your queried table. Some other statement clauses include AND, OR, ORDER BY GROUP BY,
  • 14. JOIN. There are two types of JOIN clauses. They are Implicit and explicit. Implicit is used a lot, and you may not even realize your using it because there is no actual JOIN clause with JOIN in it; its implied when you’re querying more than one table. Lets get started with the tasks now, shall we? (Fehily, 2008) The first thing I’m going to do is fix my SQL statement in the Phase 2 section, Task 5. I fixed it by using StudentID in the SELECT clause. Task 1 The first task calls for a list of all active male students assigned to Advisors 1 or 3. So, we want to query the Advisor. Advisor ID, FirstName and LastName columns along with theStudents.AdvisorID, FirstName, LastName, Birthdate, Gender, and GPA columns of the Students and Advisors tables. We use an implicit JOIN with the WHERE clause to JOIN the two tables of Student.AdvisorID and Advisor.AdvisorId together. Below, you’ll find the SQL Statement I used to retrieve the required data, and screenshot that shows a successful query. SELECT Gender, IsActive, AdvisorID FROM Cameron_CTU.dbo.Students WHERE Gender = 'm' AND IsActive = 'yes' AND AdvisorID IN (1,3) Task 2 The second task asks for a list of students without a biography. Here’s the SQL Statement I used, and screenshot that shows a successful query.
  • 15. Task 3 Task 3 is a very simple statement asking what classes are in the English Department. This SQL statement involves a wild card just after the L in the word “English”. The SQL statement and its associated screenshot are below. SELECT ClassCode, ClassName FROM Cameron_CTU.dbo.Classes WHERE ClassName LIKE 'ENGL%' Task 4 Task 4 calls for a list of all students and their advisors, and sorted by Advisors, and a few columns from the Students table SELECT A.AdvisorID, A.FirstName, A.LastName, S.AdvisorID, S.FirstName, S.LastName,BirthDate, Gender, GPA FROM Cameron_CTU.dbo.Students S, Cameron_CTU.dbo.Advisors A WHERE S.AdvisorID = A.AdvisorID ORDER BY A.LastName, S.LastName ASC; SELECT A.CustomerID, A.FirstName, A.LastName, S.AdvisorID, S.FirstName, S.LastName,BirthDate, Gender, GPA FROM Cameron_CTU.dbo.Students S, Cameron_CTU.dbo.Advisors A WHERE S.AdvisorID = A.AdvisorID ORDER BY A.LastName, S.LastName ASC; Task 5 The fifth task calls for the number of students born in the 80s.
  • 16. Below, you’ll find the SQL Statement I used to retrieve the required data, and screenshot that shows a successful query. SELECT COUNT (StudentID) as Students_born_in_the_80s FROM Cameron_CTU.dbo.Students WHERE BirthDate between '1980-01-1' AND '1989-12-31'; Task 6 Task 6 wanted to know the average GPA score sorted by men and women. Here is the SQL code and screenshot. Task 7 Task 7 is looking for all of the advisors with only 1 student. Here’s the SQL code and screenshot. SELECT A.firstname, A.LastName, COUNT (A.AdvisorID) AS Total_Active_Students FROM Cameron_CTU.dbo.Students S, Cameron_CTU.dbo.Advisors A WHERE A.AdvisorID = S.AdvisorID AND S.IsActive = 'yes' GROUP BY A.FirstName, A.LastName HAVING COUNT (S.StudentID) = '1'; Phase 4 – Architecture, Indexes Phase 4 calls for a way to track classes required for degrees, and which degree students are pursuing. We were given the task of creating a table for tracking degrees with Degree Name and Degree Description. However, the best way to track the classes required for degrees is to create a table labeled ‘Degrees’ with columns labeled ‘DegreeID’, ‘DegreeName’ and ‘DegreeDescription’, and ‘DegreeCode’. Also adding a column to the ‘Classes’ table, labeled DegreeID will help link the ‘Degrees’ and ‘Classes’ tables. After the tables have been created, I’ll need to test the architecture to ensure it can render the results I’m looking for in queries. (Fehily, 2008)
  • 17. However, I just received my grade for my Phase 1 IP with identified errors. See Phase 1 section for fixed errors. The errors that need corrected are: - Considerations regarding my data types and field lengths: FirstName and LastName too long - Fix constraints for assignments 1 through 4 to ensure only 0- 100 can be input. - Fix GPA Constraint to ensure input of only 0.00 – 4.00, and permit only 3 total digits after decimal. - Constrain ‘Gender’ to either M or F, and IsActive to either Yes or No. Step 1: CREATE TABLE [Degrees] I’ll start by creating the table, ‘Degrees’ with the following DDL script, followed by a screenshot of the query being completed successfully, and the table structure that displays the table columns to include the PRIMARY KEY, ‘DergeeID’. USE [Cameron_CTU] GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Degrees] ( [DegreeID] [int] IDENTITY(1,1) PRIMARY KEY NOT NULL, [DegreeName] [varchar](50) NOT NULL, [DegreeDescription] [varchar](1000) NOT NULL, [DegreeCode] [varchar](50) NOT NULL, )
  • 18. Step 2: Re-create ‘Classes’ TABLE to add ‘DegreeID’ column and INSERT 6 classes The next step is to delete and re-create the ‘Classes’ table, and ensure that the ‘DegreeID’ column is included in the creation, and made a FOREIGN KEY. Also, ensure you re- insert the original 3 classes, and add 3 new classes into the ‘Classes’ table required by different degrees. And since you’ve re-created the ‘Classes’ table with ‘DegreeID’ as a FOREIGN KEY, make sure you add it to the INSERT INTO DDL script or you’ll receive an error regarding the ‘DegreeID’ column. Below are the following DDL scripts, followed by a screenshot of the queries being completed successfully, and the table structure that displays the table columns with ‘DegreeID’ as a FOREIGN KEY, and the query results of the SELECT * FROM Classes query. USE [Cameron_CTU] GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[Classes]
  • 19. ( [ClassID] [int] IDENTITY(1,1) PRIMARY KEY NOT NULL, [DegreeID] [int] NOT NULL, [ClassCode] [varchar](50) NOT NULL, [ClassName] [varchar](100) NOT NULL, [Description] [varchar](1000) NOT NULL, ) ALTER TABLE [dbo].[Classes] ADD FOREIGN KEY([DegreeID]) REFERENCES [dbo].[Degrees]([DegreeID]) GO INSERT INTO [Cameron_CTU].[DBO].[Classes] ( [DegreeID], [ClassCode], [ClassName], [Description] ) VALUES ( '4', 'ACCT306', 'Accounting 1', 'This course introduces accounting concepts and explores the accounting environment. It covers the basic structure of accounting, how to maintain accounts, use account balances to prepare financial statements, and complete the accounting cycle. It also introduces the concept of internal control and how to account for assets.' ), ( '5', 'CS362', 'Structured Query Language for Data Management', 'This course gives complete coverage of SQL, with an emphasis on storage, retrieval, and manipulation of data.' ), ( '3', 'ENGL115', 'English Composition', 'In this course, students focus on developing writing skills through practice and revision. Students will examine expository,
  • 20. critical, and persuasive essay techniques.' ), ( '3', 'BHVS205', 'Managerial Psychology', 'This course introduces Psyhology concepts that will serve as the foundation to other concepts, such as Motivation and Emotion and Interpersonal Communications and Dynamics.' ), ( '4', 'CSS150', 'Introduction to Computer Security', 'This course covers Computer Security Principles, such as Policy letters, Remote Logins, and Network Security.' ), ( '5', 'CS126', 'UNIX Fundamentals', 'This course teaches you thed origins of the UNIX Operating System, and teaches you how to build directories.' ) Step 3: ALTER TABLE [Students] As the paragraph title implies, the next step is to add the ‘DegreeID’ column to the ‘Students’ table, and make it a FOREIGN KEY. Below is the following DDL script used to add the column, and make it a FOREIGN KEY, and the screenshot of the successful command. USE [Cameron_CTU] GO ALTER TABLE Students ADD DegreeID [int] NOT NULL GO ALTER TABLE Students ADD FOREIGN KEY (DegreeID) REFERENCES Degrees(DegreeID)
  • 21. Step 4: DML script to insert 3 test records in [Degrees] The next step is to insert degree data into the ‘Degrees’ table. Below is the DML script used, and a screenshot of the successful command along with an inset of the results for a SELECT * FROM Degrees statement. INSERT INTO [Cameron_CTU].[DBO].[Degrees] ( [DegreeCode], [DegreeName], [DegreeDescription] ) VALUES ( 'BSIP', 'Bachelor of Science in Psychology', 'The Bachelor’s degree in General Psychology is designed to prepare students to successfully navigate in the 21st century workplace, in a variety of careers that focus on the business of people, including but not limited to work in management, administration, research, and sales. It is positioned to provide an overview of the major psychological concepts, perspectives, and skills that explain human behavior. ' ), ( 'BSIS', 'Bachelor of Science in Information Security', 'The Bachelors of Science in Information Assurance and Security degree allows undergraduate learners to acquire and apply various processes, tools, technologies, and methods of securing an enterprise; including security policies, social engineering, access control, authentication, perimeter security, disaster recovery and business continuity, risk management, incident response, viruses, malware, spam, encryption, and other infrastructure security techniques that include governance and strategic alignment of IT and business. ' ), ( 'BSIT', 'Bachelor of Science in Information Technology', 'The Bachelor of Science in Information Technology (BSIT) curriculum includes both a common core, as well as specialization-specific courses. The BSIT core provides a strong foundation in the key information technology areas of programming, systems administration, security, architecture, databases, and ethics.' ) Step 5: DML script to INSERT INTO the ‘Students’ table
  • 22. ‘DegreeID’ data The next step is to add the ‘DegreeID’ to 4 records applicable to each of the 4 students. Below is the DML script used to execute the command and a screenshot showing it was successful. INSERT INTO [Cameron_CTU].[dbo].[Students] ( [FirstName], [LastName], [BirthDate], [Gender], [StartDate], [GPA], [IsActive], [Bio], [AdvisorID], [DegreeID] ) VALUES ( 'Craig', 'Franklin', '1970-03-15', 'm', '2010-05-30', 3.10, 'Yes', NULL, 3, 3 ), ( 'Harriet', 'Smith', '1982-04-15', 'f', '2010-05-30', 3.22, 'Yes', NULL, 1, 4 ), ( 'George', 'David', '1984-11-05', 'm', '2010-10-01', 0.00, 'Yes', NULL, 3, 5 ), ( 'Ben', 'Jefferson', '1976-09-25', 'm', '2009-02-21', 1.80, 'No', 'The student has gone on temporary leave to pursue other opportunities but plans on returning in 1 year.', 3, 3 ) The last step is to execute a SELECT statement with an implicit JOIN clause to show what degree each student is pursuing. USE Cameron_CTU
  • 23. SELECT FirstName, LastName, Students.DegreeID, Degrees.DegreeName FROM Cameron_CTU.dbo.Students, Cameron_CTU.dbo.Degrees WHERE Students.DegreeID = Degrees.DegreeID; Step 6: Display ERD Phase 5 – Views, Transactions, Testing and Performance References Fehily, C. (2008) Visual QuickStart Guide SQL, Third Edition, [CourseSmart e-Book reader version] Retrieved from http://wow.coursesmart.com/9781256745129/firstsection