100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Lecture 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
Module











Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Study
Unknown
Module

Document information

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

Subjects

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

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
63
Member since
3 year
Number of followers
34
Documents
29
Last sold
4 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

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

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

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight 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 smashed it. It really can be that simple.”

Alisha Student

Frequently asked questions