0% found this document useful (0 votes)
3 views5 pages

1 Introduction

SQL, or Structured Query Language, is a computer language used for managing and retrieving data in relational databases. It includes various commands categorized into Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), Transaction Control Language (TCL), and Data Query Language (DQL). SQL allows users to create, modify, and control access to databases and their data efficiently.

Uploaded by

Rajendra Babu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

1 Introduction

SQL, or Structured Query Language, is a computer language used for managing and retrieving data in relational databases. It includes various commands categorized into Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), Transaction Control Language (TCL), and Data Query Language (DQL). SQL allows users to create, modify, and control access to databases and their data efficiently.

Uploaded by

Rajendra Babu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

SQL

SQL is a database computer language designed for the retrieval and management of data in relational databases like MySQL, MS
Access, SQL Server, MS Access, Oracle, Sybase, Informix, PostgreSQL etc. SQL stands for Structured Query Language.

What is SQL?
SQL is a language to operate databases; it includes Database Creation, Database Deletion, Fetching Data Rows, Modifying & Deleting
Data rows, etc.

SQL stands for Structured Query Language which is a computer language for storing, manipulating and retrieving data stored in a
relational database. SQL was developed in the 1970s by IBM Computer Scientists

Why SQL?
SQL is widely popular because it offers the following advantages −

 Allows users to access data in the relational database management systems.


 Allows users to describe the data.
 Allows users to define the data in a database and manipulate that data.
 Allows embedding within other languages using SQL modules, libraries & pre-compilers.
 Allows users to create and drop databases and tables.
 Allows users to create view, stored procedure, functions in a database.
 Allows users to set permissions on tables, procedures and views.

SQL Basic Commands

1. Data Definition Language (DDL)


o DDL changes the structure of the table like creating a table, deleting a table, altering a table, etc.
o All the command of DDL are auto-committed that means it permanently save all the changes in the database.

Here are some commands that come under DDL:

a) CREATE
b) ALTER
c) DROP
d) TRUNCATE

a. CREATE It is used to create a new table in the database.

b. DROP: It is used to delete both the structure and record stored in the table.

c. ALTER: It is used to alter the structure of the database. This change could be either to modify the
characteristics of an existing attribute or probably to add a new attribute.

d. TRUNCATE: It is used to delete all the rows from the table and free the space containing the table.

2. Data Manipulation Language

 DML commands are used to modify the database. It is responsible for all form of changes in the database.
 The command of DML is not auto-committed that means it can't permanently save all the changes in the
database. They can be rollback.

Here are some commands that come under DML:

a) INSERT
b) UPDATE
c) DELETE

a. INSERT: The INSERT statement is a SQL query. It is used to insert data into the row of a table.

b. UPDATE: This command is used to update or modify the value of a column in the table.

c. DELETE: It is used to remove one or more row from a table.

3. Data Control Language

DCL commands are used to grant and take back authority from any database user.

Here are some commands that come under DCL:

a) GRANT
b) REVOKE

a. Grant: It is used to give user access privileges to a database.

b. Revoke: It is used to take back permissions from the user.

4. Transaction Control Language


TCL commands controls the transaction that are previously done by user.

Here are some commands that come under TCL:

a) COMMIT
b) ROLLBACK
c) SAVEPOINT

a. Commit: Commit command is used to save all the transactions to the database.

b. Rollback: Rollback command is used to undo transactions that have not already been saved to the database.

c. Savepoint: It is used to roll the transaction back to a certain point.

5. Data Query Language

DQL is used to fetch the data from the database.

It uses only one command:

a) SELECT

a. Select: This is the same as the projection operation of relational algebra. It is used to select the attribute based
on the condition described by WHERE clause.

Data Types
Data types are used to represent the nature of the data that can be stored in the database table. For example, in a
particular column of a table, if we want to store a string type of data then we will have to declare a string data type
of this column.

Data types mainly classified into three categories for every database.

 String Data types


 Numeric Data types
 Date and time Data types

a) String data types:

VARCHAR2(si It is used to store variable string data within the predefined length. It can be stored
ze) up to 4000 byte.

VARCHAR(SIZ It is the same as VARCHAR2(size). You can also use VARCHAR(size).


E)

b) Numeric Data Types:

NUMBER It allows whole numbers.

FLOAT(p) It is a subtype of the NUMBER data type. It allow decimal value numbers.
c) Date and Time Data Types:

DATE It is used to store a valid date-time format with a fixed length. Its range varies from
January 1, 4712 BC to December 31, 9999 AD.

TIMESTA It is used to store the valid date in YYYY-MM-DD with time hh:mm:ss format.
MP

Create Table
SQL CREATE TABLE statement is used to create table in a database.

If you want to create a table, you should name the table and define its column and each column's data type.

Let's see the simple syntax to create the table.

1. create table "tablename"("column1" "data type","column2" "data type",”column3" "data type",......."columnN


" "data type");

Example:
1. CREATE TABLE Employee(EmployeeID int,FirstName varchar(25),LastName varchar(50),Email varchar(50);

Drop Table
A SQL DROP TABLE statement is used to delete a table definition and all data from a table.

This is very important to know that once a table is deleted all the information available in the table is lost forever,
so we have to be very careful when using this command.

Let's see the syntax to drop the table from the database.

DROP TABLE "table_name";

Insert
SQL INSERT statement is a SQL query. It is used to insert a single or a multiple records in a table.

There are two ways to insert data in a table:

1. Without specifying column names


2. By specifying column names

In the first method there is no need to specify the column name where the data will be inserted, you
need only their values.

1. INSERT INTO table_name VALUES (value1, value2, value3....);


The second method specifies both the column name and values which you want to insert.

1. INSERT INTO table_name (column1, column2, column3....) VALUES (value1, value2, value3.....);

Truncate Table
In Oracle, TRUNCATE TABLE statement is used to remove all records from a table.

Let's see the syntax to truncate the table from the database.

1. TRUNCATE TABLE table_name;

You might also like