How to use SQL statement rules in MySQL command line, mysqlsql

Source: Internet
Author: User
Tags how to use sql mysql command line

How to use SQL statement rules in MySQL command line, mysqlsql

Rule 1: the SQL statement must end with a semicolon (;) or (\ G ).

A semicolon (;) indicates the end of an SQL statement. If you forget the semicolon and press the Enter key, the following message is displayed on the MySQL client:

mySQL> SELECT * FROM customer->

Because the SQL statement does not end with a semicolon, the client determines that the SQL statement has not ended. [->] is displayed, waiting for the user to continue entering the command until it ends with a semicolon. In some databases, the last semicolon can be omitted.

Rule 2: reserved keywords are case insensitive

Reserved keywords are keywords defined in SQL. For example, the SELECT and FROM keywords in the preceding query statements are reserved keywords. In SQL, these reserved keywords are case-insensitive. That is to say, all the following statements are correct.
Executed.

mySQL> SELECT * FROM customer;mySQL> select * FROM customer;mySQL> SeLecT * FROM customer;

However, when writing SQL statements, you should keep the keyword size as much as possible. For example, to write reserved keywords in the form of uppercase letters and to write tables or column names in the form of lowercase letters, the SQL statement will also look clear at a glance. In addition, some databases are case sensitive to tables or column names.

Rule 3: free to add blank or line breaks

In the middle of an SQL statement, you can freely add spaces or line breaks. For example, the following languages can be correctly executed.

mySQL> SELECT *-> FROM customer;mySQL> SELECT->*->FROM->customer;

However, adding spaces or line breaks in the middle of a keyword is invalid.

An SQL statement can be written as one line. However, you can add the appropriate line feed to the long periods to facilitate reading.

Line feed in command statements is a reference standard. For example, the names of retrieved object columns are listed one by one in the SELECT statement, and the names of retrieved object tables are listed after the FROM command in the next line, in this way, the entire SQL statement looks distinct.

In addition, you can wrap a line after a column name or table name. For example, you can add an indent (tab) to the column name of the retrieved object after a single row of SELECT columns, list all column names separately in one row.

Rule 4: Use [--] or [/*... */] to add comments.

You can add comments to SQL statements. Annotations are information that is not interpreted by DBMS. Annotations are divided into single-line annotations and multi-line annotations. A single line comment starts with two [-] until the end of a row is treated as a comment. Multi-line comments are strings contained in [/*] and ..

mySQL> SELECT * FROM customer; --THIS IS COMMENTSmysql>/*this/*>is/*>comments*/


How can I use Mysql command lines to execute SQL statements in notepad?

First, change the notepad extension to. SQL, and then enter SOURCE + space + file path name in the command line.
Note: No quotation marks are required for the path name. Also, change "\" in the path name to "/".

How can I run an SQL statement in the doc command line?

Start mysql first -- then enter the SQL statement.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.