Structured Query Language (SQL) - commands and syntaxes

BCfd...szBp
28 Jan 2024
34

SQL is, basically, a programming language planned for accessing, modifying and extracting information from relational databases. As a programming language, SQL has commands and a syntax for providing those commands.


SQL commands are divided into some dissimilar types, including the following:

  1. Data Definition Language (DDL) commands are also called data definition commands because they are used to define data tables.
  2. Data Manipulation Language (DML) commands are used to manipulate data in existing tables by adding, changing or removing data. Unlike DDL commands that define how data is stored, DML commands operate in the tables defined with DDL commands.
  3. Data Query Language consists of just one command, SELECT, used to get specific data from tables. This command is sometimes grouped with the DML commands.
  4. Data Control Language commands are used to grant or revoke user access privileges.
  5. Transaction Control Language commands are used to change the state of some data -- for example, to COMMIT transaction changes or to ROLLBACK transaction changes.


SQL syntax, the set of rules for how SQL statements are written and formatted, is similar to other programming languages. Some components of SQL syntax include the following:

  • SQL statements start with a SQL command and end with a semicolon (;), for example:
SELECT * FROM customers;
  • This SELECT statement extracts all of the contents of a table called customers.
  • SQL statements are case-insensitive, meaning that they can be written using lowercase, uppercase or a combination. However, it is traditional to write out SQL keywords -- commands or control operators -- in all-caps and table/column names in lowercase. Words in the statement can be treated as case-sensitive using quotes, so the following two statements produce identical results.
SELECT * FROM customers;
select * from CUSTOMERS;
  • These two statements are different:
SELECT * FROM customers;
SELECT * FROM "Customers";
  • SQL statements are terminated only by the semicolon, meaning that more complex statements can be rendered across multiple lines, like this one:
SELECT name, telephone, age
FROM customers;
  • This command selects the contents of the columns name, telephone and age in the table customers.
  • SQL statements can incorporate program flow controls, meaning that a statement can incorporate table and row selection -- as in the previous example -- and then operate on the data contained in those columns. For example, the following command selects the name, telephone number and birthdate for all customers whose age is over 21:
SELECT name, telephone, age
FROM customers
WHERE age > 21;
Most SQL executions consist of support for issuing statements at the command line, through a graphical user interface, by using SQL programs or through application programming interfaces to access SQL databases using other programming languages.



Write & Read to Earn with BULB

Learn More

Enjoy this blog? Subscribe to Fuad0707

0 Comments

B
No comments yet.
Most relevant comments are displayed, so some may have been filtered out.