mingling
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的更多相关文章
- linux mingling
grep 文本搜索工具 -i 忽略大小写 -v 不显示匹配行 -c 显示符合条件的行数值 文本搜索支持正则表达式 1 2 3 cat /etc/passwd | grep root // 显示包含ro ...
- vim总结
1.vim基础用法 注:该思维导图来自笔者<Linux就该这么学>读书笔记. 移动光标: 命令 描述 k 向上移动光标(移动一行) j 向下移动光标(移动一行) h 向左移动光标(移动一个 ...
- 20款优秀的国外 Mobile App 界面设计案例
在下面给大家分享的移动应用程序界面设计作品中,你可以看到不同创意类型的视觉效果.如果你想获得灵感,那很有必要看看下面20个优秀用户体验的移动应用 UI 设计.想要获取更多的灵感,可以访问移动开发分类, ...
- 关于Windows常用命令
本文引用自:http://ylbook.com/cms/computer/mingling.htm Windows Run命令: calc———–启动计算器certmgr.msc—-证书管理实用程序c ...
- WPF——执行命令清空文本框
一.造一个窗体,在窗体里面先造一个StackPanel,然后再StackPanel里面放好按钮和文本框,注意给所有的控件和容器起名字 <Grid> <StackPanel Name= ...
- JavaScript设计模式之命令模式
一.命令模式概念 命令模式(Command)的定义是:用来对方法调用进行参数化处理和传送,经过这样处理过的方法调用可以在任何需要的时候执行.也就是说该模式旨在将函数的调用.请求和操作封装成一个单一的对 ...
- shell脚本结构
echo $? 代表上一次命令的状态返回值,‘0’则代表为真<执行成功>,‘非零’则代表为假<执行失败>. shell脚本: <判断老男孩的年纪> [root@bo ...
- shell及编程实例
1.shell简介 1) 概念--命令解释器 2) 常见shell bash linux标准shell sh 早期shell,较简单 csh ksh tcsh unix shell vi /etc ...
- ubuntu下smokeping安装配置
0.参考文件 http://wenku.baidu.com/view/950fbb0a79563c1ec5da71b1 http://aaaxiang000.blog.163.com/blog/sta ...
随机推荐
- 第1次 Beta Scrum Meeting
本次会议为Beta阶段第1次Scrum Meeting会议 会议概要 会议时间:2021年5月29日 会议地点:「腾讯会议」线上进行 会议时长:0.5小时 会议内容简介:本次会议为Beta阶段第1次会 ...
- Go语言核心36讲(Go语言进阶技术八)--学习笔记
14 | 接口类型的合理运用 前导内容:正确使用接口的基础知识 在 Go 语言的语境中,当我们在谈论"接口"的时候,一定指的是接口类型.因为接口类型与其他数据类型不同,它是没法被实 ...
- 最后的OI(HAOI2020游记)
马上就省选了,怎么不得写点什么?要不然到最后或许就真的落得个白茫茫大地真干净的局面. 其实也不知道该说啥?我这一路走来,感觉挺赚的. 每一个OIer背后都有一个故事,所以,我有故事,你有酒吗? 依稀记 ...
- heihei
adb shell screencap -p /sdcard/p1.pngadb pull /sdcard/p1.png c:\BaiduYunDownloadadb shell rm /sdcard ...
- Cnetos 8 DNS解析慢
参考链接:https://blog.csdn.net/u014401141/article/details/105869242/ 修改 /etc/resolv.conf配置文件,最上方加入 optio ...
- ZooKeeper 集群搭建 Error contacting service. It is probably not running.
搭建环境:Centos 7 虚拟机 3台 按照此教程搭建:https://www.ilanni.com/?p=11393 之后出现错误:Error contacting service. It is ...
- c++ IO库
1:为了支持使用宽字符的语言,标准库定义了一组类型和对象来操作wchar_t类型的数据.宽字符版本的类型和函数的名字以w开头.宽字符版本和普通的char版本定义在同一个头文件中,例如头文件fstrea ...
- KMP算法,看这篇就够了!
普通的模式匹配算法(BF算法) 子串的定位操作通常称为模式匹配算法 假设有一个需求,需要我们从串"a b a b c a b c a c b a b"中,寻找内容为"a ...
- [第二章]c++学习笔记2(类和对象的基础3)
隐藏的概念 隐藏的作用 使用例 成员函数的重载与缺省(附使用例) 注意事项
- NFS导致df -h卡主解决
NFS导致df -h无法使用解决 NFS服务意外断开,导致挂载的客户端"df -Th"命令无法使用,及挂载目录无法"cd""ls"解决思路: ...