Unit 03_Basics of SQL_MDT_PDB
Unit 03_Basics of SQL_MDT_PDB
MANAGEMENT SYSTEM
L.J Institutes of Engineering and Technology
Semester: II Subject: Database Management System
Unit-3 Basics of SQL
Content:
1. Introduction to SQL
1.1. Basics of SQL
1.2. SQL Rules
1.3. SQL Process
1.4. SQL characteristic
1.5. SQL Advantages
1.6. SQL Datatype
1.7. SQL Command
2. Data Definition Language (DDL)
2.1 Create Command
2.2 Alter Command
2.3 Truncate Command
2.4 Drop Command
3. Data Manipulation Language (DML)
3.1 Insert Command
3.2 Update Command
3.3 Delete Command
4. Data Control Language (DCL)
4.1 Grant Command
4.2 Revoke Command
Prepared By: Mr. Milan Trivedi & Mr. Divyang Patel Page| 1
L.J Institutes of Engineering and Technology
Semester: II Subject: Database Management System
Unit-3 Basics of SQL
1. Introduction of SQL
1.1 Basics of SQL:
• SQL stands for Structured Query Language. It is used for storing and
managing data in relational database management system (RDMS).
• It is a standard language for Relational Database System. It enables a user to
create, read, update and delete relational databases and tables.
• All the RDBMS like MySQL, Informix, Oracle, MS Access and SQL Server
use SQL as their standard database language.
• SQL allows users to query the database in a number of ways, using English-like
statements.
Prepared By: Mr. Milan Trivedi & Mr. Divyang Patel Page| 2
L.J Institutes of Engineering and Technology
Semester: II Subject: Database Management System
Unit-3 Basics of SQL
Prepared By: Mr. Milan Trivedi & Mr. Divyang Patel Page| 3
L.J Institutes of Engineering and Technology
Semester: II Subject: Database Management System
Unit-3 Basics of SQL
1. Number:
Define by numeric
2. Varchar:
Define by varchar(size)
3. Char:
Define by char(size)
4. Integer
Define by integer
5. Date:
Size not given because it is fixed.
YYYY-MM-DD
6. Time:
HH:MM:SS
7. Timestamp
YYYY-MM-DD HH:MM:SS
Prepared By: Mr. Milan Trivedi & Mr. Divyang Patel Page| 4
L.J Institutes of Engineering and Technology
Semester: II Subject: Database Management System
Unit-3 Basics of SQL
✓ There are five types of SQL commands: DDL, DML, DCL, TCL, and DQL.
SQL
command
Prepared By: Mr. Milan Trivedi & Mr. Divyang Patel Page| 5
L.J Institutes of Engineering and Technology
Semester: II Subject: Database Management System
Unit-3 Basics of SQL
2.1 Create:
✓ This command will create database or table.
1. To create database:
Syntax: CREATE DATABASE DATABASE_NAME;
e.g. CREATE DATABASE COMPANY;
➢ where company is the name of database.
Prepared By: Mr. Milan Trivedi & Mr. Divyang Patel Page| 6
L.J Institutes of Engineering and Technology
Semester: II Subject: Database Management System
Unit-3 Basics of SQL
Prepared By: Mr. Milan Trivedi & Mr. Divyang Patel Page| 7
L.J Institutes of Engineering and Technology
Semester: II Subject: Database Management System
Unit-3 Basics of SQL
2.2 Alter:
e.g., In above table of employee if we want to modify data type of salary then,
Prepared By: Mr. Milan Trivedi & Mr. Divyang Patel Page| 8
L.J Institutes of Engineering and Technology
Semester: II Subject: Database Management System
Unit-3 Basics of SQL
4. Use the DROP keyword to delete one or more columns from a table:
e.g., If we want to rename in Employee table ,column name Salary to Perk then,
Prepared By: Mr. Milan Trivedi & Mr. Divyang Patel Page| 9
L.J Institutes of Engineering and Technology
Semester: II Subject: Database Management System
Unit-3 Basics of SQL
2.3 Truncate:
✓ The TRUNCATE statement is used to delete all rows from a table in the
database.
SYNTAX: TRUNCATE TABLE TABLE_NAME;
e.g., If we want to remove all data from the Emp table then,
TRUNCATE TABLE Emp;
2.4 Drop:
✓ Use the DROP TABLE statement to delete a table with data from the database.
Prepared By: Mr. Milan Trivedi & Mr. Divyang Patel Page| 10
L.J Institutes of Engineering and Technology
Semester: II Subject: Database Management System
Unit-3 Basics of SQL
✓ 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.
3.1 Insert:
✓ The INSERT statement is used to insert single or multiple records into a table.
SYNTAX:
INSERT INTO table_name (column_name1, column_name2, ..., column_nameN)
VALUES (column1_value, column2_value, ..., columnN_value);
e.g.,
1. If data entry into specific column, then:
INSERT INTO Emp (empid, firstname, phoneno) VALUES (1, 'John ', 33000);
Prepared By: Mr. Milan Trivedi & Mr. Divyang Patel Page| 11
L.J Institutes of Engineering and Technology
Semester: II Subject: Database Management System
Unit-3 Basics of SQL
Prepared By: Mr. Milan Trivedi & Mr. Divyang Patel Page| 12
L.J Institutes of Engineering and Technology
Semester: II Subject: Database Management System
Unit-3 Basics of SQL
3.2 Update:
✓ The UPDATE command is used to update records of the table in the database.
SYNTAX:
UPDATE table_name SET column_name1 = new_value, column_name2 =
new_value WHERE Condition;
e.g.,
1. If we want to change email of mark, then:
UPDATE Emp SET email = 'jking@test.com' WHERE EmpId = 2;
Select * from emp; // for print emp table
Prepared By: Mr. Milan Trivedi & Mr. Divyang Patel Page| 13
L.J Institutes of Engineering and Technology
Semester: II Subject: Database Management System
Unit-3 Basics of SQL
3.3 Delete:
✓ Use the DELETE statement to delete records from the existing table in the current
schema or tables of the schema on which you have the DELETE privilege.
SYNTAX:
DELETE FROM table_name WHERE Condition;
e.g.,
1. If we want to delete empid number 4, then:
DELETE FROM Emp WHERE EmpId = 4;
Select * from emp; // for print emp table
Prepared By: Mr. Milan Trivedi & Mr. Divyang Patel Page| 14
L.J Institutes of Engineering and Technology
Semester: II Subject: Database Management System
Unit-3 Basics of SQL
4.1 Grant:
✓ You can grant users various privileges to tables. These permissions can be any
combination of SELECT, INSERT, UPDATE, DELETE
4.2 Revoke:
✓ With this command, it can revoke or take grant from users for various privileges to
tables.
Syntax:
Prepared By: Mr. Milan Trivedi & Mr. Divyang Patel Page| 15
L.J Institutes of Engineering and Technology
Semester: II Subject: Database Management System
Unit-3 Basics of SQL
Prepared By: Mr. Milan Trivedi & Mr. Divyang Patel Page| 16