1. Comments on MySQL primary keys and table fields1. Primary key and auto-incrementEach table usually has one and only one primary key to indicate the uniqueness of each piece of data. Features: Values cannot be repeated and cannot be null
Primary key + auto-increment writing method:
Note: Auto-increment can only be used with the primary key (if defined separately, an error will be reported) 2. Comments on table fieldsmysql> alter table test modify Name varchar(12) comment 'user name'; 3. Multi-table querymysql> create table A(ID int primary key auto_increment,Name varchar(12),Department int); mysql> create table B(ID int primary key auto_increment,Name varchar(12)); mysql> insert into B(Name) values("Finance"),("Market"); mysql> insert into A(Name,Department) values("张三",1),("李四",2),("王五",2); mysql> select B.Name 部门,A.Name from B,A where B.ID=2 and A.Department=2; 2. Database Transaction OverviewDatabase: relational database (supports transactions); non-relational database (does not support)
A transaction contains multiple SQL statements, and there are certain relationships between these SQL statements:
1. Database transaction characteristics (ACID)
2. Transaction concurrency without transaction isolation
the difference:
Isolation Level:
MySQL supports the above four isolation levels, with repeatable read being the default. If you want to change the isolation level, you need to: mysql> show variables like '%tx_is%'; mysql> exit [root@MySQL ~]# sed -i '/\[mysqld]/a transaction-isolation = SERIALIZABLE' /etc/my.cnf [root@MySQL ~]# systemctl restart mysqld [root@MySQL ~]# mysql -uroot -p123123 -e "show variables like '%tx_is%';" 4.MySQL database management transactionsThree commands to manage transactions:
mysql> create table C(ID int); mysql> insert into C values(1),(2); mysql> select * from C; mysql> BEGIN; mysql> insert into C values(3); mysql> COMMIT; mysql> select * from C; mysql> show variables like 'autocommit'; #Check whether to enable automatic transaction commitmysql> BEGIN; mysql> insert into C values(4) mysql> select * from C; mysql> exit [root@localhost ~]# mysql -uroot -p123123 -e "select * from Coco.C where ID=4" mysql> set autocommit=0; mysql> select * from Coco.C; mysql> insert into Coco.C values(4); mysql> select * from Coco.C where ID=4; [root@localhost ~]# mysql -uroot -p123123 -e "select * from Coco.C where ID=4" Notice:
1) Aliasmysql> select ID as "Number",Name as "Name",Department as "Department" from A where ID=1; mysql> select ID "Number",Name "Name",Department "Department" from A where ID=1; 2) Deduplicationmysql> select distinct Department from A; 3) AND and OR operatorsAND: logical AND (all conditions must be met); OR: logical OR (only one of the conditions needs to be met). mysql> select * from A where ID >= 3 and Department = 2; mysql> select * from A where ID >= 3 or Department = 2;
mysql> select * from A where ID in(1,3,4); mysql> select * from A where ID not in(1,3,4); mysql> select * from A where ID between 1 and 3; 4) SQL LIKE Operator
mysql> select * from A where Name like "%三%"; mysql> select * from A where Name like "%三%" or Name like "%四"; 5) SQL ORDER BY Clause
mysql> select * from A order by ID desc; mysql> select * from A order by Department,ID desc; 6) Limit Clausemysql> select * from C; mysql> select * from C limit 2; mysql> select * from C limit 0,2; SummarizeThis is the end of this article about MySQL primary keys and transactions. For more relevant MySQL primary keys and transactions, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Nginx Layer 4 Load Balancing Configuration Guide
>>: Drop-down menu and sliding menu design examples
View container logs First, use docker run -it --r...
This article example shares the specific code of ...
This article shares the specific code of Vue to a...
This article shares the specific code of js to re...
Preface In the development of actual projects, we...
Prepare war package 1. Prepare the existing Sprin...
First, the principle of esp8266 publishes message...
Table of contents 1.Vue.js features: 2.Observer.j...
Table of contents What is FormData? A practical e...
The parent node of the parent node, for example, t...
Preface PIPE, translated as pipeline. Angular pip...
Table of contents background 1. Document Descript...
This article shares the specific code of Vue usin...
Table of contents Install Redis on Docker 1. Find...
1. Execute the select statement first to generate...