Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

SQL

SQL, or Structured Query Language, is utilized for querying and manipulating relational databases. It is classified into four categories: DDL (Data Definition Language), DML (Data Manipulation Language), TCL (Transaction Control Language), and DCL (Data Control Language), each serving distinct purposes in database management. Key commands include CREATE, INSERT, UPDATE, DELETE, and TRUNCATE, which facilitate the creation, modification, and management of database objects and data.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

SQL

SQL, or Structured Query Language, is utilized for querying and manipulating relational databases. It is classified into four categories: DDL (Data Definition Language), DML (Data Manipulation Language), TCL (Transaction Control Language), and DCL (Data Control Language), each serving distinct purposes in database management. Key commands include CREATE, INSERT, UPDATE, DELETE, and TRUNCATE, which facilitate the creation, modification, and management of database objects and data.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

SQL stands for Structured Query Language.

SQL is used to such as query and manipulate the


underlying relational databases SQL Server, Oracle, MySQL, PostgreSQL, SQLite, etc.

SQL Classification

Commands Description
DDL Data Definition Language
DML Data Manipulation Language
TCL Transaction Control Language
DCL Data Control Language

DDL – Data Definition Language

Data Definition Language (DDL) statements are used to define the structure of the data in the
database such as tables, procedures, functions, views, etc.

Statement Description
CREATE Create a new object(table, procedure, function, view etc.) in the database
ALTER Modify the structure of database table
DROP Delete database Objects
RENAME Rename database Objects (table, view, sequence, private synonym)
TRUNCATE Remove all records of a table

DML – Data Manipulation Language

Data Manipulation Language (DML) statements are used to manage data within a database object. It
allows manipulation and querying the existing database schema objects.

Statement Description
SELECT Retrieve rows/columns from a table.
INSERT Insert new data to a table.
UPDATE Update existing records of table.
DELETE Delete existing records from table.
MERGE INSERT new rows or UPDATE existing rows in a table based on the specified
conditions.
LOCK Lock one or more tables in the specified mode. Based on lock applied table access
TABLE denied or only real only access given to another user.

TCL– Transaction Control Language

Transaction Control Language (TCL) statements are used to finalize the changes in the data made by
executing the DML statements.
Statement Description
COMMIT Permanently save transaction changes to the database.

ROLLBACK Restore the database to its original state since the last COMMIT.

SAVEPOINT Create a SAVEPOINT to be later used by ROLLBACK Command to undo changes up to that
point.
SET Set the transaction properties such as READ WRITE or READ ONLY access.
TRANSACTION
CREATE DATABASE Statement

The CREATE DATABASE statement is used to create a new SQL database.

CREATE DATABASE databasename;


Create database test;

SHOW DATABASES;
DROP DATABASE Statement

The DROP DATABASE statement is used to drop an existing SQL database.

DROP DATABASE databasename;


DROP DATABASE test;

To Create a table
CREATE TABLE table_name(

column_name1 data_type [NULL|NOT NULL],

column_name2 data_type [NULL|NOT NULL],

...

);

create table employee_details (

empNum varchar(10),

lastName varchar(50),

firstName varchar(50),

email varchar(255) ,

dob date,

deptNum integer,
salary integer);

SQL - INSERT Data into a Table

INSERT INTO table_name(column_name1,


column_name2...column_nameN)

VALUES(column1_value, column2_value...columnN_value);

insert into employee_details values (1001, 'Luther', 'Martin', 'ml@gmail.com','1982-05-30',1,30000);

insert into employee_details values (1002, 'Murray', 'Keith', 'km@gmail.com', '2001-8-18',2, 25000);

insert into employee_details values (1003, 'Branson', 'John', 'jb@gmail.com', '1989-9-13',3, 15000);

insert into employee_details values (1004, 'Martin', 'Richard', 'rm@gmail.com', '1985-6-25',4,


16000);

insert into employee_details values (1005, 'Hickman', 'David', 'dh@gmail.com', '1977-07-13',5,


17000);

SQL - UPDATE Statement

UPDATE table_name

SET column_name1 = new_value,

column_name2 = new_value,

...

[WHERE Condition];

UPDATE employee_details
SET email = 'jking@test.com'
WHERE empNum = 1001;
Update Multiple Columns

UPDATE employee_details SET email = 'jking@test.com',


deptNum = 5 WHERE empNum = 1001;

SELECT Statement

The SELECT statement is used to select data from a database.

SELECT column1, column2, ...


FROM table_name;
select * from employee_details;

DELETE Statement

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.

DELETE FROM table_name [WHERE Condition];

DELETE FROM employee_details WHERE empNum = 1001;


DELETE FROM employee_details WHERE Salary > 20000;
TRUNCATE Table Statement
The TRUNCATE statement is used to delete all rows from
a table in the database.
TRUNCATE TABLE table_name;

TRUNCATE TABLE employee_details;

Tutorial:

https://www.w3schools.com/mysql/default.asp

https://www.youtube.com/watch?v=duEkh8ZsFGs

https://www.youtube.com/watch?v=cWNBchp_WCM&t=3596s

You might also like