0% found this document useful (0 votes)
4 views

SQL For Beginners Complete Guide: Gagandeep Singh

SQL for beginners

Uploaded by

Ady db
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

SQL For Beginners Complete Guide: Gagandeep Singh

SQL for beginners

Uploaded by

Ady db
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

SQL for Beginners

Complete Guide
Gagandeep Singh
https:www.linkedin.com/in/singhdeepgagan
What is SQL?

SQL stands for STRCUTURED QUERY LANGUAGE it is a


programming Language used to interact with the Databases.
It was earlier Known as SEQUEL which stands for
( STRCUTURED ENGLISH QUERY LANGUAGE ) it was
developed by IBM Scientist in 1970s. It is used to insert,
Update, Delete Data from a Relational Database.
Gagandeep Singh
SQL COMMANDS
SQL commands are the sets of
instructions used to interact with the
Database.

There are 5 types of SQL Commands :

(i) DATA DEFINITION LANGUAGE

(ii) DATA MANIPULATION LANGUAGE

(iii) DATA CONTROL LANGUAGE

(iv) DATA Query Language

(V) TRANSACTION CONTROL LANGUAGE

Gagandeep Singh
DATA DEFINITION LANGUAGE
1 DDL stands for Data Defintion Language. This Language is
used to Define the Structure of a Database Schema.
The Statements Present in DDL are :
(i) CREATE : This statement is used to create a new
Database, Tables or view.

-- Syntax for Creating the Database --


2 CREATE DATABASE database_name;
-- Example –
3 CREATE DATABASE testdb;

Gagandeep Singh
DDL - Create
-- Syntax for Creating the Table –
CREATE TABLE table_name (
Column_1 Datatype,
Column_2 Datatype,
Column_3 Datatype,
Column_n Datatype
);

-- Example –
CREATE TABLE customers (
cust_id INT,
cust_name VARCHAR(30),
cust_age INT,
);
Gagandeep Singh
(ii) ALTER : This statement is used to add, drop and modify columns in
an existing SQL Database.

-- Syntax for Adding column in the Table --


ALTER TABLE table_name
ADD column_name Datatype;

-- Example –
ALTER TABLE customers ADD Gender VARCHAR(10);

-- Syntax for Dropping column in the Table --


ALTER TABLE table_name
Drop column column_name;

-- Example –
ALTER TABLE customers
DROP column Gender;
Gagandeep Singh
-- Syntax For Modifying Column –
ALTER TABLE table_name
MODIFY column column_name Datatype;

--Example –
ALTER TABLE customers
MODIFY column Gender Char(01);

(iii) DROP : The DROP statement is used to Drop / Delete an existing SQL
Database or Tables. The whole table or Database will be Deleted.

-- Syntax For Deleting The Database –


DROP DATABASE database_name;
-- Example –
DROP DATABASE testdb;

Gagandeep Singh
-- Syntax For Deleting The Table –
DROP TABLE table_name;
-- Example –
DROP TABLE customers;

(iv) TRUNCATE : The Truncate command is used to Delete Rows /


Records from table but the table structure will remain as it is the
table will not be deleted you can insert records again.

-- Syntax For Truncating the Table –


TRUNCATE TABLE table_name;

-- Example –
TRUNCATE TABLE customers;

Gagandeep Singh
DATA MANIPULATION LANGUAGE
1 DML stands for Data Manipulate Language. This
Language is used to make changes in a Database such as
insert Data , update or Delete Data in Database.

The Statements Present in DML are :


(i) INSERT : This statement is used to insert or Add
records in a table.
-- Syntax for Inserting Data in the Database --
2 INSERT INTO table_name
(column_1, column_2, column _n)
3 VALUES
(value_1, value_2, value_n);
Gagandeep Singh
-- Example –
INSERT INTO customers
(cust_id, cust_name, cust_age)
VALUES
(101, ‘Gagan’, 20),
(102, ‘Aman’, 24),
(103, ‘Rabi’, 23)
);

(ii) UPDATE : The UPDATE statement is used to modify existing records


in the table.

-- Syntax for updating the Table –


UPDATE table_name
SET column_1= value_1, column_2 = value_2
WHERE condition;
Gagandeep Singh
-- Example –
UPDATE customers
SET cust_name = ‘Virat’
WHERE cust_id = 103;

(ii) DELETE : The DELETE statement is used to delete rows or records


from a table it can also be used to delete all records.

-- Syntax for Deleting the Data –


DELETE FROM table_name WHERE condition;

-- Example –
DELETE FROM customers WHERE cust_id = 103;

Gagandeep Singh
DATA QUERY LANGUAGE
1 DQL stands for Data Query Language. This Language
is used to Retrieve or read Data from the database
table .

The Statements Present in DQL are :


(i) SELECT : The SELECT statement is used to Retrive
all Data from the Database Table.
2 -- Syntax for Reading Data From the Database for
specific Columns you want to Retrieve --
3
SELECT column_1, column_2, column_n
FROM table_name;
Gagandeep Singh
-- Example –
SELECT cust_id, cust_name
FROM customers;
SET cust_name = ‘Virat’
WHERE cust_id = 103;

-- Syntax for Reading all Data use ( * ) Asterisk Symbol --


SELECT * FROM table_name;

-- Example –
SELECT * FROM customers;

-- Syntax for Getting Unique Values From a Column use DISTINCT --


SELECT DISTINCT column FROM table_name;

-- Example –
SELECT DISTINCT City FROM customers;
Gagandeep Singh
LIKE FOLLOW
& CONNECT
FOR MORE SUCH POST
Gagandeep Singh
www.linkedin.com/in/singhdeepgagan

Gagandeep Singh

You might also like