0% found this document useful (0 votes)
24 views17 pages

SQL Fundamentals - Joseph Konka

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

SQL Fundamentals - Joseph Konka

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

Algo Jungle

SQL Language Essentials


Data Definition Language DDL
Data Manipulation Language DML

Joseph Konka
Contents
A. Data Definition Language

1. Create table
2. Modify table
3. Remove table

B. Data Manipulation Language

1. Create record
2. Read record
3. Update record
4. Delete record
Part I
Data Definition Language
Data Definition Language
DDM consist in databases objects manipulation, create, modify and remove.

Databases objects are tables, views, functions, procedures,….

This presentation only presents how to manipulate tables:

1. Create table

2. Modify an existing table

3. Remove a table
Create table
This is the table creation syntax

CREATE TABLE <table name>

column1 type1,

column2 type2,

column3 type3

);

Note that, I first created a database.


Modify table
Rename table
ALTER TABLE <table name>
RENAME TO <new name>;

Rename column
ALTER TABLE <table name>
RENAME COLUMN <col name> TO <new name>;

Change column type


ALTER TABLE <table name>
ALTER COLUMN <col name> TYPE <new type>;

Add new column


ALTER TABLE <table name>
ADD COLUMN <col name> <col type>;

Delete column
ALTER TABLE <table name>
DROP COLUMN <col name>;
Remove table
Remove table
DROP TABLE <table name>;

Remove table if it exists


DROP TABLE IF EXISTS <table name>;

Just remove table contents


TRUNCATE <table name>;
Part II
Data Manipulation Language
Data Manipulation Language
DDL consists in manipulating records contained in a table.

1. CREATE

2. READ

3. UPDATE

4. DELETE

These different operations are commonly called CRUD.


Insert record into a table
Insert a record/row/data
INSERT INTO <table> (<col1>, <col2>)
VALUES (<value1>, <value2>);

Insert multiple records


INSERT INTO <table> (<col1>, <col2>)
VALUES (<value11>, <value12>),
(<value21>, <value22>),
(<value31>, <value32>),
(<value41>, <value42>);
Read records from a table
Read entire content
SELECT *
FROM <table name>;

Sort records
SELECT *
FROM <table name>
ORDER BY <col name>;

Filter records
SELECT *
FROM <table name>
WHERE <condition>;
Update records
Update specific records
UPDATE <table name>
SET <col name> = <new value>
WHERE <condition>;

Update multiple columns


UPDATE <table name>
SET <col1 name> = <new value1>,
<col2 name> = <new value2>
WHERE <condition>

Update all records


UPDATE <table name>
SET <col name> = <new value>;
Delete records
Delete specific record
DELETE FROM <table name>
WHERE <condition>;

Delete entire records


DELETE FROM <table name>;

This last operation can be used instaed of


TRUNCATE <table name>.
Appendix
SQL : Structured Query Language

DDL : Data Definition Language

DML : Data Manipulation Language

CRUD : Create Read Update Delete

Record : Row/Data

If you have any questions, feel free to send me message on +228 91 51 89 23.
Algo Jungle Follow me on social medias

Joseph Konka

github.com/algojungle

[email protected]

+228 91 51 89 23

algojungle.herokuapp.com
Joseph Konka
Technical Writer at Algo Jungle
‘‘Le savoir est la seule matière qui s’accroît
[email protected] quand on la partage.’’ Socrate
Algo Jungle
algojungle.herokuapp.com
Algo Jungle
Community
Let’s Connect and Learn Together !

ALGO JUNGLE

You might also like