Select Page

Types of SQL Commands

SQL (Structured Query Language) is a language used for managing and manipulating data in a relational database management system (RDBMS). There are several types of SQL commands that can be used to perform different operations on a database. Here are some of the most common types of SQL commands:

Data Definition Language (DDL) Commands: DDL commands are used to define the structure of a database. They include commands like CREATE, ALTER, DROP, and TRUNCATE. These commands are used to create tables, modify their structure, delete them, or remove all of their data.

Data Manipulation Language (DML) Commands: DML commands are used to manipulate data in a database. They include commands like SELECT, INSERT, UPDATE, and DELETE. These commands are used to retrieve data from a table, add new data, modify existing data, or delete data.

Data Control Language (DCL) Commands: DCL commands are used to control access to a database. They include commands like GRANT and REVOKE. These commands are used to grant or revoke privileges to a user or group of users.

Transaction Control Language (TCL) Commands: TCL commands are used to manage transactions in a database. They include commands like COMMIT, ROLLBACK, and SAVEPOINT. These commands are used to manage the changes made to a database during a transaction.

Data Query Language (DQL) Commands: DQL commands are used to retrieve data from a database. They include commands like SELECT, FROM, WHERE, and ORDER BY. These commands are used to retrieve specific data from one or more tables in a database.

SQL commands can be used together to perform complex operations on a database. For example, you can use a DDL command to create a new table, followed by a DML command to insert data into that table, and then use a DQL command to retrieve specific data from the table.

SQL Operators and their procedure

SQL (Structured Query Language) operators are used to perform various operations on data stored in a database. Here are some of the most commonly used operators in SQL and their procedures:

Comparison Operators: Comparison operators are used to compare two values and return a boolean (true/false) result. Some commonly used comparison operators in SQL include:

Equal to (=): Returns true if the two values are equal.

Not equal to (<> or !=): Returns true if the two values are not equal.

Greater than (>): Returns true if the first value is greater than the second value.

Less than (<): Returns true if the first value is less than the second value.

Greater than or equal to (>=): Returns true if the first value is greater than or equal to the second value.

Less than or equal to (<=): Returns true if the first value is less than or equal to the second value.

For example, the following SQL statement uses the comparison operator ‘=’ to retrieve all records from the ‘my_table’ table where the ‘column_name’ column is equal to ‘value’:

sql

SELECT * FROM my_table WHERE column_name = ‘value’;

Logical Operators: Logical operators are used to combine multiple conditions in a SQL statement. Some commonly used logical operators in SQL include:

AND: Returns true if all conditions are true.

OR: Returns true if at least one condition is true.

NOT: Reverses the result of a condition.

For example, the following SQL statement uses the logical operator ‘AND’ to retrieve all records from the ‘my_table’ table where the ‘column_name_1’ column is equal to ‘value_1’ and the ‘column_name_2’ column is equal to ‘value_2’:

SELECT * FROM my_table WHERE column_name_1 = ‘value_1’ AND column_name_2 = ‘value_2’;

Arithmetic Operators: Arithmetic operators are used to perform mathematical operations on values in SQL. Some commonly used arithmetic operators in SQL include:

Addition (+)

Subtraction (-)

Multiplication (*)

Division (/)

For example, the following SQL statement uses the arithmetic operator ‘+’ to retrieve the sum of the ‘column_name_1’ and ‘column_name_2’ columns from the ‘my_table’ table:

vbnet

SELECT column_name_1 + column_name_2 AS total FROM my_table;

String Operators: String operators are used to perform operations on string values in SQL. Some commonly used string operators in SQL include:

Concatenation (||): Combines two or more strings into a single string.

Length (LEN): Returns the length of a string.

Substring (SUBSTR): Returns a portion of a string.

For example, the following SQL statement uses the string operator ‘||’ to concatenate the ‘first_name’ and ‘last_name’ columns from the ‘my_table’ table:

sql

SELECT first_name || ‘ ‘ || last_name AS full_name FROM my_table;

SQL operators can be used together to perform complex operations on data stored in a database.