|
The MySQL command line interface allows you to put a statement on one line or spread it across multiple lines. There's no difference in syntax between the two. Using multiple lines allows you to break down the SQL statement into steps you may more easily comprehend.
In multiple line mode, the interpreter appends each line to the prior lines. This continues until you enter a semicolon " ; " to close out the SQL statement. Once the semicolon is typed in and you hit enter, the statement is executed.
Here's an example of the same exact SQL statement entered both ways:
Single Line Entry
mysql 4.1.16-nt-max> create table
table33 (field01 integer,field02 char(30)); |
Multiple Line Entry
mysql 4.1.16-nt-max> create table
table33
-> (field01
-> integer,
-> field02
-> char(30)); |
Don't break up words:
Valid |
Invalid |
mysql 4.1.16-nt-max> create table table33
-> (field01
-> integer,
-> field02
-> char(30)); |
mysql 4.1.16-nt-max> create table table33
-> (field01 inte
-> ger,
-> field02
-> char(30)); |
When inserting or updating records, do not spread a field's string across multiple lines, otherwise the line breaks are stored in the record:
Standard Operation
mysql
4.1.16-nt-max> insert into table33 (field02)
-> values
-> ('Who
thought of foo?'); |
Line Break Stored in Record
mysql
4.1.16-nt-max> insert into table33 (field02)
-> values
-> ('Pooh
thought
-> of foo.'); |
Results
mysql 4.1.16-nt-max> select * from
table33;
| Field01 |
| field02 |
NULL
NULL
of foo. | |
Who thought of foo?
Pooh thought |
|
|