Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

STRUCTURED QUERY LANGUAGE

GROUP SIX

DATABASE AND WAREHOUSING

27.02.21

Group Members

Tinashe Marume C21143650X


Leopatra Mutazu C21143682K
Paison Tazvivinga C21143659V
Michelle Mugweni C21143482K
Clayton Gwava C21143603L
Simukai A. Mutanga C21143571O
WHAT IS SQL?
• It is a standard computer language for relational
database management and data manipulation;
• Most relational databases support SQL hence it is the
standard language for relational database management
systems; hence
• It is mainly used to communicate with a database.
Source: Slideshare.net
USES OF SQL

• Query
• Insert
• Update on a database
• Modify data
• Allows us to interface with databases
ADVANTAGES AND DISADVANTAGES OF SQL

• ADVANTAGES • DISADVANTAGES
• High Speed - its easy to retrieve records from a • Its platform dependent
database.
• Occupies some space i.e extra memory location for
• No coding needed - doesn’t require substantial each record.
amount of code to manage database.
• It is command a command based language
• Adheres to long established and defined Standards
(ISO, ANSI)
• Portable – can be used in laptops, PCs server and
even mobile phones
• ACID- Atomicity, Consistency, Isolation, Durability
COMMON RELATIONAL DATABASE MANAGEMENT
SYSTEMS THAT USE SQL
• Oracle
• Sybase
• Microsoft SQL Server
• Access
• Ingres
COMMON COMMANDS IN
SQL
• CREATE DATABASE: to create a database
• CREATE TABLE: to create tables
• SELECT: to find/extract some data from a database
• UPDATE: to make adjustments and edit data
• DELETE: to delete some data.
SQL
SUBLANGUAGES
SQL consists of five principal sublanguages as presented below:
• Data Definition Language
• Data Query Language
• Data Manipulation Language
• Data Control Language
• Transaction Control Language
SQL Sublanguages
SQL SUBLANGUAGES
DDL (DATA DEFINITION LANGUAGE)
• It is used to define data structures stored in the database. DDL statements allow to
create, modify or destroy individual database objects
• Examples of DDL commands:
• CREATE– is used to create the database or its objects (like table, index, function,
views, store procedure and triggers).
Syntax:
CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES[,....]);
Example:
CREATE TABLE EMPLOYEE(Name VARCHAR2(20), Email VARCHAR2(100), DOB DATE);
SQL SUBLANGUAGES
DDL (DATA DEFINITION LANGUAGE)
• Examples of DDL commands (cont):
• DROP – is used to delete objects from the database.
Syntax
DROP TABLE ;
Example
DROP TABLE EMPLOYEE;
SQL SUBLANGUAGES
DDL (DATA DEFINITION LANGUAGE)
• Examples of DDL commands (continued):
• ALTER - is used to alter the structure of the database. Below we will look at altering a table

To add a new column in the table


Syntax
ALTER TABLE table_name ADD column_name COLUMN-definition;
To modify existing column in the table:
Syntax
ALTER TABLE MODIFY(COLUMN DEFINITION....);
EXAMPLES
ALTER TABLE STUDENTBIO ADD(ADDRESS VARCHAR(20));
ALTER TABLE STUDENTBIO MODIFY (NAME VARCHAR(20));
SQL SUBLANGUAGES
DDL (DATA DEFINITION LANGUAGE)
• Examples of DDL commands:
• TRUNCATE - is used to remove all records from a table, including all spaces
allocated for the records are removed.
Syntax:

TRUNCATE TABLE table_name;


Example:
TRUNCATE TABLE STUDENTBIO;

• COMMENT – is used to add comments to the data dictionary.


• RENAME - is used to rename an object existing in the database.
SQL SUBLANGUAGES
DQL (DATA QUERY LANGUAGE)
• DML statements are used for performing queries on the data within schema objects. The
purpose of DQL Command is to get some schema relation based on the query passed to it.

• Example of DQL:
• SELECT – is used to retrieve data from a database.

• Syntax: SELECT expressions

FROM TABLES

WHERE conditions;

EXAMPLE

SELECT FIRSTNAME

FROM STUDENTBIO

WHERE age > 20;


SQL SUBLANGUAGES
DML (DATA MANIPULATION LANGUAGE)
• It is used to query and change data stored in the database. DML statements
allow to select, insert, update and delete data in the tables.
• Examples of DML:
• INSERT – is used to insert data into a table.
• UPDATE – is used to update existing data within a table.
• DELETE – is used to delete records from a database table.
SQL SUBLANGUAGES
DCL (DATA CONTROL LANGUAGE)
• Is used to control access to data stored in the database.
• DCL statements operate with privileges and allow to grant and revoke privileges on
applying certain DDL and DML commands to certain database objects.
• DCL includes commands such as GRANT and REVOKE which mainly deals with the
rights, permissions and other controls of the database system.
• Examples of DCL commands:
• GRANT-gives user’s access privileges to database.
• REVOKE-withdraw user’s access privileges given by using the GRANT command.
SQL SUBLANGUAGES
TCL (TRANSACTION CONTROL LANGUAGE)
• Is used to control processing of transactions in the database.
• Usual TCL statements are, commit to apply the changes introduced by the transaction, rollback to undo them
and save point to divide the transaction into several smaller parts.
• TCL commands deals with transactions within a database.
• Examples of TCL commands:
• COMMIT– commits a Transaction.
• ROLLBACK rollbacks a transaction in case of any error occurs.
• SAVEPOINT–sets a save point within a transaction.
• SET TRANSACTION–specify characteristics for the transaction.
Anomalies are problems that can occur in poorly planned, un-normalized databases
where all the data is stored in one table.
The three type of anomalies that can arise in the database because of redundancy
are 1. Insertion, Deletion and Update anomalies.

ID Forename Surname Department Department ID Phone number

1 Tinashe Marume ICT 001 300


2 Paison Tazvivinga ICT 001 300
3 Leopatra Mutazu ICT 001 300
4 Simukai Mutanga English 002 301
5 Mercy Wanana English 002 301
6 Ross Moyo PE 003 302
7 Clyaton Gwava PE 003 302

8 Michelle Mugweni Geography 004 303


Insert anomaly
In the above example, it is not possible to add a new department to the database without also having to add a
member of staff at the same time. The table expects a teacher’s details and the details of a department to be
stored together as one record.
At the moment, there is no way to add the Maths department without also having to add a Maths teacher. This
problem is known as an insert anomaly.
Delete anomaly
A delete anomaly is opposite of an insert anomaly. When a delete anomaly occurs it means that you cannot delete
data from the table without having to delete the entire record.
For example, if we want to remove Michelle Mugweni from the table, we would also need to remove all data that is
stored about the Geography department. This means we would lose data that we might not want to lose.
Update anomaly
Take a look at the table shown above again. If the phone number for the English department changed to 307
instead of 301 it would need to be changed in two different records.
If the change only happened in one of the two records, then an update anomaly would have taken place.
In small tables it can be easy to spot update anomalies and make sure that changes are made everywhere.
However, large flat file tables would often contain thousands of records, meaning that it is difficult to make changes
to every record. Update anomalies lead to inaccuracy and inconsistency in a database.
REFERENCES

• https://www.w3schools.com/sql/sql_create_table.asp
• https://www.w3schools.com/sql/sql_create_table.asp
• https://www.khanacademy.org/computing/computer-programming/sql

You might also like