MySQL Language Syntax

Good Day!!!

In this tutorial, we are going to learn about the MySQL Language Syntax and this is the continuation of MySQL Tutorials. My last work was all about the Installation of MySQL. In this Chapter, we will know how most actions on a database are performed using the SQL statements.

SQL Statements

This is the free-form language for SQL, statements are the following:
  • Uppecase or Lowercase. Example: (SELECT, select and sELeCT are all considered identical keywords)
  • As long as you don't split words, tokens or quoted strings in two, you can continue on the next line.
  • You can start in any column.
  • Be on the same line as other statements.
The SQL statements consist of clauses and expressions. The image below is a diagram that uses a SELECT statement to illustrate the basic syntax of an SQL statement: Select Statement SQL can be divided into two parts. These are:
  • Data Manipulation Language (DML)
  • Data Definiton Language (DDL)
This is the query and update commands form for the Data Manipulation Language (DML) part of a SQL:
  • SELECT - extracts data from a database
  • UPDATE - updates data in a database
  • DELETE - deletes data fro a database
  • INSERT INTO - inserts new data into a database
The Data Definiton Language (DDL) it can create or delete database tables in SQL. It can also specify links between tables, impose constraints between table and it can be define indexes (keys). For the Data Definiton Language (DDL), these are the most important statements in SQL:
  • CREATE DATABASE - to create a new database
  • ALTER DATABASE - to modify database
  • CREATE TABLE - to create a new table
  • ALTER TABLE - to modify table
  • DROP TABLE - to delete a table
  • CREATE INDEX - to create index (search key)
  • DROP INDEX - to delete a index

Comments

The MySQL Server supports three comment styles:
  • #
  • --
  • /* */
From a "#" character to the end of the line. From a "--" sequence to the end of the line. In MySQL, the "--" (double-dash) comment style it requires for the second dash to be followed by at least one whitespace or the control character (such as a space, tab and newline). This is different from the standard SQL comment syntax. From a "/* */" sequence to the following, as in the C programming language. You can enable a multiple lines comment because the beginning and closing nee not be on the same line. The following example demonstrates all three type of comment styles in SQL statement:
  1. mysql> SELECT 1+1; # This comment
  2. continues TO the END OF line
  3. mysql> SELECT 1+1; -- This comment
  4. continues TO the END OF line
  5. mysql> SELECT 1 /* this is an
  6. in-line comment */ + 1;
  7. mysql> SELECT 1+
  8. /* this is a multi-line comment
  9. */ 1;
In general, nested comments are not supported. In the next tutorial, we will discuss Reserve Words in MySQL. So what can you say about this tutorial? Share your thoughts in the comment section below and also, don’t forget to like this page. Thank you.

Add new comment