Structured Query
Language – SQL
Theodore Chirindo
Tinotenda Maposa
Courtney Dzere
Michell Gurenje
Introduction to SQL
SQL is a standard programming language used for managing relational
databases.
It allows users to access and manipulate data stored in a database
management system.
SQL is widely used in various applications that require interaction with
databases, such as websites, business intelligence tools, and data analysis
platforms.
Naming Conventions
Naming conventions are guidelines for naming database objects such as
tables, columns, indexes, and constraints.
Following consistent naming conventions helps improve the readability and
maintainability of SQL code.
Some common naming conventions include using descriptive names, avoiding
reserved keywords, using underscores or camel case for multi-word
identifiers, and being consistent throughout the database schema.
Structure of SQL Statement
An SQL statement consists of several components:
i)Keywords
-SQL statements begin with keywords that indicate the type of operation, such as SELECT, INSERT,
UPDATE, DELETE, CREATE, ALTER, or DROP
ii)Clauses
- Clauses are used to define the specific details of the operation. These include SELECT, FROM, WHERE,
GROUP BY, HAVING, ORDER BY, SET, VALUES, and JOIN. Each clause serves a different purpose and
helps define the scope and conditions of the operation.
Continuation…
iii) Expressions
- Expressions are used to perform calculations or manipulate data within an SQL statement. They can involve
arithmetic operations, functions, or comparisons.
iv) Identifiers
-Identifiers are names given to database objects such as tables and columns. They need to follow naming
conventions and be enclosed in backticks (`) or double quotes (" ") if they contain special characters or spaces
v)Comments start with -- for single-line comments or /* */ for multi-line comments. They are used to document
the code for better understanding.
Data Definition Language (DDL)
Data Definition Language (DDL) is a subset of SQL statements used to define
and manage the structure of the database.
DDL commands include:
i)CREATE: used to create database objects like tables, views, indexes.
ii)ALTER: modifies the structure of existing database objects.
iii)DROP: deletes existing database objects.
iv)TRUNCATE: removes all records from a table but keeps its structure.
v)RENAME: renames a table or other database object.
Data Manipulation Language (DML)
DML statements are used to manipulate data stored in the database tables without
changing the structure of the tables themselves.DML commands include:
1. SELECT: retrieves data from one or more tables based on specified criteria.
2. INSERT: adds new records into a table.
3. UPDATE: modifies existing records in a table.
4. DELETE: removes records from a table based on specified conditions.