0% found this document useful (0 votes)
3 views10 pages

08 Create Update Delete, Insert Queries

Uploaded by

Jhanzab Khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views10 pages

08 Create Update Delete, Insert Queries

Uploaded by

Jhanzab Khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Create, Update,

Delete, Insert Queries


Week 9

Muhammad Qasim
SQL Commands
These SQL commands are mainly categorized into four categories as:
 DDL – Data Definition Language

◦ CREATE – is used to create the database or its objects (like table, index,
function, views, store procedure and triggers).
◦ DROP – is used to delete objects from the database.
◦ ALTER-is used to alter the structure of the database.
 DQL – Data Query Language
◦ SELECT – is used to retrieve data from the a database.
 DML – Data Manipulation Language
◦ INSERT – is used to insert data into a table.
◦ UPDATE – is used to update existing data within a table.
◦ DELETE – is used to delete records from a database table.
 DCL – Data Control Language
◦ GRANT-gives user’s access privileges to database.
◦ REVOKE-withdraw user’s access privileges given by using the GRANT
command.
Create
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
....
);

CREATE TABLE Persons (


PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
Drop
DROP TABLE table_name;

DROP TABLE Persons;


Alter
ALTER TABLE table_name
ADD column_name datatype;

ALTER TABLE Customers


ADD Email varchar(255);
Insert
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);

INSERT INTO Customers (CustomerName, ContactName, Address, City,


PostalCode, Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen
21', 'Stavanger', '4006', 'Norway');
Update
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

UPDATE Customers
SET ContactName = 'Alfred Schmidt', City= 'Frankfurt'
WHERE CustomerID = 1;
Delete
DELETE FROM table_name WHERE condition;

DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste';


Grant
GRANT privilege_name
ON object_name
TO {user_name |PUBLIC |role_name}
[WITH GRANT OPTION];

GRANT SELECT ON employee TO user1;


Revoke
REVOKE privilege_name
ON object_name
FROM {user_name |PUBLIC |role_name}

REVOKE SELECT ON employee FROM user1;

You might also like