structured query language

42
Table of Content Preface INDEX Introduction……………………………………………………………………..1 Background…………………………………………………............................1.1 AIM……………………………………………………………………………2.0 Functions and Facility………………………………………………………….3.0 Data manipulation language......................................................... ..................…...3.1 Data Definition Language…………………………………………………….…3.2 Data type and Constraint………………………………………………………..3.3 Clause………………………………………………………………………….…3.4 Changes made on the tools……………………………………………………….4.0 Changes made on the server………………………………………………………4.1 Activity Covered………………………………………………………………….5.0 ER Model for UCSI University…………………………………………………...5.1 ER diagram………………………………………………………………………...5.2 Create table statement……………………………………………………………..5.3

Upload: emmy-black

Post on 02-Dec-2014

167 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Structured Query Language

Table of Content

Preface INDEX

Introduction……………………………………………………………………..1

Background…………………………………………………............................1.1

AIM……………………………………………………………………………2.0

Functions and Facility………………………………………………………….3.0

Data manipulation language...........................................................................…...3.1

Data Definition Language…………………………………………………….…3.2

Data type and Constraint………………………………………………………..3.3

Clause………………………………………………………………………….…3.4

Changes made on the tools……………………………………………………….4.0

Changes made on the server………………………………………………………4.1

Activity Covered………………………………………………………………….5.0

ER Model for UCSI University…………………………………………………...5.1

ER diagram………………………………………………………………………...5.2

Create table statement……………………………………………………………..5.3

Insert Statement……………………………………………………………………5.4

Problem Solving……………………………………………………………………5.5

Discussion…………………………………………………………………………..6.0

Conclusion………………………………………………………………………….7.0

References………………………………………………………………………….8.0

Page 2: Structured Query Language

1. Introduction

1.1. Background

The growth of internet and the web over the last two decades and the rising demand to access

and manage information and data has deemed it necessary for a database management system

(DBMS). The relational database model was developed using SQL (Structure Query Language)

so that database management system could be arranged in tables called Relational database

management system (RDBMS) whereby these data(S) and information can be managed better,

and new information can be added, retrieved, updated without the need to reorganize the tables.

WHAT IS SQL?

SQL simply means Structured Query language, this structured query language is a computer

based language, which can be used for the storage of data, inserting data and deleting data in a

database.

The structured query language was written by Edgar f.Code also this computerized language is

the most widely used computerized language for relational database.

HISTORY OF SQL

The origin of SQL dates back to 1970’s by IBM, Dr. E. F. Codd published a book titled

“Relational model of Data for Large shared Data Banks “this eventually became the foundation

of the relational database System. This published book provided a new way to structure data

within the database and also led to the relational database System that we use today. [1]

The likes of DR.codd was not alone in the business, while he was busy defining the structure of

the database, how the database would look like, and how data’s are to be stored his colleagues

whose names are Donald D. Chamberlin and Raymond F. Boyce who worked at IBM had been

developing a query language known as SQUARE (SPECIFYING QUERIES AS RELATIONAL

EXPRESSIONS). [2] This language was used to set theory and duplicate mathematics to select

data from the database. This language had a terse mathematical syntax and became the proven

ground for concept which is important in database projects.

Page 3: Structured Query Language

By 1974, Chamberlin and Boyce published “SEQUEL: A Structured English Query Language”

which detailed their refinements to SQUARE and introduced us to the data retrieval aspects of

SEQUEL. This new SEQUEL language was as powerful as SQUARE, but Chamberlin and

Boyce “kept in mind the notions of top down structured programming, the need for linear

notation, and the need for readable programs that are easy to maintain and modify”. The

resulting syntax could be described as block-structured English keyword syntax. [3]

2.0 Aim.

─ SQL was developed, to help store data

─ To deal with the relational database environment and to help solve problems

─ To modify database

─ To help build a database system, that can be able to store data, allows users to insert

rows, delete rows and so on

─ Manipulate and retrieve data stored in a database

3.0 FUNCTIONS AND FACILITIES OF SQL

The SQL language has many functions such as rows, columns clauses and tables. Semicolons are

used to end a statement in SQL computer based language. Though the semi-colon is not required

in every platform it is important for the statement.

Also the Select word is been used in SQL before writing a statement, the select statement is used

to show or indicate what the user wants to do with the database. Also the most common type of

operation in SQL is known as the “Query” statement.

(I.e. Select*

From students ;)

This simple SQL statement written above would retrieve all data from the student’s table, it is

also going to indicate its data type and constraints also it would indicate the null values in the

table.

The two main type of language used in SQL, are Data manipulation language and Data definition

Language.

Page 4: Structured Query Language

3.1 Data Manipulation Language:

Data manipulation language is a core part of SQL.it is been used when a user wants’ to add or

delete data from the database. [4]

In these functions of SQL, we would be talking about how to add rows, delete rows and update

roes in a given database.

Insert Statement:

Insert statement are SQL statement which are used to insert new rows into a table in a database

environment. You can add rows, by using the insert syntax. [4]

Insert into table [(column [, column…….])]

Values (value [, values………]);

For example:

A user wants to insert a table, whose name is campus. Who has columns named, campus id and

campus name.

Insert into Campus

Values (UCSI, UCSI University);

Or the user can use this method.

Insert into campus (campus_id, campus_name)

Values (‘UCSI’, ‘UCSI University’);

This SQL insert statement above would insert a row whose id is UCSI into the table named

campus.

Page 5: Structured Query Language

Update Statetement

The update statement is a feature in SQL language which is used to update tables in a database.

Although it’s main objective is to modify existing rows in a table. [4]

Just as the insert statement and the update statement have different meaning, so also they have

different syntax, and they have different functions.

Example:

A database administrator wants to update a table in his database. All what he or she needs to do

it’s to specify the role he or she wishes to update. Let’s assume the name of the table is called

employees, and the administrator wants’ to update the salary of all employees whose first name

is john to 500.

Update employees

SET first_ name = ‘john’

Where Salary=500;

So this update statement would update the salary status of all employees whose first name is

john, and give them a salary rate of 500.

Delete Statement

Delete statement is a type of data manipulation language which is used in deleting rows from a

table, in a database. The delete statement is the most easiest to execute among the main three

data manipulation languages. [4]

DELETER FROM table

[Where Condition];

What the delete statement is implying is that, for a user to delete a row, he or she has to specify

the role he or she wants to delete, by specifying the where condition the database administrator

has to be specify one data in the row he wants to delete, so that it can be deleted easily, because

if the where clause is not indicated, the entire rows in that particular table would be deleted.

Page 6: Structured Query Language

Delete from campus

Where campus_id =’UCSI’;

3.2 Data Defining Language:

Data defining language are SQL languages which are used to create and manage tables in a

database. The main feature of the data definition language is called the create table statement.

Create Table Statement.

A database consists of different tables, which have data’s stored in them. The data’s can be

numerical or alphabetical, also the type of data that are stored in a table describes that particular

table. [5]

Example:

A table names driver, consist of columns that are related to the driver and rows that describes the

driver.

Create TABLE driver

(driver_name VARCHAR2 (20),

Address VARCHAR2 (30),

Telephone NUMBER (20))

The create table statement above shows a table titled “driver “this table has three columns. As

mentioned before the rows and columns in the table describes the particular table.

Nevertheless a database administrator with full understanding of SQL would be able to drop the

table and describe the table by writing simple SQL statement. The two SQL statements below are

used to drop table in a database and also describe table in a database.

Drop Table driver;

Describe driver;

Page 7: Structured Query Language

3.3 Data types and Constraints. Data type and constraint are one of the most talked about

computer based related issue. Each computer language tries to define data type in a way related

to their application or to their software. [5]

Types of data types in SQL and their description.

The diagram below was attained based on reference. [5]

Data types Description

VARCHAR2 It specifies the length of the data’s Variables to

be precise.

CHAR The length of the data type when using Char is

being fixed, by the database itself rather than

the designer.

NUMBER It specifies the length of the numbers in a

particular column

DATE It is used to set Date and time in a database.

LONG It is like VARCHAR2,but it has a length up to

2GB

CLOB Unlike LONG it’s size it’s up to 4GB

RAW and LONG RAW It deals with the binary information in the

database

BLOB It has a length that is up to 4GB

BFILE This indicates that a binary data, has been

saved in an external file, and also its size is up

to 4GB

ROWID This data type in SQL represent the

Uniqueness of a row in its table, also it consist

of a 64 numbering system

Constraints

Page 8: Structured Query Language

In SQL there are four main types of Constraints, and they are

1. PRIMARY KEY constraints

2. FOREIGN KEY Constraint

3. UNIQUE Constraint

4. CHECK Constraint

Constraint can be declared in both table levels and column level in database system, it all

depends on the administrator which one he or she wants to use in declaring the Constraint, but

the table level Constraint is the best method, because it gives the table a befitting Architecture

and also there are less problems, but column level constraint can be a little bit triggy because of

its ability to cause error.

PRIMARY KEY Constraint

A primary key constraint can be defined as a column or set of column that uniquely identifies

each row in a table. [6] If a column has been declared as a primary key is also means that the

column which is declared as the primary key can never contain a null value because of its

Uniqueness.

An SQL result table indicating a primary key and it’s null values.

Foreign Key

A foreign Key Constraint, simple means it is a primary key in its original table. For example

This Entity relational diagram above show a primary key constraint and how an attribute can be

considered a foreign key, there are two different tables here, where course id is a foreign key in n

the student table and a primary key in its own table (Course).

Unique and check Constraint.

Page 9: Structured Query Language

A Unique integrity constraint requires that every value in a column or a set of column be unique. [7] It been unique means there would be no repetition of words or number in that column.

Unique column

Lecturer_id Lecturer_name Department Subject_teaching Email

10007 Ms Kasthuri IT OOM1 [email protected]

10004 Mr. Yemen Engineering Calculus [email protected]

10009 Mr. Ibo Music keyboard Ogmail.com

Not allowed, number already exists.

10007 Mr. dean agriculture Agric science [email protected]

10005 Mr. shaman fishery farming Eu.yahoo.com

Allowed.

While check constraint are constraint that defines a condition each row must satisfy.

3.4 Clauses

In SQL clause are used to indicate what you want the tables to retrieve, the types of clauses that

are usually used in SQL are categorized into functional data and non functional data and they

are:

1. Where clause

2. from clause

3. Having clause

4. with clause

5. Group By clause

6. Order By clause

Where clause:

Page 10: Structured Query Language

The where clause is the type of clause is the type of clause which restrict the number of rows

returned by the queries, the where clause also makes sure the statement must be true before

returning the required output of that statement. When writing an SQL statement which contains a

where condition, the user of the system or the designer needs to be aware of the WHERE clause

syntax and how it is been applied. [8] Also when using the where clause we are to take note of

single operators and multiple operators.

Select column

From table

Where [(condition)]

Operators Description

= Equal

< Less than

> greater

.<> Not Equal to

IN Includes all values, just like Equal to operator

ALL Return all values.

For example:

Select driver_id, driver_name

From taxi

Where driver_id =10009;

FROM CLAUSE

The form clause is the type of clause in an SQL statement which indicates the table the user

wants to retrieve a data from.

For example:

Select*

Page 11: Structured Query Language

From driver;

This SQL command statement implies that all data in the driver’s table should be derived or

retrieved.

Group By clause and Having clause

These types of clause are used to group values in a particular column and also used to perform

calculation in a column. [9]

Example:

Select last_name, emp_id, AVG (salary)

From employees

Having AVG (Salary) = 500;

Group by emp_id

4.0 Changes made on the tool:

There is no way we are to talk about the changes made in SQL, without talking about the

standards of sql.sql is a computing language that is very unique language that is different from

many other languages, SQL can run on many platforms including oracle. Also the standards of

this query language shows how the different SQL was developed, the aims and how it was been

used, it also shows the weakness of the SQL server.

SQL Standards

SQL is a commonly recognized database language, the differences in major vendors

implementations were growing, and some kind of standard became necessary. However in the

year 1978, the Committee on Data Systems and Language (CODASYL) commissioned the

development of a data model as a prototype of a database design. This development was done by

the data defining language committee (DDLC) which later led to the development of the Data

defining language (DDC) and Data Manipulation Language (DML).This two SQL language

Page 12: Structured Query Language

became standard in the year 1986 and it was endorsed by an American association known as

American National Standards Institute National Committee on Information Technology

Standards H2 Technical Committee on Database (ANSI NCITS H2 TCD).

In the year 1982, NCITS where given mandates to standardize relational model, since it was

based on IBM SQL/DS specifications. The NCITS standardized the relational model and in the

year 1984 the standard was already a recognized one. It allows more diversity among database.

Finally in the year 1986 it was endoreced by the American National Standards Institute (ANSI)

after its final endorsement it was adopted by the international standard Organization (ISO) in the

year 1987.after the adaptation ISO developed the revised standard known as SQL89.which was

published in the year 1989.

SQL89 (SQL1)

SQL89 also known as SQL 1 was the first SQL product that was extablished, it was published in

the year 1989.but the end users could not ascertain upon implementations details. Because the

end users could not agree with the implementation details.

SQL92 (SQL2)

Since many features in SQL 1989 was not working properly, and the end users where

complaining,SQL89 was modified in the year 1992 for SQL92 which is also known as

SQL2.The American National Standard institution (ANSI) took SQL82 as a basis and correct

many features ,also it worked on the weakness of SQL89 to make SQL92 a better server.

Also (ANSI) filled many gaps in the old standard, and presented conceptual SQL features to

SQL92, which at that time exceeded the capabilities of any existing RDBMS implementation.

Also, the SQL92 standard is over five times longer than its predecessor about 600 pages more,

and has three levels of conformance.

However in SQL89, the Entry-level conformance was different to that of SQL92. (i.e. circular

views and correlated sub queries became prohibited in SQL91).

Despite the entry level conformance been different, the intermediate level conformance went

through loads of improvement, the SQL92 was able to verify length, characters, national

Page 13: Structured Query Language

character set, case and cast expression, joint operators and dynamic SQL.that wasn’t all the SQL

92 also creates loads of interactivity between the system and end users where by they can create

tables, alter tables, set transactions, use sub queries in updatable view, use set operators

(i.e. Union, Except, Intersect)to combine multiple queries result.

Finally the SQL92 also has full-level conformance, and this full-level conformance includes

deferrable constraints assertions, temporary local tables, privileges on character sets and

domains. The testing of SQL 92 was performed by the U.S. Government Department of

Commerce's National Institute of Standards and Technology (NIST).

SQL99 (SQL3)

SQL99 represents the next step in SQL standards development. The efforts to define this

standard began virtually at the same time when its predecessor — SQL92 (SQL2) — was

adopted. The new standard was developed under guidance of both ANSI and ISO committees.

and the change introduced into the database world by SQL3 was as dramatic a shift from

nonrelational to relational database model, its sheer complexity is reflected in the number of

pages describing the standard — over 1,500 — comparing to 120 or so pages for SQL89 and

about 600 pages for SQL92. Some of the defined standards (for example, stored procedures)

existed as vendor-specific extensions, some of them (like OOP) are completely new to SQL

proper. SQL3 was released as an ANSI/ISO draft standard in 1999; later the same year its status

was changed to a standard level.

It was lunch to enhance the current second generation SQL standard commonly called SQL-92,it

was called SQL-92 because of the year it was published,SQL3 Was planned to be lunched in the

year 1996…but things didn’t go as planned. also SQL3 has been characterized to be an Object

Oriented SQL.also the SQL3 is the foundation of many other object oriented relational database

management system (i.e. ORACLE8, Informix ‘Universal Server, IBM’s DB2 Universal

Database, and others).It took nearly seven (7) years to develop this structured language instead of

the three to four (3-4)years usually planned.SQL99 involves additional features that are not

present in SQL-92 as well as total restructuring of the standards. The two organizations that are

involved in the standardization of the structured query language are and took part in the develop

of SQL99, are ANSI and ISO.[10]

Page 14: Structured Query Language

4.1 changes made on the server

We can’t talk of the changes made in the SQL computing Language alone, without talking about

SQL server. Because without the availability of the server the SQL language would be unable to

run on any platform including Oracle.

SQL server version and the year it was developed:

Year Description

1987 It was release for UNIX platform

1988 Microsoft, Sybase and Aston –Tate release SQL server to OS/2

1989 Microsoft, Sybase and Aston –Tate release SQL

server 1.0 for OS/2

1990 Server 1.1 is released with support for

Windows 3.0 clients.

Aston-Tate drops out of SQL Server

development.

1991 Microsoft and IBM end joint development of

OS/2.

1992 Microsoft SQL Server 4.2 for 16-bit OS/2 1.3

is released.

Microsoft and Sybase port SQL Server to

Windows NT.

1993 Windows NT 3.1 is released.

Microsoft and Sybase release version 4.2 of

SQL Server for Windows NT.

1994 Microsoft and Sybase co-development of SQL

Server of. cially ends.

- Microsoft continues to develop the Windows

version of SQL Server.

- Sybase continues to develop the UNIX

version of SQL Server.

Page 15: Structured Query Language

1995 Microsoft releases version 6.0 of SQL Server.

1996 Microsoft releases version 6.5 of SQL Server.

1998 Microsoft releases version 7.0 of SQL Server.

2000 Microsoft releases SQL Server 2000.

2001 Microsoft releases XML for SQL Server Web

Release 1 (download).

2002 Microsoft releases SQLXML 2.0 (renamed

from XML for SQL Server).

Microsoft releases SQLXML 3.0.

2005 Microsoft releases SQL Server 2005 on

November 7th, 2005.

2008 Microsoft releases SQL Server 2008 on August

6th 2008.

2010 Microsoft releases SQL Server 2008 R2 on

April 21st 2010.

SQL Server 2005

The SQL Server 2005,was released on October 2005,it was codenamed(Yukon),it was released

based on the features lacking in SQL Server 2002.it’s main aim was to manage XML data in

addition to relational data. For this main reason the SQL Server 2005 was describes as an XML

data type, which can be used as data type for columns or for queries.[11]

Common language runtime(CLR)was the main feature in SQL server 2005,where by a user of

the system can write codes as managed code, this are the codes that are being executed as by the

common language runtime. Also the SQL Server 2005, added a feature that was not there in SQL

Server 2002.where by the embedded Queries are being allowed to run, with the help of a

Common Language runtime.

SQL server 2008

It was from SQL Server 2008, that the latest version of the SQL was attained.SQL Server 2008

was released by Microsoft on august 6th 2008, its main aim was to make data management self-

Page 16: Structured Query Language

tuning, self organizing, and self maintaining with the development of SQL Server Always

On technologies.

SQL Server 2008, have data types that are not present on the other versions of the server, some

of its data type are specialized date and time types and a spatial data type for location-dependent

data. [12]

Also the SQL Server 2008,the structured data and the metadata are stored in the SQL server

database, whereas the unstructured data components are stored in the file system, so that file can

be accessed using both Win32 and APIs

SQL Server 2010.

Oracle server R2, is the latest version of the SQL server, it was formally known with the

codename (SQL Server Kilimanjaro aka KJ), this SQL server was released to the public at April

21, 2010. [13]SQL Server R2 adds certain features that are not present in SQL Server

2008.including a Master Data Management regarded as Master Data services.

5.O Activity Covered

University database.

A university (UCSI University), wants you to create a database for them that would be able to

take care of their data storage, each campus has many departments, each departments has many

lectures, a lecturer can be able to take more than one subject, there can be more than one course

that has more than one similar subjects, one student can take many subjects.

5.1 ER model for UCSI University database

CAMPUS DEPARTMENTSHAS

Page 17: Structured Query Language

1 1.* 1

1

1.*

1.*

1.* 1.

1 1.*

1.* 1

5.2 Entity relational diagram.

HOD

COURSE

LECTURERS

prerequisite

SUBJECTS

STUDENTS

HAS

teach

take

has

HAS REPORTS

Page 18: Structured Query Language

5.3 Create table statement:

Page 19: Structured Query Language

CAMPUS.

CREATE TABLE "CAMPUS"

( "CAMPUS_ID" VARCHAR2(4000) NOT NULL ENABLE,

"CAMPUS_NAME" VARCHAR2(4000) NOT NULL ENABLE,

"LOCATION" VARCHAR2(4000),

CONSTRAINT "CAMPUS_PK" PRIMARY KEY ("CAMPUS_ID") ENABLE

)

/

Column Name Data Type Nullable Default Primary Key

CAMPUS_ID VARCHAR2(4000) No - 1

CAMPUS_NAME VARCHAR2(4000) No - -

LOCATION VARCHAR2(4000) Yes - -

1 - 3

DEPARTMENT_CAMPUS

CREATE TABLE "DEPARTMENTS_CAMPUS"

( "DEPARTMENT_ID" VARCHAR2(4000),

"DEPARTMENT_NAME" VARCHAR2(4000) NOT NULL ENABLE,

"HOD" VARCHAR2(4000) NOT NULL ENABLE,

"DEPARTMENT_BUDGERT" NUMBER(15,1),

"CAMPUS_ID" VARCHAR2(4000),

CONSTRAINT "DEPARTMENTS_CAMPUS_PK" PRIMARY KEY

("DEPARTMENT_ID") ENABLE,

CONSTRAINT "DEPARTMENTS_CAMPUS_FK" FOREIGN KEY

("CAMPUS_ID")

REFERENCES "CAMPUS" ("CAMPUS_ID") ENABLE

)

/

Column Name Data Type Nullable Default Primary Key

Page 20: Structured Query Language

DEPARTMENT_ID VARCHAR2(4000) No - 1

DEPARTMENT_NAME VARCHAR2(4000) No - -

HOD VARCHAR2(4000) No - -

DEPARTMENT_BUDGERT NUMBER(15,1) Yes - -

CAMPUS_ID VARCHAR2(4000) Yes - -

1 - 5

COURSE

CREATE TABLE "COURSE"

( "COURSE_ID" VARCHAR2(4000),

"COURSE_NAME" VARCHAR2(4000),

"COURSE_DURATION" TIMESTAMP (6),

"JOB_TYPES" VARCHAR2(4000),

"DEPARTMENT_ID" VARCHAR2(4000),

"CAMPUS_ID" VARCHAR2(4000),

CONSTRAINT "COURSE_PK" PRIMARY KEY ("COURSE_ID") ENABLE,

CONSTRAINT "COURSE_FK" FOREIGN KEY ("DEPARTMENT_ID")

REFERENCES "DEPARTMENTS_CAMPUS" ("DEPARTMENT_ID") ENABLE,

CONSTRAINT "COURSE_FK2" FOREIGN KEY ("CAMPUS_ID")

REFERENCES "CAMPUS" ("CAMPUS_ID") ENABLE

)

/

Page 21: Structured Query Language

Column Name Data Type Nullable Default Primary Key

COURSE_ID VARCHAR2(4000) No - 1

COURSE_NAME VARCHAR2(4000) Yes - -

COURSE_DURATION TIMESTAMP(6) Yes - -

JOB_TYPES VARCHAR2(4000) Yes - -

DEPARTMENT_ID VARCHAR2(4000) Yes - -

CAMPUS_ID VARCHAR2(4000) Yes - -

1 - 6

STUDENT

CREATE TABLE "STUDENT"

( "STUDENT_ID" NUMBER(15,1),

"STUDENT_NAME" VARCHAR2(4000),

"ADDREES" VARCHAR2(4000),

"TELEPHONE" NUMBER(15,1),

"GENDER" VARCHAR2(4000),

"DOB" DATE,

"GRADES" VARCHAR2(4000),

CONSTRAINT "STUDENT_PK" PRIMARY KEY ("STUDENT_ID") ENABLE

)

Column Name Data Type Nullable Default Primary Key

STUDENT_ID NUMBER(15,1) No - 1

STUDENT_NAME VARCHAR2(4000) Yes - -

ADDREES VARCHAR2(4000) Yes - -

TELEPHONE NUMBER(15,1) Yes - -

GENDER VARCHAR2(4000) Yes - -

DOB DATE Yes - -

GRADES VARCHAR2(4000) Yes - -

1 - 7

LECTURERS

Page 22: Structured Query Language

CREATE TABLE "lecturers"

( "lecturer_id" NUMBER(15,0) NOT NULL ENABLE,

"lecturer_name" VARCHAR2(4000) NOT NULL ENABLE,

"lecturer_type" VARCHAR2(4000),

"telephone" NUMBER(15,1),

"address" VARCHAR2(4000),

"subject qualified" VARCHAR2(4000),

"department_id" VARCHAR2(4000),

"campus_id" VARCHAR2(4000),

CONSTRAINT "lecturers_PK" PRIMARY KEY ("lecturer_id") ENABLE,

CONSTRAINT "LECTURERS_FK" FOREIGN KEY ("department_id")

REFERENCES "DEPARTMENTS_CAMPUS" ("DEPARTMENT_ID") ENABLE,

CONSTRAINT "LECTURERS_FK2" FOREIGN KEY ("campus_id")

REFERENCES "CAMPUS" ("CAMPUS_ID") ENABLE

)

/

Column Name Data Type Nullable Default Primary Key

lecturer_id NUMBER(15,0) No - 1

lecturer_name VARCHAR2(4000) No - -

lecturer_type VARCHAR2(4000) Yes - -

telephone NUMBER(15,1) Yes - -

address VARCHAR2(4000) Yes - -

subject qualified VARCHAR2(4000) Yes - -

department_id VARCHAR2(4000) Yes - -

campus_id VARCHAR2(4000) Yes - -

1 - 8

SUBJECTS

CREATE TABLE "SUBJECTS"

( "SUBJECT_NAME" VARCHAR2(4000) NOT NULL ENABLE,

"PREREQUISITE" VARCHAR2(4000),

"CLASS_ROOMS" VARCHAR2(4000) NOT NULL ENABLE,

"DEPARTMENT_ID" VARCHAR2(4000),

11143605700225

1275970813406

Page 23: Structured Query Language

"CAMPUS_ID" VARCHAR2(4000),

"STUDENT_ID" NUMBER(15,1),

"LECTURER_ID" NUMBER(15,1),

CONSTRAINT "SUBJECTS_PK" PRIMARY KEY ("SUBJECT_NAME")

ENABLE,

CONSTRAINT "SUBJECTS_FK" FOREIGN KEY ("DEPARTMENT_ID")

REFERENCES "DEPARTMENTS_CAMPUS" ("DEPARTMENT_ID") ENABLE,

CONSTRAINT "SUBJECTS_FK2" FOREIGN KEY ("CAMPUS_ID")

REFERENCES "CAMPUS" ("CAMPUS_ID") ENABLE,

CONSTRAINT "SUBJECTS_FK3" FOREIGN KEY ("STUDENT_ID")

REFERENCES "STUDENT" ("STUDENT_ID") ENABLE,

CONSTRAINT "SUBJECTS_FK4" FOREIGN KEY ("LECTURER_ID")

REFERENCES "lecturers" ("lecturer_id") ENABLE

)

/

Column Name Data Type Nullable Default Primary Key

SUBJECT_NAME VARCHAR2(4000) No - 1

PREREQUISITE VARCHAR2(4000) Yes - -

CLASS_ROOMS VARCHAR2(4000) No - -

DEPARTMENT_ID VARCHAR2(4000) Yes - -

CAMPUS_ID VARCHAR2(4000) Yes - -

STUDENT_ID NUMBER(15,1) Yes - -

LECTURER_ID NUMBER(15,1) Yes - -

1 - 7

COURSE_SUBJECT

Column Name Data Type Nullable Default Primary Key

COURSE_ID VARCHAR2(4000) Yes - -

SUBJECT_NAME VARCHAR2(4000) Yes - -

LECTURER_ID NUMBER(15,1) Yes - -

DEPARTMENT_ID VARCHAR2(4000) Yes - -

CAMPUS_ID VARCHAR2(4000) Yes - -

11141129549203

16475

11143605700225

1275971153316

11141129549203

16475

11143605700225

1275971153316

Page 24: Structured Query Language

1 - 5

CREATE TABLE "COURSE_SUBJECT"

( "COURSE_ID" VARCHAR2(4000),

"SUBJECT_NAME" VARCHAR2(4000),

"LECTURER_ID" NUMBER(15,1),

"DEPARTMENT_ID" VARCHAR2(4000),

"CAMPUS_ID" VARCHAR2(4000),

CONSTRAINT "COURSE_SUBJECT_FK" FOREIGN KEY ("COURSE_ID")

REFERENCES "COURSE" ("COURSE_ID") ENABLE,

CONSTRAINT "COURSE_SUBJECT_FK2" FOREIGN KEY ("SUBJECT_NAME")

REFERENCES "SUBJECTS" ("SUBJECT_NAME") ENABLE,

CONSTRAINT "COURSE_SUBJECT_FK3" FOREIGN KEY ("LECTURER_ID")

REFERENCES "lecturers" ("lecturer_id") ENABLE,

CONSTRAINT "COURSE_SUBJECT_FK4" FOREIGN KEY

("DEPARTMENT_ID")

REFERENCES "DEPARTMENTS_CAMPUS" ("DEPARTMENT_ID") ENABLE,

CONSTRAINT "COURSE_SUBJECT_FK5" FOREIGN KEY ("CAMPUS_ID")

REFERENCES "CAMPUS" ("CAMPUS_ID") ENABLE

)

/

5.4 Insert Statement

Campus:

1. insert into campus

values('North wing','UCSI UNIVERSITY','CHERAS');

2. insert into campus

values('SOUTH WING','UCSI UNIVERSITY','TAMAN CONNAUGHT CHERAS');

CAMPUS_ID CAMPUS_NAME LOCATION

North wing UCSI UNIVERSITY CHERAS

Page 25: Structured Query Language

SOUTH WING UCSI UNIVERSITY TAMAN CONNAUGHT CHERAS

2 rows returned in 0.06 seconds         CSV Export

Departments_campus

1. Insert into Departments_campus

Values ('IT','Information Technology','Ms chloe',7000,'SOUTH WING');

DEPARTMENT_ID DEPARTMENT_NAME HOD DEPARTMENT_BUDGERT CAMPUS_ID

IT Information Technology Ms chloe 7000 SOUTH WING

Course

1.insert into course(course_id,course_name,department_id,campus_id)

values('hybs','Business information system','IT','SOUTH WING');

COURSE_ID

COURSE_NAME

COURSE_DURATION

JOB_TYPES

DEPARTMENT_ID

CAMPUS_ID

4hycc computing - - - -

hybsBusiness information system

- - IT SOUTH WING

STUDENT

INSERT INTO STUDENT

VALUES(1000715597,'EMMANUEL UGOCHUKWU NWABRIJE','NO 20 AKAD

AVENUE',555-768-99,'MALE','8 JUNE,1985','A');

STUDENT_ID STUDENT_NAME ADDREES TELEPHONE GENDER DOB GRADES

1000715597EMMANUEL UGOCHUKWU NWABRIJE

NO 20 AKAD AVENUE

-312 MALE08-JUN-85

A

LECTURERS

1.insert into lecturer

11141129549203

16477

11143605700225

1275971532764

Page 26: Structured Query Language

Values(7798,'Mr oscar','full time',555-897-435,'angkasa condo','java 1','IT','SOUTH WING');

lecturer_id lecturer_name lecturer_type telephone address subject qualified department_id campus_id

7798 Mr oscar full time -777angkasa condo

java 1 ITSOUTH WING

SUBJECT

1. INSERT INTO SUBJECT(SUBJECT_NAME,CLASS_ROOMS,LECTURER_ID)

VALUES( ‘JAVA 1’,’CG05’,7798);

SUBJECT_NAME PREREQUISITE CLASS_ROOMS DEPARTMENT_ID CAMPUS_ID STUDENT_ID LECTURER_ID

java 1 - CG05 - - - 7798

SUBJECT_ COURSE

1. insert into course_subject(COURSE_ID,SUBJECT_NAME)

VALUES('hycc','java 1');

COURSE_ID SUBJECT_NAME LECTURER_ID DEPARTMENT_ID CAMPUS_ID

hycc java 1 - - -

5.5 PROBLEM SOLVING.

1. Write a query to display the list of student takes java 1.

Select student_id, subject_name,class_rooms

from subjects

Where subject_name IN (select subject_name

From subjects

where subject_name = 'java 1');

STUDENT_ID SUBJECT_NAME CLASS_ROOMS

- java 1 CG05

2. retrieve all data in the lecturer’s table?

Page 27: Structured Query Language

select*

from lecturer;

lecturer_id lecturer_name lecturer_type telephone address subject qualified department_id campus_id

7798 Mr oscar full time -777angkasa condo

java 1 ITSOUTH WING

3 .display the Date of birth, gender and grades of the student whose id is 1000715597.

select student_id,dob,gender,grades

from student

where student_id= 1000715597;

STUDENT_ID DOB GENDER GRADES

1000715597 08-JUN-85 MALE A

4.using the union operator to retrieve data from the department_campus table?

select department_id,department_name,department_budgert,campus_id

from departments_campus

union

select department_id,department_name,department_budgert,campus_id

from departments_campus

DEPARTMENT_ID DEPARTMENT_NAME DEPARTMENT_BUDGERT CAMPUS_ID

IT Information Technology 7000 SOUTH WING

6.0 Discussion:

Page 28: Structured Query Language

Since SQL is a computer based language, the functions and facility of this language helped us in

this project. Also we were able to understand that despite SQL being a computer based Language

it could run on many platforms including oracle.

In this application, we were asked to create a database for UCSI University, A system that would

be able to allow storage of data, insertion of data, and respect the SQL standards. Based on the

description of the required database, a plan had to be made, a designing pattern has to be made,

the analysis of the system needs to be put into consideration, how the system is going to work

needed to be put into consideration, so by putting all the points into consideration, the ER model

was drawn to help facilitate the proposed system, after the ER model had been drawn, it gave us

a very befitting understanding on how the system is going to be. on how the attributes are to be

named, and which table would be related to another.

After getting this fact down, we drew the ER diagram. The ER diagram makes the creation of the

database much easier, because by drawing the ER diagram, we already know the primary key,

and the foreign key.

Actually a software known as DeZign for database was the software which we used in drawing

the ER diagram, the software helps us indicating foreign keys and primary keys. Also we created

the tables in the database using Oracle database 10g express edition, this software supports SQL

commands, so we used the SQL commands prompt in creating tables, describing tables and

inserting rows.

Eventually, after creating, describing and inserting rows into the database, we tried out the

application by writing out and running some queries.

.

Page 29: Structured Query Language

Conclusion:

in conclusion the ER model serve as reference model to the ER diagram and the ER diagram

serve as reference model to the create table statements. Also the ER model indicates the channel

of transaction and how it occurs.

Finally the subjects table in the ER model has one prerequisite, to the head of department

(HOD).

Page 30: Structured Query Language

References:

[1]LiquidNet.ltd (http://www.ntchosting.com/databases/structured-query-language.html)”History of

SQL”accessed 5/24/2010

[2]. D D Chamberlin, R. F. Boyce, 1974(http://www.almaden.ibm.com/cs/people/chamberlin/sequel-1974.pdf.)” SEQUEL: A Structured English Query Language” may 16, 2007

[3] chris Collins,( http://ccollins.wordpress.com/2007/05/20/history-of-sql/)” History of SQL”,May 20,2007

[4]. Chaitanya Koratamaddi and Nancy Greenberg “Oracle Database 10g: SQL Fundamentals 1,”

student guide Vol .1, Data manipulation Language, pp. 8-5 – 8-20, December 2006

[5]. Chaitanya Koratamaddi and Nancy Greenberg “Oracle Database 10g: SQL Fundamentals 1,”

student guide Vol .1, Data definition Language, pp. 9-8 – 9-18, December 2006

[6]. Chaitanya Koratamaddi and Nancy Greenberg “Oracle Database 10g: SQL Fundamentals 1,”

student guide Vol .1, Data manipulation Language, pp. 9-24, December 2006

[7]. Chaitanya Koratamaddi and Nancy Greenberg “Oracle Database 10g: SQL Fundamentals 1,”

student guide Vol .1, Data manipulation Language, pp. 9-22, December 2006

[8]. David haertzen, (http://infogoal.com/sql/sql-where.htm)”SQL WHERE CLAUSE”, JUNE 8,

2010

[9]. Ian Gilfillan,( http://www.databasejournal.com/features/mysql/article.php/3469351/The-

HAVING-and-GROUP-BY-SQL-clauses.htm) “THE HAVING AND GROUP BY CLAUSES”

February 8,2005

Page 31: Structured Query Language

10]Adam Einsbrg,Jim Melton (http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.114.1085)”

Backgroud SQL,”1999

[11]. Maud q.vincent (http://e-articles.info/e/a/title/A-Brief-History-of-Microsoft-SQL-Server/) “a brief

history of Microsoft SQL.”March 3, 2007

[12].J.NicholasHoover,(http://www.informationweek.com/news/windows/microsoft_news/

showArticle.jhtml?articleID=199500164)” Microsoft Gives Peek At Next Version of SQL

Server”, May 9 2007

[13]. Buck woody, (http://blogs.technet.com/b/sqlserverexperts/archive/2010/04/21/sql-server-

2008-r2-launches.aspx)”SQL SERVER 2008 R2 LUNCHES”, April 21, 2010