Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Brunel - Computer Science - CS1703 Data and Information Lecture Notes (Exam Revision)

Rating
-
Sold
2
Pages
33
Uploaded on
06-01-2024
Written in
2018/2019

These are the lecture notes I created which I used to revise for the CS1703 Data and Information for Term 2 only for the exam at Brunel University in which I received a First Class in.

Institution
Course

Content preview

Module: CS1703
Lecture Topic: SQL (Part 1)
Week: 17
Structured Query Language (SQL)
-Main language for relational DBMs

Main characteristics:
-Relatively easy to learn
-Declarative, you specify what info you require rather than how to get it
(vs imperative/procedural languages like Java/Python.)
-Essentially free-format
-Consists of standard English words like SELECT, INSERT, and UPDATE
-Can be used by range of users.


Objectives of SQL:
Ideally database languages should let the user:
-create database and table structures
-perform basic tasks like adding (insert), amending (update), and removal (delete)


Must perform these tasks with minimal user effort
Must be portable-must conform to recognised standard (i.e. International standards-ISO)
SQL has two main components:
-DDL (Data definition Language): for defining DB structure and controlling access to data
-DML (Data Manipulation Language): for retrieving and updating data




Writing SQL Commands:
-SQL statement consists of reserved words and user-defined words
-Reserved words are a fixed part of SQL and must be spelled exactly as required and cannot
be split across lines (e.g SELECT, INSERT)
-User-defined words are made up by user and represent names of various database objects
such as tables, columns, views.

,Literals:
-Literals are constants used in SQL statements
-All non-numeric literals must be enclosed in single quotes (eg. ‘New York’)
-Numeric literals are not enclosed in quotes (eg. 650.00)
Example:

INSERT INTO BOOK (bTitle, bPRice)
VALUES(‘Hocus Pocus’, 5.99);


Example of a DB:
Underlines column names are primary keys, convention for representing a relational DB is
to give each table name followed by their column names in brackets

Table (Relation) Columns (Fields, Attributes)

DistributionCenter (dCenterNo, dStreet, dCity,
dState, dZipCode, mgrStaffNo)

Staff (staffNo, name, position, salary,
eMail, dCenterNo)

DVD (catalogNo, title, genre, rating)

Actor (actorNo, actorName)

DVDActor (actorNo, catalogNo, character)

:




SELECT: specifies which columns are to appear in output
FROM: specifies table(s) to be used
WHERE: filters rows subject to some conditions
GROUP BY: forms groups of rows with same column value
HAVING: filters groups subject to some condition.
ORDER BY: specifies the order of the output.

-Order of the clauses cannot be changed.
-Only SELECT & FROM are mandatory.

,“List the full details of all DVDS helds”


SELECT catalogNo, title, genre, rating
FROM DVD;


Or
SELECT *
FROM DVD;


Sometimes rows will have a null value.
“List rentals that have no return date specified”


SELECT staffNo, name, position, salary
FROM Staff
WHERE supervisorStaffNo is NULL;


Distinct keyword
-SELECT does not eliminate duplicate values by default
-Replace SELECT with SELECT DISTINCT
Calculated fields
-allows you to transform existing fields according to some arithmetic operation


SELECT staffNo, name, position, salary /12
FROM Staff;
Calculated fields: AS clause
-to give the column a meaningful name, we use the AS clause
SELECT staffNo, name, position, salary /12 AS monthlySalary
FROM Staff;

, Where clause
-Follows the FROM clause
-Only retrieve rows that satisfy some condition
-Five basic search conditions include:
 Comparison (compares the value of one expression to the value of another)
 range (test whether value falls within a specified range)
 set membership (test whether the value of an expression equals one of a set of
values)
 pattern match: test whether a string matches a specified pattern
 Null: test whether a column has a unknown value




Common operators


= equals
<> is not equal to
> is greater than
< is less than
<= is less than or equal to
>= is greater than or equal to
Logical operators and brackets can be used to express more complex conditions
AND – both conditions must be satisfied
OR – one or both conditions must be satisfied
NOT – condition is false
Comparison search
“List all staff with a salary greater than $40,000”
SELECT staffNo, name, position, salary
FROM Staff
WHERE salary>40000




Range search condition

Written for

Institution
Study
Unknown
Course

Document information

Uploaded on
January 6, 2024
Number of pages
33
Written in
2018/2019
Type
Class notes
Professor(s)
Dr alan serrano
Contains
Term 2

Subjects

Free
Get access to the full document:
Download

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
cslbrunel Brunel University
Follow You need to be logged in order to follow users or courses
Sold
64
Member since
4 year
Number of followers
34
Documents
29
Last sold
3 months ago
Brunel Computer Science (1st Class Honours)

I achieved a First Class Honours degree in Computer Science from Brunel University - I will be uploading some of my work. Please do not purchase any documents looking for the solution to your assignments or deliverables. No refunds / exchanges.

5.0

2 reviews

5
2
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions