MySQL Special handling

Source: Internet
Author: User

Mysql> CREATE table EF (BC time);
Query OK, 0 rows affected (0.03 sec)

mysql> INSERT INTO EF values (CURRENT_TIMESTAMP);
Query OK, 1 row Affected (0.00 sec)

Mysql> select * FROM EF;
+----------+
| BC |
+----------+
| 11:33:26 |
| 11:33:35 |
| 11:33:39 |
+----------+
3 Rows in Set (0.00 sec)


Mysql> CREATE TABLE II (QQ datetime);

Because the default value for the current field in MySQL does not support functions, it is not possible to set the default value in the form of create_time datetime default Now (). The alternative is to use the timestamp type instead of the datetime type.
CREATE TABLE Test (
uname varchar () not NULL,
UpdateTime timestamp NULL DEFAULT current_timestamp on UPDATE current_timestamp
) Engine=innodb DEFAULT Charset=utf8;

In MySQL, the default value cannot use a function that is, you cannot set a column, and the default is now () processing
If you need a column with the default value of the current database time, you can use the TIMESTAMP data type. When inserting, fill in the null.

Mysql> CREATE TABLE TestA (dt TIMESTAMP);
Query OK, 0 rows affected (0.09 sec)

mysql> INSERT INTO TestA VALUES (null);
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO TestA VALUES (null);
Query OK, 1 row affected (0.08 sec)

Mysql> select * from TestA;
+---------------------+
| DT |
+---------------------+
| 2011-10-15 20:30:35 |
| 2011-10-15 20:30:36 |
+---------------------+
2 rows in Set (0.00 sec)


SELECT * FROM table1 where 1=1 is completely indistinguishable from the select * FROM table1, there are even many other formulations, 1<>2, ' a ' = ' a ', ' a ' <> ' B ', with only one purpose, where The condition is forever, the result that obtains is not to add the constraint condition.

If you do not write 1=1, then in every non-empty query conditions before, you must determine whether there is a WHERE clause, or in the first occurrence of the place to add where
Where 1=1 is written to detect conditions in the process of checking the program
For example, there are three parameters a, B, c
@sql =select * from TB '
These three parameters are likely to be empty
When you want to construct a statement, a test and then write a statement on the trouble

SELECT * FROM account where username like "%leo.lee%";
Update account Set state = 1 WHERE state! = 1
Select COUNT (*) from account where state! = 1;

Federated is one of the implementations specifically for remote databases. In general, building a table in a local database generates the corresponding table definition file in the database directory and simultaneously generates the corresponding data file.
But tables created by the Federated engine simply have a table definition file locally, and the data file exists in the remote database (which is important).
Use the federated to build the table statement as follows:
CREATE TABLE (...) ENGINE =federated connection= ' mysql://[name]:[pass]@[location]:[port]/[db-name]/[table-name] '
Once created, the corresponding remote table can be queried directly locally.

A few things to note:

1. The local table structure must be exactly the same as the remote.
2. The remote database is currently limited to MySQL
3. Do not support transactions
4. Table structure Modification not supported

MySQL Special handling

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.