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
Problem Description As we all know, when writing ...
Logo optimization: 1.The logo image should be as ...
Table of contents 1 View the current database con...
I used Vue.js to make a nine-grid image display m...
Purpose Understand the Nginx ngx_http_limit_conn_...
TeamCenter12 enters the account password and clic...
What is a mata tag The <meta> element provi...
Linux version upgrade: 1. First, confirm that the...
I recently started learning database, and I feel ...
How to implement the "Set as homepage" ...
If the frosted glass effect is done well, it can ...
There are two types of Linux system time. (1) Cal...
In the previous sections, we discussed aspects of ...
Set Anchor Point <a name="top"><...
Table of contents 1. Comments on MySQL primary ke...