DEV Community

Cover image for Introduction to Structured Query Language
Kiregi Paul
Kiregi Paul

Posted on

Introduction to Structured Query Language

Structured Query Language
Introduction to SQL
Structured query language is a standard language used to access and manipulate databases.

Tasks that you can do with SQL
1. Execute queries in a database
2. Create new tables in a database
3. Delete records from a database
4. Create new databases
5. Insert record in a database
6. Update records in a database
7. Retrieve data from a database

SQL commands
SQL uses commands to ensure the implementation of tasks or queries, some of the important commands include;
1. SELECT- The select statement is used to extract data from a database
2. UPDATE- Updates data in the selected database
3. DELETE- deletes data from a database
4. INSERT INTO- Inserts new data into the database
5. CREATE DATABASE- creates a new database
6. ALTER DATABASE- Modifies the data in a database
7. CREATE TABLE- creates a new table
8. ALTER TABLE- modifies a table
9. DROP TABLE- deletes a table
10. CREATE INDEX- creates a search key
11. DROP INDEX- deletes an INDEX

NOTE: SQL keywords are not case sensitive that is select and SELECT will all work the same, therefore you can use either uppercase or lowercase and still have the same output and with no error.
: A semicolon is used as the standard ay to separate each SQL statement allowing more than one statement to be executed by the same call to the server.

The use of SELECT in SQL statement

The select statement is used to select data from a database. This can be illustrated in the examples below.
SELECT *
FROM CUSTOMERS;

The * is used to symbolize all therefore the statement reads select all from the customers’ table. To select a range within the table we use the syntax below;
SELECT column_1, Column_5
FROM CUSTOMERS;

This is by assuming that your table has columns named column_1 and column_5 and you want to display the data in those columns.
The output from this statement will be data from the two columns from the customers' table that will be displayed.
Therefore, to have the output of a particular column from the table you only include the column name in the select statement, and to display all the data in the table you use the asterisk (*) in the select statement

CATEGORIES OF SQL COMMANDS
DDL- Data Definition Language
DQL- Data Query Language
DML- Data Manipulation Language
DCL- Data Control Language
TCL- Transaction Control Language
DQL- Data Query Language

Data Definition Language
The data definition language deals with database schemas and descriptions, of how the data should reside in the database
CREATE- it is used to create databases and their objects like (tables, indexes, triggers, functions, and procedures)
ALTER- alters the structure of the existing database
DROP- deletes object from the database
TRUNCATE- remove all records from a table, including spaces allocated to the record are removed
RENAME- Renames an object

Data Manipulation Language
The data manipulation language is used to store, modify retrieve, delete and update data in a database.
SELECT- retrieve data from the database
INSERT- insert data into a table
UPDATE- updates existing data in a table
DELETE- deletes all records from a database table
MERGE- UPSERT operation (insert or update)

Data Control Language
The data control language acts as an access specifier to the database. That is, it grants or revokes permission to users in the database.
GRANT- grants permission
REVOKE- revokes permission

Transaction Control Language
Acts as a manager for all types of transactional data and all transactions
ROLLBACK- cancel or undo changes made in the database
COMMIT- apply or save changes in the database
SAVEPOINT- temporarily saves data in the database

Data Query Language
This is the subset of Data Manipulation Language, the most common query in Data Query Language is the SELECT statement which helps us in retrieving the data from the table without changing anything or modifying the table.
Data Query Language is important for the retrieval of essential data

Top comments (0)