0% found this document useful (0 votes)
12 views9 pages

IS5413 Tutorial 08-Jiang Yuge-57972280

Uploaded by

chloeygjiang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views9 pages

IS5413 Tutorial 08-Jiang Yuge-57972280

Uploaded by

chloeygjiang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Jiang Yuge - 57972280

IS5413 Data Management


Tutorial 8 – Introducing SQL

Throughout this course, we’ll use SQL Server 2014 to do the database application implementation.

The labs have the SQL Server client available.

You may download and install the SQL Server 2014 at home to practice more:
http://www.microsoft.com/sql/default.mspx

OR SQL Server 2005 Management Studio Express (43 Mb)


https://www.microsoft.com/en-hk/download/details.aspx?id=42299

You should have received an email containing your SQL Server 2014 login name and password. Please
use them to login to the server for your upcoming tutorials and group project.
Start SQL Server by clicking Start  Programs  Microsoft SQL Server 2014 
SQL Server Management Studio

In the prompt, enter the following details to login to the SQL Server 2014 hosted in TST:

Server name: 144.214.55.146


Authentication: SQL Server Authentication

Login: (in your email)


Password: (in your email)

After successful login, you should see the following screen.

You can expand the databases folder (named by your login ID) to locate your database and review the
details of the database objects in your database, e.g. tables, views, constraints, etc.
Let’s start writing our 1st query. Click on the New Query button on the top left corner.

After you clicked on the New Query button, you should see the query editor is opened. On the top left
corner, a pull down menu will show you the current database you are working on now. All the queries
you write will take effect on this database.
Now, please work on the following exercises.
For SQL reference, you may refer to: http://msdn2.microsoft.com/en-us/library/ms189826.aspx

Exercise 1: Creating Table


We create tables using CREATE statement. The following statement will create tables as stated with all
the requirements and constraints.

create table Course (


CID varchar (6) not null primary key,
Name varchar (100) not null,
Credit int not null
);

create table Student (


SID varchar (8) not null,
Name varchar (50) not null,
Phone int,
Constraint Student_PK primary key (SID)
);

create table Enrollment (


EID varchar (6) not null primary key,
SID varchar (8) not null foreign key references Student (SID),
CID varchar (6) not null foreign key references Course (CID),
Date datetime not null,
Status varchar (1) not null
CHECK (Status IN ('S', 'N', 'P' ))
);

Table name: Course


Column Name Data Type Null is allowed or not? Remarks
CID Varchar, width = 6 Not allowed Unique identifier of a
course.
Primary key of the
Course table
Name Varchar, width = 100 Not allowed Name of the course
Credit Integer Not allowed Credit of the course

Table name: Student


Column Name Data Type Null is allowed or not? Remarks
SID Varchar, width = 8 Not allowed Unique identifier of a
student.
Primary key of the
Student table
Name Varchar, width = 50 Not allowed Name of the student
Phone Integer Allowed Contact phone of the
student

Table name: Enrollment


Column Name Data Type Null is allowed or not? Remarks
EID Varchar, width = 6 Not allowed Unique identifier of an
enrollment.
Primary key of the
Enrollment table.
SID Varchar, width = 8 Not allowed Foreign key referring to
the SID of the Student
table.
CID Varchar, width = 6 Not allowed Foreign key referring to
the CID of the Course
table.
Date Datetime Not allowed Enrollment date.
Status Varchar, width = 1 Not allowed Enrollment status.
S = successful
N = unsuccessful
P = pending approval

After executing the SQL statements, you may need to refresh the Tables folder in order to see the newly
created tables. Your newly created tables should look like the following:
Exercise 2: Basic SELECT, INSERT, UPDATE and DELETE statements
Insert the following data into the corresponding table.

Insert into Course table:


IS3331, Data Management, 3

Insert into Student table:


50123456, Ling Ge, 27888514
50123457, Your tutor’s name, 21942329 (what is your tutor’s name?)
50123458, Your name, 27889972 (what is your name?)

Insert to Enrollment table:


1, 50123456, IS3331, 2007-10-20, P
2, 50123457, IS3331, 2007-10-20, P
3, 50123458, IS3331, 2007-10-20, P
insert into Course values ('IS3331', 'Data Management', 3);

insert into Student values ('50123456', 'Ling Ge', 27888514);

insert into Student values ('50123457', 'Jian Ma', 21942329);

insert into Student values ('50123458', 'Yuge Jiang', 27889972);

insert into Enrollment values ('1', '50123456', 'IS3331', '2007-10-20', 'P');

insert into Enrollment values ('2', '50123457', 'IS3331', '2007-10-20', 'P');

insert into Enrollment values ('3', '50123458', 'IS3331', '2007-10-20', 'P');

There are other ways to create tables.


1. In Summary window, locate Tables folder, right click on the blank area, as shown below. To find
Summary window if it doesn’t appear by default, click on ViewObject Explorer Details.

2. A new tab of table design interface as below will show up. You may specify attribute name, data
type and other characteristics here. Try create a table and delete it using an SQL query.
Exercise 2: DELETE and UPDATE
Insert a new course to the Course table: IS5740, Decision Support Systems, 3 credit points.
Delete course IS5740.
Update the status of the enrollments for course IS3232 from P to S.
insert into Course values ('IS5740', 'Decision Support Systems', 3);

delete from Course

where CID = 'IS5740';

Exercise 3: Basic SELECT


Use queries to answer the following questions.
A. Which courses offer 3 credit points? List the course name and credit.
B. How many students enrolled in course IS3331?
C. List the enrollments after the date of 10/20/2006.
Answer:
A. IS3331, Data Management, 3
B.
3 students.
50123456, Ling Ge, 27888514
50123457, Jian Ma, 21942329 (what is your tutor’s name?)
50123458, Yuge Jiang, 27889972
C.
1, 50123456, IS3331, 2007-10-20, P
2, 50123457, IS3331, 2007-10-20, P
3, 50123458, IS3331, 2007-10-20, P

If there’s still time left, the students may work on their own project databases.

Reference:
Modern Database Management, 10th Edition, Chapter 6
http://msdn2.microsoft.com/en-us/library/ms189826.aspx

- End of Tutorial 8 -

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy