Basics of SQL

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

SQL was earlier known as SEQUEL. SQL stands for structured query language.

It is the language
used to access the data and structures within a relational database. It is non-procedural. It provides
commands for the following tasks:
 Querying data
 Inserting, updating and deleting data
 Creating, modifying and deleting database objects
 Controlling access to the database and database objects.
 Guarantees database consistency.
 Monitoring database performance and configuration.

Types of SQL Statements: Standard SQL Statements are divided into following five distinct  groups:

Group Statements Description

Data Definition Language CREATE Allows to create data structures i.e. tables, delete,
(DDL) ALTER alter etc.,
DROP
TRUNCATE

Data Manipulation Language INSERT Allows modification of data in the database


(DML) UPDATE
DELETE

Data Query Language (DQL) SELECT Helps in Retrieving data and information from the
SHOW database.
HELP

Data Control Language (DCL) GRANT Allows or denies permissions to access the tables.
REVOKE

Transaction Control Language COMMIT Manages the changes made by the DML
(TCL) ROLLBACK statements.
SAVEPOINT

Connecting to database from Command Prompt:

Creating a database: To create a database in MySQL, you use the CREATE DATABASE  statement
as follows:
CREATE DATABASE [IF NOT EXISTS] database_name;
Displaying Databases: The SHOW DATABASES statement lists all databases in the MySQL database
server. You can use the SHOW DATABASES statement to check the database that you’ve created or to
see all the databases on the database server before you create a new database, for example:

SHOW DATABASES;

Selecting a MySQL Database: To select a particular database to work with you issue the USE
statement as follows:

USE database_name;

Removing Databases: Removing database means deleting all the tables contained in the database and
the database itself permanently. Therefore, it is very important to execute this query with extra
cautions. To delete a database, you use the DROP DATABASE statement as follows:

DROP DATABASE [IF EXISTS] database_name;

You might also like