SQL Command (DML)

[日本語]

This is a memo of SQL commands which I learned from workplace and self-study.

If you do not know SQL, please refer to “Database, DBMS and SQL“. Here, SQL commands are classified as follows.

DDL

DML

DCL

Others

  • DML (Data Manipulation Language)

Commands for retrieving, adding, updating, and deleting data in a table.

Prof. Wiki:”For adding (inserting), deleting, and modifying (updating) data in a database.”

  • DML Command List and Description

※Checked operation with MySQL and PostgreSQL.

– Insert a value into a table

INSERT INTO table_name VALUES
(1, 'ABC', 12),
(2, 'ABC', 12),
(3, 'EFG', 34);

– Retrieve value from table

SELECT * FROM table_name;

– Conditionally retrieve values from a table

(The following conditions:”column_name_1″ is “2” )

SELECT * FROM table_name WHERE column_name_1 = 1 ;
Comparison operator Description
= Left and right values are equal
<> Left and right values are not equal
< Left value is less than right value
> Left value is greater than right value
<= Left value is less than right value
>= Left value is greater than right value

Usage example of AND

SELECT * FROM table_name
WHERE
column_name_1 = 1 AND column_name_2 = 'ABC';

Usage example of OR

SELECT * FROM table_name
WHERE
column_name_1 = 1 OR column_name_2 = 'EFG';

– Update table records

UPDATE table_name SET
column_name_2 = 'ZYX',
column_name_3 = 56
WHERE
column_name_1 = 2;

– Delete table records

DELETE FROM table_name WHERE column_name_1 = 3;

– Delete all records in the table

DELETE FROM table_name;

20190701

 

 

Leave a comment