0% found this document useful (0 votes)
6 views2 pages

SQL Syntax (1)

The document outlines SQL syntax for Data Definition Language (DDL), Data Manipulation Language (DML), and Data Query Language (DQL) commands. It includes commands for creating, altering, and deleting databases and tables, as well as inserting, updating, and deleting records. Additionally, it provides various query examples for retrieving data with specific conditions and aggregations.

Uploaded by

yahiyama650
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
6 views2 pages

SQL Syntax (1)

The document outlines SQL syntax for Data Definition Language (DDL), Data Manipulation Language (DML), and Data Query Language (DQL) commands. It includes commands for creating, altering, and deleting databases and tables, as well as inserting, updating, and deleting records. Additionally, it provides various query examples for retrieving data with specific conditions and aggregations.

Uploaded by

yahiyama650
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

SQL Syntax

DDL Commands

1. Creating a Database: CREATE DATABASE <database_name>;


2. Opening a Database: USE <database_name>;
3. Creating a Table: CREATE TABLE < table_name> (<col_name> <data_type> <constraints>, foreign key(<col_name>) REFERENCES <refer_table>(<refer_column>));
4. Structure of a Table: DESC <table_name>;
5. Altering a Table:
i. Adding a Column: ALTER TABLE <table_name> ADD <col_name> <data_type> <constraints>;
ii. Renaming a Column: ALTER TABLE <table_name> CHANGE <current_name> <new_name> <data_type>;
iii. Modifying a Column: ALTER TABLE <table_name> MODIFY <col_name> <changed_data_type>;
iv. Removing a Column: ALTER TABLE <table_name> DROP <col_name>;
6. Deleting a Table: DROP TABLE <table_name>;
7. Deleting a Database: DROP DATABASE <database_name>;

DML Commands
1. Inserting Records into a Table: INSERT INTO <table_name> VALUES(<values_list1>), (<values_list2>);
2. Updating Records in a Table: UPDATE <table_name> SET <col_name> = <new_value> WHERE <condition>;
3. Deleting Records from a Table: DELETE FROM <table_name> WHERE <condition>;
DQL Commands
1. Display all Records from a Table: SELECT * FROM <table_name>;
2. Display only certain Columns from a Table: SELECT <col_name1><col_name2> FROM <table_name>;
3. Display Text with Records of the Table: SELECT <col_name1> <text> <col_name2> FROM <table_name>;
4. Display added/subtracted integer with Records of a Table: SELECT <col_name1><col_name2_type=int>+<number> FROM <table_name>;
5. Display the Records of a Table with an Alias Name: SELECT <col_name1> AS <alias_name> FROM <table_name>;
6. Display the Records of a Table satisfying a Condition: SELECT * FROM <table_name> WHERE <condition> <conjunctive_operator> <condition>;
7. Display Unique Records from a Table: SELECT DISTINCT <col_name> FROM <table_name>;
8. Display the Records of a Table Between a certain range: SELECT * FROM <table_name> WHERE <col_name> BETWEEN <value1> AND <value2>;
9. Display the Records of a Table with a certain value: SELECT * FROM <table_name> WHERE <col_name> IN (<value1>,<value2>,<value3>);
10. Display the Records of a Table showing a Pattern: SELECT * FROM <table_name> WHERE <col_name> LIKE <value_and_wildcard>;
11. Display the Records of a Table in the Appending Order of a Column: SELECT * FROM <table_name> ORDER BY <col_name> ASC;
12. Display the Records of a Table in the Descending Order of a Column: SELECT * FROM <table_name> ORDER BY <col_name> DESC;
13. Display the Maximum Value of a Column in a Table: SELECT MAX(<col_name>) FROM <table_name>;
14. Display the Minimum Value of a Column in a Table: SELECT MIN(<col_name>) FROM <table_name>;
15. Display the Sum of Values of a Column in a Table: SELECT SUM(<col_name>) FROM <table_name>;
16. Display the Average Value of a Column in a Table: SELECT AVG(<col_name>) FROM <table_name>;
17. Display the Number of Records in a Table: SELECT COUNT(*) FROM <table_name>;
18. Display the Number of Values in a Column of a Table: SELECT COUNT(<col_name>) FROM <table_name>;
19. Display the Number of Unique Values in a Column of a Table: SELECT COUNT(DISTINCT <col_name>) FROM <table_name>;
20. Display the Records of a Table Group-wise: SELECT <col_name1><col_name2> FROM <table_name> GROUP <col_name1> HAVING <aggregate_functions>;
21. Cartesian Product of two Tables: SELECT <x>.<col_name1>, <y>.<col_name2> FROM <table_name1> <x>, <table_name2> <y>,
➔ WHERE <x>.<primary_key > = <y>.<foreign_key >;

Others

data_type: [INTEGER, FLOAT, DECIMAL(size, precision), CHAR(size), VARCHAR(size), DATE, TIME]

constraints: [PRIMARY KEY, NOT NULL, UNIQUE, DEFAULT, FOREIGN KEY]

conjunctive_operator: [NOT, AND, OR]

wildcard: [%, _]

aggregate_functions: [MAX, MIN, SUM, AVG ,COUNT]

You might also like