mysql> USE mon
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> SHOW TABLES;
+---------------+
| Tables_in_mon |
+---------------+
| qqq |
+---------------+
1 row in set (0.00 sec) mysql> DESC qqq;
+----------+--------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------------+------+-----+---------+-------+
| username | varchar(10) | YES | | NULL | |
| munber | int(11) | YES | | NULL | |
| money | decimal(8,2) | YES | | NULL | |
| sex | enum('n','NV','M') | YES | | NULL | |
| content | text | YES | | NULL | |
+----------+--------------------+------+-----+---------+-------+
5 rows in set (0.00 sec) mysql> SHOW COLUMNS FROM qqq;
+----------+--------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------------+------+-----+---------+-------+
| username | varchar(10) | YES | | NULL | |
| munber | int(11) | YES | | NULL | |
| money | decimal(8,2) | YES | | NULL | |
| sex | enum('n','NV','M') | YES | | NULL | |
| content | text | YES | | NULL | |
+----------+--------------------+------+-----+---------+-------+
5 rows in set (0.00 sec) mysql> INSERT INTO qqq (username,munber,money,sex) VALUES('quanzhiqia',23,1351.41,'n');
Query OK, 1 row affected (0.07 sec) mysql> INSERT INTO qqq (username,munber,money,sex) VALUES('quanzhiqia',23,1351.41121,'n');
Query OK, 1 row affected, 1 warning (0.12 sec) mysql> SHOW WARNINGS;
+-------+------+--------------------------------------------+
| Level | Code | Message |
+-------+------+--------------------------------------------+
| Note | 1265 | Data truncated for column 'money' at row 1 |
+-------+------+--------------------------------------------+
1 row in set (0.00 sec) mysql> SELECT money FROM qqq;
+---------+
| money |
+---------+
| 1351.41 |
| 1351.41 |
+---------+
2 rows in set (0.01 sec) mysql> SELECT money,sex FROM qqq;
+---------+------+
| money | sex |
+---------+------+
| 1351.41 | n |
| 1351.41 | n |
+---------+------+
2 rows in set (0.09 sec) mysql> SELECT * FROM qqq;
+------------+--------+---------+------+---------+
| username | munber | money | sex | content |
+------------+--------+---------+------+---------+
| quanzhiqia | 23 | 1351.41 | n | NULL |
| quanzhiqia | 23 | 1351.41 | n | NULL |
+------------+--------+---------+------+---------+
2 rows in set (0.00 sec) mysql> mysql> CREATE TABLE numm(tiny TINYINT UNSIGNED) ENGINE=MYISAM CHARACTER SET utf8MB4;
Query OK, 0 rows affected (0.14 sec) mysql> DESC numm;
+-------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------------+------+-----+---------+-------+
| tiny | tinyint(3) unsigned | YES | | NULL | |
+-------+---------------------+------+-----+---------+-------+
1 row in set (0.02 sec) mysql> INSERT INTO numm VALUES(255);
Query OK, 1 row affected (0.10 sec) mysql> SELECT * FROM numm;
+------+
| tiny |
+------+
| 255 |
+------+
1 row in set (0.00 sec) mysql> CREATE TABLE nummm(
-> mun SMALLINT ZEROFILL )ENGINE=MYISAM CHARSET utf8MB4;
Query OK, 0 rows affected (0.00 sec) mysql> DESC nummm;
+-------+-------------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------------------------+------+-----+---------+-------+
| mun | smallint(5) unsigned zerofill | YES | | NULL | |
+-------+-------------------------------+------+-----+---------+-------+
1 row in set (0.00 sec) mysql> INSERT INTO nummm VALUES(99);
Query OK, 1 row affected (0.00 sec) mysql> SELECT * FROM nummm;
+-------+
| mun |
+-------+
| 00099 |
+-------+
1 row in set (0.00 sec) mysql> DESC qqq;
+----------+--------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------------+------+-----+---------+-------+
| username | varchar(10) | YES | | NULL | |
| munber | int(11) | YES | | NULL | |
| money | decimal(8,2) | YES | | NULL | |
| sex | enum('n','NV','M') | YES | | NULL | |
| content | text | YES | | NULL | |
+----------+--------------------+------+-----+---------+-------+
5 rows in set (0.00 sec) mysql> CREATE TABLE nu (
-> user CHAR(10) NOT NULL,
-> pass CHAR(32) NULL);
Query OK, 0 rows affected (0.13 sec) mysql> DESC nu;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| user | char(10) | NO | | NULL | |
| pass | char(32) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
2 rows in set (0.00 sec) mysql> INSERT INTO nu (pass) VALUES('FEF');
ERROR 1364 (HY000): Field 'user' doesn't have a default value
mysql> SELECT * FROM nu;
Empty set (0.00 sec) mysql> INSERT INTO nu (user) VALUES('FEF');
Query OK, 1 row affected (0.01 sec) mysql> SELECT * FROM nu;
+------+------+
| user | pass |
+------+------+
| FEF | NULL |
+------+------+
1 row in set (0.00 sec) mysql> CREATE TABLE tp3(
-> username CHAR(10) NOT NULL DEFAULT 'QUAN',
-> user CHAR(12) NULL);
Query OK, 0 rows affected (0.12 sec)
mysql> DESC tp3;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| username | char(10) | NO | | QUAN | |
| user | char(12) | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
2 rows in set (0.00 sec) mysql> INSERT INTO tp3 (user) VALUES('FEFE');
Query OK, 1 row affected (0.00 sec) mysql> SELECT * FROM tp3;
+----------+------+
| username | user |
+----------+------+
| QUAN | FEFE |
+----------+------+
1 row in set (0.00 sec)

主键约束:

mysql> CREATE TABLE tp4(
-> id INT AUTO_INCREMENT PRIMARY KEY,
-> user CHAR(10) NOT NULL);
Query OK, 0 rows affected (0.13 sec) mysql> DESC tp4;
+-------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| user | char(10) | NO | | NULL | |
+-------+----------+------+-----+---------+----------------+
2 rows in set (0.01 sec) mysql> INSERT INTO tp4 (user) VALUES('FEF');
Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO tp4 (user) VALUES('FEFE');
Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO tp4 (user) VALUES('WWWE');
Query OK, 1 row affected (0.00 sec) mysql> SELECT * FROM tp4;
+----+------+
| id | user |
+----+------+
| 1 | FEF |
| 2 | FEFE |
| 3 | WWWE |
+----+------+
3 rows in set (0.00 sec) mysql> CREATE TABLE tp5 (
-> id INT PRIMARY KEY,
-> user CHAR(10) NOT NULL);
Query OK, 0 rows affected (0.11 sec) mysql> DESC tp5;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| user | char(10) | NO | | NULL | |
+-------+----------+------+-----+---------+-------+
2 rows in set (0.00 sec) mysql> INSERT INTO tp5(user) VALUES('fefe');
ERROR 1364 (HY000): Field 'id' doesn't have a default value
mysql> INSERT INTO tp5(id,user) VALUES(11,'fefe');
Query OK, 1 row affected (0.01 sec) mysql> INSERT INTO tp5 VALUES(21,'fefe');
Query OK, 1 row affected (0.01 sec) mysql> SELECT * FROM tp5;
+----+------+
| id | user |
+----+------+
| 11 | fefe |
| 21 | fefe |
+----+------+
2 rows in set (0.00 sec) mysql> INSERT INTO tp5 VALUES(21,'fefe');
ERROR 1062 (23000): Duplicate entry '21' for key 'PRIMARY'
mysql> CREATE TABLE tp6( id INT AUTO_INCREMENT PRIMARY KEY, username CHAR(10) NOT NULL UNIQUE KEY, tel C
Query OK, 0 rows affected (0.19 sec) mysql> DESC tp5;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| user | char(10) | NO | | NULL | |
+-------+----------+------+-----+---------+-------+
2 rows in set (0.00 sec) mysql> DESC tp6;
+----------+------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| username | char(10) | NO | UNI | NULL | |
| tel | char(11) | YES | UNI | NULL | |
| sex | tinyint(4) | NO | | 0 | |
+----------+------------+------+-----+---------+----------------+
4 rows in set (0.00 sec) mysql> INSERT INTO tp6 VALUES( 'null','quan','15219588659');
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> INSERT INTO tp6 VALUES( 'null','quan','15219588659',1);
ERROR 1366 (HY000): Incorrect integer value: 'null' for column 'id' at row 1
mysql> INSERT INTO tp6 VALUES( null,'quan','15219588659',1);
Query OK, 1 row affected (0.00 sec) mysql> SELECT * FROM tp6;
+----+----------+-------------+-----+
| id | username | tel | sex |
+----+----------+-------------+-----+
| 1 | quan | 15219588659 | 1 |
+----+----------+-------------+-----+
1 row in set (0.00 sec) mysql> INSERT INTO tp6 VALUES( null,'quan','15219588659',0);
ERROR 1062 (23000): Duplicate entry 'quan' for key 'username'
mysql> INSERT INTO tp6 VALUES( null,'quan1','15219588659',0);
ERROR 1062 (23000): Duplicate entry '15219588659' for key 'tel'
mysql> INSERT INTO tp6 VALUES( null,'quan1','15219588658',0);
Query OK, 1 row affected (0.00 sec) mysql> SELECT * FROM tp6;
+----+----------+-------------+-----+
| id | username | tel | sex |
+----+----------+-------------+-----+
| 1 | quan | 15219588659 | 1 |
| 4 | quan1 | 15219588658 | 0 |
+----+----------+-------------+-----+
2 rows in set (0.00 sec) mysql> INSERT INTO tp6 (username,tel) VALUES('quan2','13145710069');
Query OK, 1 row affected (0.00 sec) mysql> SELECT * FROM tp6;
+----+----------+-------------+-----+
| id | username | tel | sex |
+----+----------+-------------+-----+
| 1 | quan | 15219588659 | 1 |
| 4 | quan1 | 15219588658 | 0 |
| 5 | quan2 | 13145710069 | 0 |
+----+----------+-------------+-----+
3 rows in set (0.00 sec)
mysql> CREATE TABLE fa(
-> id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
-> name CHAR(10) NOT NULL);
Query OK, 0 rows affected (0.12 sec)
mysql> CREATE TABLE ss( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, name CHAR(10) NOT NULL, cid INT UNSIGNED, FOREIGN KEY(cid) REFERENCES fa(id));
Query OK, 0 rows affected (0.20 sec)
mysql> SHOW CREATE TABLE fa;
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------+
| fa | CREATE TABLE `fa` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` char(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec) mysql> SHOW CREATE TABLE ss;
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ss | CREATE TABLE `ss` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` char(10) NOT NULL,
`cid` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `cid` (`cid`),
CONSTRAINT `ss_ibfk_1` FOREIGN KEY (`cid`) REFERENCES `fa` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.05 sec)
mysql> SHOW INDEXES FROM fa\G;
*************************** 1. row ***************************
Table: fa
Non_unique: 0
Key_name: PRIMARY
Seq_in_index: 1
Column_name: id
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
1 row in set (0.00 sec) ERROR:
No query specified mysql> SHOW INDEXES FROM ss \G
*************************** 1. row ***************************
Table: ss
Non_unique: 0
Key_name: PRIMARY
Seq_in_index: 1
Column_name: id
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
*************************** 2. row ***************************
Table: ss
Non_unique: 1
Key_name: cid
Seq_in_index: 1
Column_name: cid
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
2 rows in set (0.00 sec) mysql> SHOW TABLES;
+---------------+
| Tables_in_mon |
+---------------+
| fa |
| father |
| nu |
| numm |
| nummm |
| qqq |
| son |
| ss |
| tp3 |
| tp4 |
| tp5 |
| tp6 |
+---------------+
12 rows in set (0.00 sec) mysql> DESC fa;
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | char(10) | NO | | NULL | |
+-------+------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec) mysql> INSERT INTO fa VALUES('A');
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> INSERT INTO fa(name) VALUES('A');
Query OK, 1 row affected (0.06 sec) mysql> INSERT INTO fa(name) VALUES('B');
Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO fa(name) VALUES('C');
Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO fa(name) VALUES('C');
Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO fa(name) VALUES('D');
Query OK, 1 row affected (0.00 sec) mysql> SELECT * FROM fa;
+----+------+
| id | name |
+----+------+
| 1 | A |
| 2 | B |
| 3 | C |
| 4 | C |
| 5 | D |
+----+------+
5 rows in set (0.00 sec) mysql> DESC ss;
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | char(10) | NO | | NULL | |
| cid | int(10) unsigned | YES | MUL | NULL | |
+-------+------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec) mysql> INSERT INTO ss(name,cid) VALUES('LLL',1);
Query OK, 1 row affected (0.05 sec) mysql> INSERT INTO ss(name,cid) VALUES('LLL',6);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`mon`.`ss`, CONSTRAINT `ss_ibfk_1` FOREIGN KEY (`cid`) REFERENCES `fa` (`id`))
mysql> INSERT INTO ss(name,cid) VALUES('LLL',2);
Query OK, 1 row affected (0.04 sec) mysql> INSERT INTO ss(name,cid) VALUES('LLL',3);
Query OK, 1 row affected (0.00 sec) mysql> SELECT * FROM ss;
+----+------+------+
| id | name | cid |
+----+------+------+
| 1 | LLL | 1 |
| 3 | LLL | 2 |
| 4 | LLL | 3 |
+----+------+------+
3 rows in set (0.00 sec)
mysql> CREATE TABLE ALT( id INT , username CHAR(10));
Query OK, 0 rows affected (0.11 sec) mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| username | char(10) | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
2 rows in set (0.00 sec) mysql> ALTER TABLE ALT ADD sex CHAR(10) NOT NULL DEFAULT '0';
Query OK, 0 rows affected (0.28 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| username | char(10) | YES | | NULL | |
| sex | char(10) | NO | | 0 | |
+----------+----------+------+-----+---------+-------+
3 rows in set (0.00 sec) mysql> ALTER TABLE ALT ADD pid INT FIRST;
Query OK, 0 rows affected (0.12 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| pid | int(11) | YES | | NULL | |
| id | int(11) | YES | | NULL | |
| username | char(10) | YES | | NULL | |
| sex | char(10) | NO | | 0 | |
+----------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec) mysql> ALTER TABLE ALT price INT NOT NULL AFTER id;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MyQL server version for the right syntax to use near 'price INT NOT NULL AFTER id' at line 1
mysql> ALTER TABLE ALT ADD price INT NOT NULL AFTER id;
Query OK, 0 rows affected (0.11 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| pid | int(11) | YES | | NULL | |
| id | int(11) | YES | | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | | NULL | |
| sex | char(10) | NO | | 0 | |
+----------+----------+------+-----+---------+-------+
5 rows in set (0.00 sec) mysql> ALTER TABLE ALT ADD(xing CHAR(10),age INT);
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| pid | int(11) | YES | | NULL | |
| id | int(11) | YES | | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | | NULL | |
| sex | char(10) | NO | | 0 | |
| xing | char(10) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
7 rows in set (0.00 sec) mysql> ALTER TABLE ALT DROP age;
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| pid | int(11) | YES | | NULL | |
| id | int(11) | YES | | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | | NULL | |
| sex | char(10) | NO | | 0 | |
| xing | char(10) | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
6 rows in set (0.00 sec) mysql> ALTER TABLE ALT DROP xing,sex;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MyQL server version for the right syntax to use near 'sex' at line 1
mysql> ALTER TABLE ALT DROP xing,DROP sex;
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| pid | int(11) | YES | | NULL | |
| id | int(11) | YES | | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec) mysql> ALTER TABLE ALT ADD PRIMARY id;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MyQL server version for the right syntax to use near 'id' at line 1
mysql> ALTER TABLE ALT ADD PRIMARY (id);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MyQL server version for the right syntax to use near '(id)' at line 1
mysql> ALTER TABLE ALT ADD PRIMARY KEY (id);
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| pid | int(11) | YES | | NULL | |
| id | int(11) | NO | PRI | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec) mysql> ALTER TABLE ALT ADD UNIQUE(pid,price);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| pid | int(11) | YES | MUL | NULL | |
| id | int(11) | NO | PRI | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec) mysql> ALTER TABLE ALT ADD UNIQUE(pid);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> ALTER TABLE ALT ADD UNIQUE(pid);
Query OK, 0 rows affected, 1 warning (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 1 mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| pid | int(11) | YES | UNI | NULL | |
| id | int(11) | NO | PRI | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec) mysql> ALTER TABLE ALT ADD UNIQUE(pid,price);
Query OK, 0 rows affected, 1 warning (0.11 sec)
Records: 0 Duplicates: 0 Warnings: 1 mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| pid | int(11) | YES | UNI | NULL | |
| id | int(11) | NO | PRI | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec) mysql> ALTER TABLE ALT ADD UNIQUE(usename,price);
ERROR 1072 (42000): Key column 'usename' doesn't exist in table
mysql> ALTER TABLE ALT ADD UNIQUE(username,price);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| pid | int(11) | YES | UNI | NULL | |
| id | int(11) | NO | PRI | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | MUL | NULL | |
+----------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> ALTER TABLE ALT ADD UNIQUE(username,price);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| pid | int(11) | YES | UNI | NULL | |
| id | int(11) | NO | PRI | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | MUL | NULL | |
+----------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec)

两项加在一起作为唯一索引

mysql> ALTER TABLE ALT ADD price INT NOT NULL AFTER id;
Query OK, 0 rows affected (0.11 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| pid | int(11) | YES | | NULL | |
| id | int(11) | YES | | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | | NULL | |
| sex | char(10) | NO | | 0 | |
+----------+----------+------+-----+---------+-------+
5 rows in set (0.00 sec) mysql> ALTER TABLE ALT ADD(xing CHAR(10),age INT);
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| pid | int(11) | YES | | NULL | |
| id | int(11) | YES | | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | | NULL | |
| sex | char(10) | NO | | 0 | |
| xing | char(10) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
7 rows in set (0.00 sec) mysql> ALTER TABLE ALT DROP age;
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| pid | int(11) | YES | | NULL | |
| id | int(11) | YES | | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | | NULL | |
| sex | char(10) | NO | | 0 | |
| xing | char(10) | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
6 rows in set (0.00 sec) mysql> ALTER TABLE ALT DROP xing,sex;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MyQL server version for the right syntax to use near 'sex' at line 1
mysql> ALTER TABLE ALT DROP xing,DROP sex;
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| pid | int(11) | YES | | NULL | |
| id | int(11) | YES | | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec) mysql> ALTER TABLE ALT ADD PRIMARY id;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MyQL server version for the right syntax to use near 'id' at line 1
mysql> ALTER TABLE ALT ADD PRIMARY (id);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MyQL server version for the right syntax to use near '(id)' at line 1
mysql> ALTER TABLE ALT ADD PRIMARY KEY (id);
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| pid | int(11) | YES | | NULL | |
| id | int(11) | NO | PRI | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec) mysql> ALTER TABLE ALT ADD UNIQUE(pid,price);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| pid | int(11) | YES | MUL | NULL | |
| id | int(11) | NO | PRI | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec) mysql> ALTER TABLE ALT ADD UNIQUE(pid);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> ALTER TABLE ALT ADD UNIQUE(pid);
Query OK, 0 rows affected, 1 warning (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 1 mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| pid | int(11) | YES | UNI | NULL | |
| id | int(11) | NO | PRI | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec) mysql> ALTER TABLE ALT ADD UNIQUE(pid,price);
Query OK, 0 rows affected, 1 warning (0.11 sec)
Records: 0 Duplicates: 0 Warnings: 1 mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| pid | int(11) | YES | UNI | NULL | |
| id | int(11) | NO | PRI | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec) mysql> ALTER TABLE ALT ADD UNIQUE(usename,price);
ERROR 1072 (42000): Key column 'usename' doesn't exist in table
mysql> ALTER TABLE ALT ADD UNIQUE(username,price);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| pid | int(11) | YES | UNI | NULL | |
| id | int(11) | NO | PRI | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | MUL | NULL | |
+----------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec) mysql> ALTER TABLE ALT ADD age TINYINT UNSIGNED NOT NULL DEFAULT 0;
Query OK, 0 rows affected (0.21 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+----------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------------+------+-----+---------+-------+
| pid | int(11) | YES | UNI | NULL | |
| id | int(11) | NO | PRI | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | MUL | NULL | |
| age | tinyint(3) unsigned | NO | | 0 | |
+----------+---------------------+------+-----+---------+-------+
5 rows in set (0.13 sec) mysql> ALTER TABLE ALT ALTER age SET DEFAULT 15;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+----------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------------+------+-----+---------+-------+
| pid | int(11) | YES | UNI | NULL | |
| id | int(11) | NO | PRI | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | MUL | NULL | |
| age | tinyint(3) unsigned | NO | | 15 | |
+----------+---------------------+------+-----+---------+-------+
5 rows in set (0.00 sec) mysql> ALTER TABLE ALT ALTER DROP DEFAULT;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DROP DEFAULT' at line 1
mysql> ALTER TABLE ALT ALTER age DROP DEFAULT;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+----------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------------+------+-----+---------+-------+
| pid | int(11) | YES | UNI | NULL | |
| id | int(11) | NO | PRI | NULL | |
| price | int(11) | NO | | NULL | |
| username | char(10) | YES | MUL | NULL | |
| age | tinyint(3) unsigned | NO | | NULL | |
+----------+---------------------+------+-----+---------+-------+
5 rows in set (0.00 sec) mysql> SHOW CTEATE TABLE ALT;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CTEATE TABLE ALT' at line 1
mysql> SHOW CREATE TABLE ALT;
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ALT | CREATE TABLE `ALT` (
`pid` int(11) DEFAULT NULL,
`id` int(11) NOT NULL,
`price` int(11) NOT NULL,
`username` char(10) DEFAULT NULL,
`age` tinyint(3) unsigned NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `pid` (`pid`,`price`),
UNIQUE KEY `pid_2` (`pid`),
UNIQUE KEY `pid_3` (`pid`),
UNIQUE KEY `pid_4` (`pid`,`price`),
UNIQUE KEY `username` (`username`,`price`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec) mysql> ALTER TABLE ALT DROP PRIMARY KEY;
Query OK, 0 rows affected (0.19 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> SHOW CREATE TABLE ALT;
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ALT | CREATE TABLE `ALT` (
`pid` int(11) DEFAULT NULL,
`id` int(11) NOT NULL,
`price` int(11) NOT NULL,
`username` char(10) DEFAULT NULL,
`age` tinyint(3) unsigned NOT NULL,
UNIQUE KEY `pid` (`pid`,`price`),
UNIQUE KEY `pid_2` (`pid`),
UNIQUE KEY `pid_3` (`pid`),
UNIQUE KEY `pid_4` (`pid`,`price`),
UNIQUE KEY `username` (`username`,`price`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec) mysql> SHOW INDEXES FROM ALT\G
*************************** 1. row ***************************
Table: ALT
Non_unique: 0
Key_name: pid
Seq_in_index: 1
Column_name: pid
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 2. row ***************************
Table: ALT
Non_unique: 0
Key_name: pid
Seq_in_index: 2
Column_name: price
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
*************************** 3. row ***************************
Table: ALT
Non_unique: 0
Key_name: pid_2
Seq_in_index: 1
Column_name: pid
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 4. row ***************************
Table: ALT
Non_unique: 0
Key_name: pid_3
Seq_in_index: 1
Column_name: pid
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 5. row ***************************
Table: ALT
Non_unique: 0
Key_name: pid_4
Seq_in_index: 1
Column_name: pid
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 6. row ***************************
Table: ALT
Non_unique: 0
Key_name: pid_4
Seq_in_index: 2
Column_name: price
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
*************************** 7. row ***************************
Table: ALT
Non_unique: 0
Key_name: username
Seq_in_index: 1
Column_name: username
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 8. row ***************************
Table: ALT
Non_unique: 0
Key_name: username
Seq_in_index: 2
Column_name: price
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
8 rows in set (0.09 sec) mysql> ALTER TABLE ALT DROP username;
Query OK, 0 rows affected (0.18 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> SHOW INDEXES FROM ALT\G
*************************** 1. row ***************************
Table: ALT
Non_unique: 0
Key_name: username
Seq_in_index: 1
Column_name: price
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
*************************** 2. row ***************************
Table: ALT
Non_unique: 0
Key_name: pid
Seq_in_index: 1
Column_name: pid
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 3. row ***************************
Table: ALT
Non_unique: 0
Key_name: pid
Seq_in_index: 2
Column_name: price
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
*************************** 4. row ***************************
Table: ALT
Non_unique: 0
Key_name: pid_2
Seq_in_index: 1
Column_name: pid
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 5. row ***************************
Table: ALT
Non_unique: 0
Key_name: pid_3
Seq_in_index: 1
Column_name: pid
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 6. row ***************************
Table: ALT
Non_unique: 0
Key_name: pid_4
Seq_in_index: 1
Column_name: pid
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 7. row ***************************
Table: ALT
Non_unique: 0
Key_name: pid_4
Seq_in_index: 2
Column_name: price
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
7 rows in set (0.00 sec) mysql> SHOW CREATE TABLE ALT;
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ALT | CREATE TABLE `ALT` (
`pid` int(11) DEFAULT NULL,
`id` int(11) NOT NULL,
`price` int(11) NOT NULL,
`age` tinyint(3) unsigned NOT NULL,
UNIQUE KEY `username` (`price`),
UNIQUE KEY `pid` (`pid`,`price`),
UNIQUE KEY `pid_2` (`pid`),
UNIQUE KEY `pid_3` (`pid`),
UNIQUE KEY `pid_4` (`pid`,`price`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> DESC ALT;
+-------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------------+------+-----+---------+-------+
| pid | int(11) | YES | UNI | NULL | |
| id | int(11) | NO | | NULL | |
| price | int(11) | NO | PRI | NULL | |
| age | tinyint(3) unsigned | NO | | NULL | |
+-------+---------------------+------+-----+---------+-------+
4 rows in set (0.00 sec) mysql> ALTER TABLE ALT MODIFY id int(11) NOT NULL DEFAULT 22;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+-------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------------+------+-----+---------+-------+
| pid | int(11) | YES | UNI | NULL | |
| id | int(11) | NO | | 22 | |
| price | int(11) | NO | PRI | NULL | |
| age | tinyint(3) unsigned | NO | | NULL | |
+-------+---------------------+------+-----+---------+-------+
4 rows in set (0.00 sec) mysql> ALTER TABLE ALT MODIFY age FIRST;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FIRST' at line 1
mysql> ALTER TABLE ALT MODIFY age TINYINT(3) UNSIGNED NOT NULL FIRST;
Query OK, 0 rows affected (1.24 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+-------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------------+------+-----+---------+-------+
| age | tinyint(3) unsigned | NO | | NULL | |
| pid | int(11) | YES | UNI | NULL | |
| id | int(11) | NO | | 22 | |
| price | int(11) | NO | PRI | NULL | |
+-------+---------------------+------+-----+---------+-------+
4 rows in set (0.00 sec) mysql> ALTER TABLE ALT CHANGE price prices;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
mysql> ALTER TABLE ALT CHANGE price prices INT NOT NULL PRIMARY KEY;
Query OK, 0 rows affected (0.28 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> DESC ALT;
+--------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+---------------------+------+-----+---------+-------+
| age | tinyint(3) unsigned | NO | | NULL | |
| pid | int(11) | YES | UNI | NULL | |
| id | int(11) | NO | | 22 | |
| prices | int(11) | NO | PRI | NULL | |
+--------+---------------------+------+-----+---------+-------+
4 rows in set (0.00 sec) mysql> ALTER TABLE ALT RENAME alt;
Query OK, 0 rows affected (0.22 sec) mysql> show tables;
+---------------+
| Tables_in_mon |
+---------------+
| alt |
| fa |
| father |
| nu |
| numm |
| nummm |
| qqq |
| son |
| ss |
| tp3 |
| tp4 |
| tp5 |
| tp6 |
+---------------+
13 rows in set (0.00 sec) mysql> DESC alt;
+--------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+---------------------+------+-----+---------+-------+
| age | tinyint(3) unsigned | NO | | NULL | |
| pid | int(11) | YES | UNI | NULL | |
| id | int(11) | NO | | 22 | |
| prices | int(11) | NO | PRI | NULL | |
+--------+---------------------+------+-----+---------+-------+
4 rows in set (0.00 sec) mysql> RANAME TABLE alt TO ALT;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'RANAME TABLE alt TO ALT' at line 1
mysql> RENAME TABLE alt TO ALT;
Query OK, 0 rows affected (0.00 sec) mysql> show tables;
+---------------+
| Tables_in_mon |
+---------------+
| ALT |
| fa |
| father |
| nu |
| numm |
| nummm |
| qqq |
| son |
| ss |
| tp3 |
| tp4 |
| tp5 |
| tp6 |
+---------------+
13 rows in set (0.00 sec)

用户表;

  用户id  INT

  用户名  VARCHAR(20)

  密码  CHAR(32)

  性别   sex TINYINT DEFAULT 0

  年龄  age TINYINT DEFAULT 0

  学历 education TINYINT 1 2 3 4 5

  所在班级 class VARCHAR(10) NOT NULL

  省份 province VARCHAR(10) NOT NULL

  

mysql> CREATE TABLE user(
-> id INT AUTO_INCREMENT PRIMARY KEY,
-> username VARCHAR(20) NOT NULL ,
-> pwd CHAR(32) NOT NULL,
-> sex TINYINT DEFAULT 0,
-> age TINYINT DEFAULT 18,
-> edu TINYINT DEFAULT 2 NOT NULL,
-> classname VARCHAR(10) NOT NULL,
-> province VARCHAR(10) NOT NULL);

mysql> SHOW TABLES;
+---------------+
| Tables_in_mon |
+---------------+
| ALT |
| fa |
| father |
| nu |
| numm |
| nummm |
| qqq |
| son |
| ss |
| tp3 |
| tp4 |
| tp5 |
| tp6 |
+---------------+
13 rows in set (0.00 sec) mysql> CREATE TABLE user(
-> id INT AUTO_INCREMENT PRIMARY KEY,
-> username VARCHAR(20) NOT NULL ,
-> pwd CHAR(32) NOT NULL,
-> sex TINYINT DEFAULT 0,
-> age TINYINT DEFAULT 18,
-> edu TINYINT DEFAULT 2 NOT NULL,
-> classname VARCHAR(10) NOT NULL,
-> province VARCHAR(10) NOT NULL);
Query OK, 0 rows affected (0.13 sec) mysql> INSERT INTO user (username ,pwd,classname ,province) VALUES('小强',md5(123),'jave','内蒙古') ;
-> '
'> ‘
'> ^C
mysql> INSERT INTO user (username ,pwd,classname ,province) VALUES('小强',md5(123),'jave','内蒙古');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ',md5(123),'jave','内蒙古')' at line 1
mysql> INSERT INTO user (username ,pwd,classname ,province) VALUES('小强','md5(123)','jave','内蒙古');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ','md5(123)','jave','内蒙古')' at line 1
mysql> INSERT INTO user (username ,pwd,classname ,province) VALUES('小强',md5(123),'jave','内蒙古');
Query OK, 1 row affected (0.11 sec) mysql> SELECT * FROM user;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 18 | 2 | jave | 内蒙古 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
1 row in set (0.00 sec) mysql> INSERT INTO user (username ,pwd,classname ,province) VALUES('小Q',md5(123),'jŠŠ罆罆 ^C
mysql> INSERT INTO user (username ,pwd,classname ,province) VALUES('小强',md5(123),'jave','内蒙古');INSERT INTO user (username ,pwd,classname ,province) VALUES('小强',md5(123),'jave','内蒙古')
[1]+ Stopped mysql -u root -p
[root@mysql.bktwo.quan.bbs ~]$mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 134
Server version: 5.7.29-log Source distribution Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use qqq
ERROR 1049 (42000): Unknown database 'qqq'
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| m1 |
| mon |
| mysql |
| performance_schema |
| quan; |
| quanbbs |
| quantest |
| quantesttwo |
| sys |
+--------------------+
10 rows in set (0.01 sec) mysql> use mon
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> INSERT INTO user (username ,pwd,classname ,province) VALUES('小xx',md5(123),'jave','内蒙古'),('小jj',md5(1234),'javed','湛江');
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0 mysql> SELECT * FROM user;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 18 | 2 | jave | 内蒙古 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 18 | 2 | jave | 内蒙古 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 18 | 2 | javed | 湛江 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
3 rows in set (0.00 sec) mysql> INSERT INTO user VARLUES(default,'小米',md5(1245),1,79,3,'py','背景');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VARLUES(default,'小米',md5(1245),1,79,3,'py','背景')' at line 1
mysql> INSERT INTO user VALUES(default,'小米',md5(1245),1,66,3,'py','背景');
Query OK, 1 row affected (0.00 sec) mysql> SELECT * FROM user;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 18 | 2 | jave | 内蒙古 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 18 | 2 | jave | 内蒙古 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 18 | 2 | javed | 湛江 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 1 | 66 | 3 | py | 背景 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
4 rows in set (0.00 sec) mysql> INSERT INTO user VALUES(default,'小米',md5(1245),1,66,3,'py','背景'),(default,'小xiao',md5(12fe45),1,99,3,'py','福门');
ERROR 1054 (42S22): Unknown column '12fe45' in 'field list'
mysql> INSERT INTO user VALUES(default,'小米',md5(1245),1,66,3,'py','背景'),(default,'小xiao',md5(123245),1,99,3,'py','福门');
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0 mysql> SELECT * FROM user;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 18 | 2 | jave | 内蒙古 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 18 | 2 | jave | 内蒙古 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 18 | 2 | javed | 湛江 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 1 | 66 | 3 | py | 背景 |
| 5 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 1 | 66 | 3 | py | 背景 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 1 | 99 | 3 | py | 福门 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
6 rows in set (0.00 sec) mysql> INSERT INTO user SET username='root',pwd=md5(3453),classname='dada',province='天津';
-> ^C
mysql> INSERT INTO user SET username='root',pwd=md5(3453),classname='dada',province='天津';
Query OK, 1 row affected (0.00 sec) mysql> SELECT * FROM user;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 18 | 2 | jave | 内蒙古 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 18 | 2 | jave | 内蒙古 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 18 | 2 | javed | 湛江 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 1 | 66 | 3 | py | 背景 |
| 5 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 1 | 66 | 3 | py | 背景 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 1 | 99 | 3 | py | 福门 |
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 18 | 2 | dada | 天津 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
7 rows in set (0.00 sec)
mysql> SELECT * FROM user;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 18 | 2 | jave | 内蒙古 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 18 | 2 | jave | 内蒙古 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 18 | 2 | javed | 湛江 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 1 | 66 | 3 | py | 背景 |
| 5 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 1 | 66 | 3 | py | 背景 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 1 | 99 | 3 | py | 福门 |
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 18 | 2 | dada | 天津 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
7 rows in set (0.00 sec) mysql> UPDATE user SET age + 5;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '+ 5' at line 1
mysql> UPDATE user SET age = age + 5;
Query OK, 7 rows affected (0.09 sec)
Rows matched: 7 Changed: 7 Warnings: 0 mysql> SELECT * FROM user;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 23 | 2 | jave | 内蒙古 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 23 | 2 | jave | 内蒙古 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 23 | 2 | javed | 湛江 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 1 | 71 | 3 | py | 背景 |
| 5 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 1 | 71 | 3 | py | 背景 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 1 | 104 | 3 | py | 福门 |
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 23 | 2 | dada | 天津 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
7 rows in set (0.00 sec) mysql> UPDATE user SET age = age + 2 ,sex = 0;
Query OK, 7 rows affected (0.01 sec)
Rows matched: 7 Changed: 7 Warnings: 0 mysql> SELECT * FROM user;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | jave | 内蒙古 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | jave | 内蒙古 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | javed | 湛江 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 73 | 3 | py | 背景 |
| 5 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 73 | 3 | py | 背景 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 106 | 3 | py | 福门 |
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | dada | 天津 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
7 rows in set (0.00 sec) mysql> UPDATE user SET age = age + 10 WHRER id%2 =0;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHRER id%2 =0' at line 1
mysql> UPDATE user SET age = age + 10 WHRER id%2 ==0;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHRER id%2 ==0' at line 1
mysql> UPDATE user SET age = age + 10 WHERE id%2 ==0;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '==0' at line 1
mysql> UPDATE user SET age = age + 10 WHERE id%2 =0;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0 mysql> SELECT * FROM user;
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| id | username | pwd | sex | age | edu | classname | province |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
| 1 | 小强 | 202cb962ac59075b964b07152d234b70 | 0 | 25 | 2 | jave | 内蒙古 |
| 2 | 小xx | 202cb962ac59075b964b07152d234b70 | 0 | 35 | 2 | jave | 内蒙古 |
| 3 | 小jj | 81dc9bdb52d04dc20036dbd8313ed055 | 0 | 25 | 2 | javed | 湛江 |
| 4 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 83 | 3 | py | 背景 |
| 5 | 小米 | 5eac43aceba42c8757b54003a58277b5 | 0 | 73 | 3 | py | 背景 |
| 6 | 小xiao | 09a6f4ead95fb05ee29ab9e7d1219e33 | 0 | 116 | 3 | py | 福门 |
| 7 | root | f356355c1634839cf42769e7f30905a3 | 0 | 25 | 2 | dada | 天津 |
+----+----------+----------------------------------+------+------+-----+-----------+-----------+
7 rows in set (0.00 sec)

mingling的更多相关文章

  1. linux mingling

    grep 文本搜索工具 -i 忽略大小写 -v 不显示匹配行 -c 显示符合条件的行数值 文本搜索支持正则表达式 1 2 3 cat /etc/passwd | grep root // 显示包含ro ...

  2. vim总结

    1.vim基础用法 注:该思维导图来自笔者<Linux就该这么学>读书笔记. 移动光标: 命令 描述 k 向上移动光标(移动一行) j 向下移动光标(移动一行) h 向左移动光标(移动一个 ...

  3. 20款优秀的国外 Mobile App 界面设计案例

    在下面给大家分享的移动应用程序界面设计作品中,你可以看到不同创意类型的视觉效果.如果你想获得灵感,那很有必要看看下面20个优秀用户体验的移动应用 UI 设计.想要获取更多的灵感,可以访问移动开发分类, ...

  4. 关于Windows常用命令

    本文引用自:http://ylbook.com/cms/computer/mingling.htm Windows Run命令: calc———–启动计算器certmgr.msc—-证书管理实用程序c ...

  5. WPF——执行命令清空文本框

    一.造一个窗体,在窗体里面先造一个StackPanel,然后再StackPanel里面放好按钮和文本框,注意给所有的控件和容器起名字 <Grid> <StackPanel Name= ...

  6. JavaScript设计模式之命令模式

    一.命令模式概念 命令模式(Command)的定义是:用来对方法调用进行参数化处理和传送,经过这样处理过的方法调用可以在任何需要的时候执行.也就是说该模式旨在将函数的调用.请求和操作封装成一个单一的对 ...

  7. shell脚本结构

    echo $? 代表上一次命令的状态返回值,‘0’则代表为真<执行成功>,‘非零’则代表为假<执行失败>. shell脚本: <判断老男孩的年纪> [root@bo ...

  8. shell及编程实例

    1.shell简介 1) 概念--命令解释器 2) 常见shell bash linux标准shell sh 早期shell,较简单 csh ksh tcsh unix  shell vi  /etc ...

  9. ubuntu下smokeping安装配置

    0.参考文件 http://wenku.baidu.com/view/950fbb0a79563c1ec5da71b1 http://aaaxiang000.blog.163.com/blog/sta ...

随机推荐

  1. DDD领域驱动设计-概述-Ⅰ

     如果我看得更远,那是因为我站在巨人的肩膀上.(If I have seen further it is by standing on ye shoulder of Giants.)         ...

  2. BUAA软件工程个人博客作业

    软件工程个人博客作业 项目 内容 这个作业属于哪个课程 2020春季计算机学院软件工程(罗杰 任健) 这个作业的要求在哪里 个人博客作业 我在这个课程的目标 团队完成好的软件,并对自己作出规划 这个作 ...

  3. Spring Authorization Server的使用

    Spring Authorization Server的使用 一.背景 二.前置知识 三.需求 四.核心代码编写 1.引入授权服务器依赖 2.创建授权服务器用户 3.创建授权服务器和客户端 五.测试 ...

  4. webpack基础以及webpack中babel的配置

    webpack 安装 npm 初始化,控制台输入 npm init -y webpack 安装 npm i webpack webpack-cli -D 新建 webpack.config.js co ...

  5. 2021.10.12考试总结[NOIP模拟75]

    T1 如何优雅的送分 考虑式子的实际意义.\(2^{f_n}\)实际上就是枚举\(n\)质因子的子集.令\(k\)为这个子集中数的乘积,就可以将式子转化为枚举\(k\),计算\(k\)的贡献. 不难得 ...

  6. Unity——射线系统

    Unity射线系统 Demo展示 UI+Physical射线测试: FPS自定义射线测试: UGUI射线工具 实现功能,鼠标点击UI,返回鼠标点击的UI对象: 需要使用到鼠标点击事件-PointerE ...

  7. Python gpu 显卡小工具 gpu

    安装 pip install gpustat 或者 换源 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade gpust ...

  8. 第07课 OpenGL 光照和键盘(1)

    光照和键盘控制: 在这一课里,我们将添加光照和键盘控制,它让程序看起来更美观. 这一课我会教您如何使用三种不同的纹理滤波方式.教您如何使用键盘来移动场景中的对象,还会教您在OpenGL场景中应用简单的 ...

  9. SpringBoot整合reids之JSON序列化文件夹操作

    前言 最近在开发项目,用到了redis作为缓存,来提高系统访问速度和缓解系统压力,提高用户响应和访问速度,这里遇到几个问题做一下总结和整理 快速配置 SpringBoot整合redis有专门的场景启动 ...

  10. 【完美解决】IDEA 中 Maven 报错 Cannot resolve xxx 和 Maven 中 Dependencies 报红/报错。

    目录 前提 场景 解决办法 1.首先,清除缓存,点击之后重启IDEA. 2.关闭IDEA,打开项目文件夹 3.重新打开 IDEA,找到右边的 Maven 4.解决 Maven 中 Dependenci ...