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
The Linux stream editor is a useful way to run sc...
Table of contents 1. Download nodejs 2. Double-cl...
Table of contents Introduction to Samba Server Sa...
Table of contents el-scrollbar scroll bar el-uplo...
Overview When a 500 or 502 error occurs during ac...
In combination with the scenario in this article,...
Copy code The code is as follows: <span style=...
Introduction to Git Git is an open source version...
MAC installs mysql8.0, the specific contents are ...
Introduction to HTML page source code layout This...
Table of contents introduction Install Homebrew I...
Table of contents 1. Create components using func...
About who Displays users logged into the system. ...
1. Introduction Presto is an open source distribu...
Table of contents Missing root location Off-By-Sl...