SQL 6 DDL - 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

DATA SCIENCE

SQL
SQL Commands

Data Manipulation Language (DML) - deals with data


manipulation (used to retrieve, store, modify, delete and update
data in database).

Data Definition Language (DDL) - defining and dealing with


database schemas and descriptions of how the data should exist
in database.
SQL Commands
Data Manipulation Language Data Definition Language
SELECT DROP
UPDATE RENAME
CREATE
DELETE ALTER
INSERT TRUNCATE
(SUDI) (DR CAT)

DML Commands can be


DDL Commands cannot be
reversed / Rolled back
reversed / Rolled Back
Important Datatypes in ORACLE

Data Type Syntax Explanation


Where size is the number of characters to store. Fixed-length strings. Space
char(size)
padded.
Where size is the number of characters to store. Fixed-length NLS string Space
varchar(size)
padded.
Where p is the precision and s is the scale.
number(p,s) For example, number(7,2) is a number that has 5 digits before the decimal and 2
digits after the decimal.
Where p is the precision and s is the scale.
dec(p,s) For example, dec(3,1) is a number that has 2 digits before the decimal and 1 digit
after the decimal.
date A date. Format: YYYY-MM-DD. The supported range is from '1000-01-01' to '9999-12-31'

BOOLEN Zero is considered as false, nonzero values are considered as true.


A integer. Signed range is from -2147483648 to 2147483647. Unsigned range is from 0
integer
to 4294967295. The size parameter specifies the maximum display width (which is 255)
Difference between Char() and
varChar()

Difference is in Memory Allocation

Use char when the sizes of the column data entries are consistent.
char(10)--> takes 10 spaces in memory regardless of how much is used. Example: John (Column)
--> still take 10 spaces

Use varchar when the sizes of the column data entries varies.
varChar(10) --> may take up to 10 spaces in memory. Example: John (Column) --> It will only
take 4 spaces from memory and rest will be left to be used for something else
Create Command
Task:
Create a table called CLIENTS_YourNameDoB with 5 columns :
Client_ID,
First_Name,
Last_Name,
Postal_Address,
State_Address
Make
client ID datatype numbers --> should be NOT NULL Primary Key
First Name datatype varchar NOT NULL
Last Name datatype varchar not null
Postal Address varchar
State_ Address char
Insert Statement
Update Statement
Delete Statement
Used to delete ROWS in a Table
Alter Statement ADD Column
The ALTER TABLE statement is used to add, delete, or modify columns in an existing
table.
The ALTER TABLE statement is also used to add and drop various constraints on an
existing table.
To Add a column in a table, use the following syntax:

SYNTAX

ALTER TABLE table_name


ADD column_name datatype;
Alter Statement RENAME Column
To Rename a column in a table, use the following syntax:

SYNTAX

ALTER TABLE table_name


RENAME COLUMN
”column1” to “column2” datatype;
Alter Statement DROP Column
To Drop a column in a table, use the following syntax:

SYNTAX

ALTER TABLE table_name


DROP COLUMN column_name;
Alter Statement ALTER/MODIFY Column
To Modify a column in a table, use the following syntax:

SYNTAX

ALTER TABLE table_name


MODIFY column_name datatype;
Truncate Statement

• Used to remove data / records from the table and NOT THE TABLE
ITSELF
• Keeps the TABLE in place but deletes All the DATA / RECORDS in the
Table
Drop Table Statement
Used to delete the Data and the Table from Database
Rename Table Statement
Used to Rename the Table from Database

Syntax

Rename Table table_name


Task:
● Insert 3 records to the Clients table
○ - First row Enter all columns
Client id (1) First Name ( Ali ) Last name( Ahmad ) Postal Address ( 22312 ) State Address ( VA )
○ - Second row leave postal Address blank
Client id (2) First Name ( John ) Last name( doe ) State Address ( VA )
○ - Third row leave state blank.
Client id (3) First Name ( Sara ) Last name( Smith ) State Address ( MD )

(Post a Screenshot on Slack )

● Update First Customer client id to (15), second customer's Last name to (


Alex ), third customer's State_Address to (VA).

(Post a Screenshot on Slack )

● Delete Second record from a table.


● Due to recent changes made in the company, The hiring manager wants
you to remove all the records from the Clients Table.
Task:
● Insert 3 records to the Clients table
○ - First row Enter all columns
Client id (1) First Name ( Uzma ) Last name( Bashir ) Postal Address ( 65000 ) State Address ( Sindh )
○ - Second row leave postal Address blank
Client id (2) First Name ( Fiza ) Last name( Tahir ) State Address ( Baluchistan )
○ - Third row leave state blank.
Client id (3) First Name ( Asad ) Last name( Umer ) Postal Address ( 54000 )
● Delete Second record from a table.
● Insert A new Row Into The Table.
First Name ( Maham ) Last name( Naeem ) Postal Address ( 65000 ) State Address ( Sindh )
● remove the CLIENTS table from database (Table and Data)
SQL Commands
➢ Data Definition Language (DDL) - defining and dealing
with database schemas and descriptions of how the data
should exist in database.
➢ Data Manipulation Language (DML) - deals with data
manipulation (used to retrieve, store, modify, delete and
update data in database).
➢ Data Control Language (DCL) - deals with rights,
permissions and other controls of the database system.
➢ Transaction Control Language (TCL) – deals with a
transaction within a database.
SQL Commands
DML DDL DCL TCL

SELECT DROP
UPDATE RENAME REVOKE COMMIT
DELETE CREATE GRANT ROLLBACK
INSERT ALTER
TRUNCATE
SQL Commands
Data Manipulation Data Definition Language
Language DROP
SELECT RENAME
UPDATE CREATE
DELETE ALTER
TRUNCATE
INSERT (DR CAT)
(SUDI)

DML Commands can be DDL Commands cannot be


reversed / Rolled back reversed / Rolled Back
What is the difference
between DELETE,
TRUNCATE, DROP?

?
THANK YOU
QUESTIONS & ANSWERS

You might also like