SQLite and MySQL common knowledge points

Source: Internet
Author: User

First, SQLite:

1. Command Line annotator --

2. Paging Query
Select * from messages limit 10,100;
This indicates that 10 rows are skipped and the returned results of 100 rows are taken.

3. Set the default Field Value
Create Table T2 (ID integer default 0, time datetime default (strftime ('% Y-% m-% d % H: % m: % s ', 'Now ')));
Or create table T2 (ID integer default 0, time datetime default (datetime ()));

4. connection string Connection Symbol |

Example:
Update message set content = content | 'abc ';

5. federated primary keys
Create Table Test (col1 char (2), col2 char (2), primary key (col1, col2 ));

6. Ignore (replace) This statement if the primary key already exists during data insertion.
Insert or ignore (replace) into user values ('abc ');

7. Create a trigger to automatically update the last_update_time of the table:
Create trigger tr_test Before update on test for each row begin update Test Set gtime = datetime () Where id = new. ID; end;

MySQL:

1. Command Line annotator #

2. Paging Query
Select * from messages limit 10,100;
This indicates that 10 rows are skipped and the returned results of 100 rows are taken.

3. The default table Creation Time column is the current time.
Create Table mtable (my_time timestamp default current_timestamp );

4. connection string connection function Concat

Example:
Update message set content = content | 'abc ';

5. federated primary keys
Create Table Test (col1 char (2), col2 char (2), primary key (col1, col2 ));

6. Ignore (replace) This statement if the primary key already exists during data insertion.
Insert or ignore (replace) into user values ('abc ');

7. The fields are case sensitive during table creation.

Column_name varchar (20) Character Set utf8 collate utf8_bin

8. Use variables for table names
/* ----- Create a stored procedure: sp_auto_create -------*/
Delimiter ;;
Create procedure sp_auto_create (in tname char (32 ))
Begin
Set @ stmt = Concat ('create table', tname, '(ID int, name varchar (10 ));');
Prepare S1 from @ stmt;
Execute S1;
End ;;
Delimiter;
/* ----- Execute the stored procedure: sp_auto_create to automatically generate the table test -------*/
Call sp_auto_create ('test ');

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.