1 Introduction
1 Introduction
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 −
a) CREATE
b) ALTER
c) DROP
d) TRUNCATE
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.
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.
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.
DCL commands are used to grant and take back authority from any database user.
a) GRANT
b) REVOKE
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.
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.
VARCHAR2(si It is used to store variable string data within the predefined length. It can be stored
ze) up to 4000 byte.
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.
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.
Insert
SQL INSERT statement is a SQL query. It is used to insert a single or a multiple records in a table.
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 (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.