当前位置: 首页 >数据库 > mingling

mingling

mysql> USE monReading table information for completion of table and column namesYou can tu off this feature to get a quicker startup with -ADatabase changedmysql> SHOW TABLES;+---------------+| Tables_in_mon |+---------------+| qqq|+---------------+1 row in set (0.00 sec)mysql> DESC qqq;+----------+--------------------+------+-----+---------+-------+| Field| Type| Null | Key | Default | Extra |+----------+--------------------+------+-----+---------+-------+| useame | 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 |+----------+--------------------+------+-----+---------+-------+| useame | 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 (useame,munber,money,sex) VALUES('quanzhiqia',23,1351.41,'n');Query OK, 1 row affected (0.07 sec)mysql> INSERT INTO qqq (useame,munber,money,sex) VALUES('quanzhiqia',23,1351.41121,'n');Query OK, 1 row affected, 1 waing (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;+------------+--------+---------+------+---------+| useame| 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 |+----------+--------------------+------+-----+---------+-------+| useame | 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 valuemysql> 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(-> useame 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 |+----------+----------+------+-----+---------+-------+| useame | 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;+----------+------+| useame | 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 valuemysql> 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, useame CHAR(10) NOT NULL UNIQUE KEY, tel CQuery 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 || useame | 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 1mysql> INSERT INTO tp6 VALUES( 'null','quan','15219588659',1);ERROR 1366 (HY000): Incorrect integer value: 'null' for column 'id' at row 1mysql> INSERT INTO tp6 VALUES( null,'quan','15219588659',1);Query OK, 1 row affected (0.00 sec)mysql> SELECT * FROM tp6;+----+----------+-------------+-----+| id | useame | 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 'useame'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 | useame | tel | sex |+----+----------+-------------+-----+|  1 | quan | 15219588659 |1 ||  4 | quan1| 15219588658 |0 |+----+----------+-------------+-----+2 rows in set (0.00 sec)mysql> INSERT INTO tp6 (useame,tel) VALUES('quan2','13145710069');Query OK, 1 row affected (0.00 sec)mysql> SELECT * FROM tp6;+----+----------+-------------+-----+| id | useame | 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: faNon_unique: 0 Key_name: PRIMARY Seq_in_index: 1  Column_name: idCollation: A  Cardinality: 0 Sub_part: NULLPacked: NULL Null:Index_type: BTREE  Comment: Index_comment: 1 row in set (0.00 sec)ERROR: No query specifiedmysql> SHOW INDEXES FROM ss \G*************************** 1. row ***************************Table: ssNon_unique: 0 Key_name: PRIMARY Seq_in_index: 1  Column_name: idCollation: A  Cardinality: 0 Sub_part: NULLPacked: NULL Null:Index_type: BTREE  Comment: Index_comment: *************************** 2. row ***************************Table: ssNon_unique: 1 Key_name: cid Seq_in_index: 1  Column_name: cidCollation: A  Cardinality: 0 Sub_part: NULLPacked: NULL Null: YESIndex_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 1mysql> 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 , useame CHAR(10));Query OK, 0 rows affected (0.11 sec)mysql> DESC ALT;+----------+----------+------+-----+---------+-------+| Field| Type | Null | Key | Default | Extra |+----------+----------+------+-----+---------+-------+| id| int(11)  | YES  | | NULL||| useame | 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  Waings: 0mysql> DESC ALT;+----------+----------+------+-----+---------+-------+| Field| Type | Null | Key | Default | Extra |+----------+----------+------+-----+---------+-------+| id| int(11)  | YES  | | NULL||| useame | 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  Waings: 0mysql> DESC ALT;+----------+----------+------+-----+---------+-------+| Field| Type | Null | Key | Default | Extra |+----------+----------+------+-----+---------+-------+| pid  | int(11)  | YES  | | NULL||| id| int(11)  | YES  | | NULL||| useame | 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 1mysql> ALTER TABLE ALT ADD price INT NOT NULL AFTER id;Query OK, 0 rows affected (0.11 sec)Records: 0  Duplicates: 0  Waings: 0mysql> DESC ALT;+----------+----------+------+-----+---------+-------+| Field| Type | Null | Key | Default | Extra |+----------+----------+------+-----+---------+-------+| pid  | int(11)  | YES  | | NULL||| id| int(11)  | YES  | | NULL||| price| int(11)  | NO| | NULL||| useame | 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  Waings: 0mysql> DESC ALT;+----------+----------+------+-----+---------+-------+| Field| Type | Null | Key | Default | Extra |+----------+----------+------+-----+---------+-------+| pid  | int(11)  | YES  | | NULL||| id| int(11)  | YES  | | NULL||| price| int(11)  | NO| | NULL||| useame | 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  Waings: 0mysql> DESC ALT;+----------+----------+------+-----+---------+-------+| Field| Type | Null | Key | Default | Extra |+----------+----------+------+-----+---------+-------+| pid  | int(11)  | YES  | | NULL||| id| int(11)  | YES  | | NULL||| price| int(11)  | NO| | NULL||| useame | 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 1mysql> ALTER TABLE ALT DROP xing,DROP sex;Query OK, 0 rows affected (0.02 sec)Records: 0  Duplicates: 0  Waings: 0mysql> DESC ALT;+----------+----------+------+-----+---------+-------+| Field| Type | Null | Key | Default | Extra |+----------+----------+------+-----+---------+-------+| pid  | int(11)  | YES  | | NULL||| id| int(11)  | YES  | | NULL||| price| int(11)  | NO| | NULL||| useame | 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 1mysql> 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 1mysql> ALTER TABLE ALT ADD PRIMARY KEY (id);Query OK, 0 rows affected (0.02 sec)Records: 0  Duplicates: 0  Waings: 0mysql> DESC ALT;+----------+----------+------+-----+---------+-------+| Field| Type | Null | Key | Default | Extra |+----------+----------+------+-----+---------+-------+| pid  | int(11)  | YES  | | NULL||| id| int(11)  | NO| PRI | NULL||| price| int(11)  | NO| | NULL||| useame | 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  Waings: 0mysql> 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||| useame | 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  Waings: 0mysql> ALTER TABLE ALT ADD UNIQUE(pid);Query OK, 0 rows affected, 1 waing (0.01 sec)Records: 0  Duplicates: 0  Waings: 1mysql> 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||| useame | 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 waing (0.11 sec)Records: 0  Duplicates: 0  Waings: 1mysql> 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||| useame | 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 tablemysql> ALTER TABLE ALT ADD UNIQUE(useame,price);Query OK, 0 rows affected (0.01 sec)Records: 0  Duplicates: 0  Waings: 0mysql> 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||| useame | char(10) | YES  | MUL | NULL||+----------+----------+------+-----+---------+-------+4 rows in set (0.00 sec)

 

 

 

mysql> ALTER TABLE ALT ADD UNIQUE(useame,price);Query OK, 0 rows affected (0.01 sec)Records: 0  Duplicates: 0  Waings: 0mysql> 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||| useame | 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  Waings: 0mysql> DESC ALT;+----------+----------+------+-----+---------+-------+| Field| Type | Null | Key | Default | Extra |+----------+----------+------+-----+---------+-------+| pid  | int(11)  | YES  | | NULL||| id| int(11)  | YES  | | NULL||| price| int(11)  | NO| | NULL||| useame | 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  Waings: 0mysql> DESC ALT;+----------+----------+------+-----+---------+-------+| Field| Type | Null | Key | Default | Extra |+----------+----------+------+-----+---------+-------+| pid  | int(11)  | YES  | | NULL||| id| int(11)  | YES  | | NULL||| price| int(11)  | NO| | NULL||| useame | 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  Waings: 0mysql> DESC ALT;+----------+----------+------+-----+---------+-------+| Field| Type | Null | Key | Default | Extra |+----------+----------+------+-----+---------+-------+| pid  | int(11)  | YES  | | NULL||| id| int(11)  | YES  | | NULL||| price| int(11)  | NO| | NULL||| useame | 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 1mysql> ALTER TABLE ALT DROP xing,DROP sex;Query OK, 0 rows affected (0.02 sec)Records: 0  Duplicates: 0  Waings: 0mysql> DESC ALT;+----------+----------+------+-----+---------+-------+| Field| Type | Null | Key | Default | Extra |+----------+----------+------+-----+---------+-------+| pid  | int(11)  | YES  | | NULL||| id| int(11)  | YES  | | NULL||| price| int(11)  | NO| | NULL||| useame | 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 1mysql> 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 1mysql> ALTER TABLE ALT ADD PRIMARY KEY (id);Query OK, 0 rows affected (0.02 sec)Records: 0  Duplicates: 0  Waings: 0mysql> DESC ALT;+----------+----------+------+-----+---------+-------+| Field| Type | Null | Key | Default | Extra |+----------+----------+------+-----+---------+-------+| pid  | int(11)  | YES  | | NULL||| id| int(11)  | NO| PRI | NULL||| price| int(11)  | NO| | NULL||| useame | 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  Waings: 0mysql> 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||| useame | 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  Waings: 0mysql> ALTER TABLE ALT ADD UNIQUE(pid);Query OK, 0 rows affected, 1 waing (0.01 sec)Records: 0  Duplicates: 0  Waings: 1mysql> 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||| useame | 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 waing (0.11 sec)Records: 0  Duplicates: 0  Waings: 1mysql> 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||| useame | 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 tablemysql> ALTER TABLE ALT ADD UNIQUE(useame,price);Query OK, 0 rows affected (0.01 sec)Records: 0  Duplicates: 0  Waings: 0mysql> 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||| useame | 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  Waings: 0mysql> 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||| useame | 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  Waings: 0mysql> 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||| useame | 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 1mysql> ALTER TABLE ALT ALTER  age DROP DEFAULT;Query OK, 0 rows affected (0.01 sec)Records: 0  Duplicates: 0  Waings: 0mysql> 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||| useame | 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 1mysql> 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,  `useame` 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 `useame` (`useame`,`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  Waings: 0mysql> 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,  `useame` 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 `useame` (`useame`,`price`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 |+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec)mysql> SHOW INDEXES FROM ALT\G*************************** 1. row ***************************Table: ALTNon_unique: 0 Key_name: pid Seq_in_index: 1  Column_name: pidCollation: A  Cardinality: 0 Sub_part: NULLPacked: NULL Null: YESIndex_type: BTREE  Comment: Index_comment: *************************** 2. row ***************************Table: ALTNon_unique: 0 Key_name: pid Seq_in_index: 2  Column_name: priceCollation: A  Cardinality: 0 Sub_part: NULLPacked: NULL Null:Index_type: BTREE  Comment: Index_comment: *************************** 3. row ***************************Table: ALTNon_unique: 0 Key_name: pid_2 Seq_in_index: 1  Column_name: pidCollation: A  Cardinality: 0 Sub_part: NULLPacked: NULL Null: YESIndex_type: BTREE  Comment: Index_comment: *************************** 4. row ***************************Table: ALTNon_unique: 0 Key_name: pid_3 Seq_in_index: 1  Column_name: pidCollation: A  Cardinality: 0 Sub_part: NULLPacked: NULL Null: YESIndex_type: BTREE  Comment: Index_comment: *************************** 5. row ***************************Table: ALTNon_unique: 0 Key_name: pid_4 Seq_in_index: 1  Column_name: pidCollation: A  Cardinality: 0 Sub_part: NULLPacked: NULL Null: YESIndex_type: BTREE  Comment: Index_comment: *************************** 6. row ***************************Table: ALTNon_unique: 0 Key_name: pid_4 Seq_in_index: 2  Column_name: priceCollation: A  Cardinality: 0 Sub_part: NULLPacked: NULL Null:Index_type: BTREE  Comment: Index_comment: *************************** 7. row ***************************Table: ALTNon_unique: 0 Key_name: useame Seq_in_index: 1  Column_name: useameCollation: A  Cardinality: 0 Sub_part: NULLPacked: NULL Null: YESIndex_type: BTREE  Comment: Index_comment: *************************** 8. row ***************************Table: ALTNon_unique: 0 Key_name: useame Seq_in_index: 2  Column_name: priceCollation: A  Cardinality: 0 Sub_part: NULLPacked: NULL Null:Index_type: BTREE  Comment: Index_comment: 8 rows in set (0.09 sec)mysql> ALTER TABLE ALT DROP useame;Query OK, 0 rows affected (0.18 sec)Records: 0  Duplicates: 0  Waings: 0mysql> SHOW INDEXES FROM ALT\G*************************** 1. row ***************************Table: ALTNon_unique: 0 Key_name: useame Seq_in_index: 1  Column_name: priceCollation: A  Cardinality: 0 Sub_part: NULLPacked: NULL Null:Index_type: BTREE  Comment: Index_comment: *************************** 2. row ***************************Table: ALTNon_unique: 0 Key_name: pid Seq_in_index: 1  Column_name: pidCollation: A  Cardinality: 0 Sub_part: NULLPacked: NULL Null: YESIndex_type: BTREE  Comment: Index_comment: *************************** 3. row ***************************Table: ALTNon_unique: 0 Key_name: pid Seq_in_index: 2  Column_name: priceCollation: A  Cardinality: 0 Sub_part: NULLPacked: NULL Null:Index_type: BTREE  Comment: Index_comment: *************************** 4. row ***************************Table: ALTNon_unique: 0 Key_name: pid_2 Seq_in_index: 1  Column_name: pidCollation: A  Cardinality: 0 Sub_part: NULLPacked: NULL Null: YESIndex_type: BTREE  Comment: Index_comment: *************************** 5. row ***************************Table: ALTNon_unique: 0 Key_name: pid_3 Seq_in_index: 1  Column_name: pidCollation: A  Cardinality: 0 Sub_part: NULLPacked: NULL Null: YESIndex_type: BTREE  Comment: Index_comment: *************************** 6. row ***************************Table: ALTNon_unique: 0 Key_name: pid_4 Seq_in_index: 1  Column_name: pidCollation: A  Cardinality: 0 Sub_part: NULLPacked: NULL Null: YESIndex_type: BTREE  Comment: Index_comment: *************************** 7. row ***************************Table: ALTNon_unique: 0 Key_name: pid_4 Seq_in_index: 2  Column_name: priceCollation: A  Cardinality: 0 Sub_part: NULLPacked: 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 `useame` (`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  Waings: 0mysql> 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 1mysql> ALTER TABLE ALT MODIFY age TINYINT(3) UNSIGNED NOT NULL FIRST;Query OK, 0 rows affected (1.24 sec)Records: 0  Duplicates: 0  Waings: 0mysql> 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 1mysql> ALTER TABLE ALT CHANGE price prices INT NOT NULL PRIMARY KEY;Query OK, 0 rows affected (0.28 sec)Records: 0  Duplicates: 0  Waings: 0mysql> 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 1mysql> 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,
-> useame 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,-> useame 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 (useame ,pwd,classname ,province) VALUES('小强',md5(123),'jave','内蒙古') ;-> ''> ‘'> ^Cmysql> INSERT INTO user (useame ,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 1mysql> INSERT INTO user (useame ,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 1mysql> INSERT INTO user (useame ,pwd,classname ,province) VALUES('小强',md5(123),'jave','内蒙古');Query OK, 1 row affected (0.11 sec)mysql> SELECT * FROM user;+----+----------+----------------------------------+------+------+-----+-----------+-----------+| id | useame | pwd  | sex  | age  | edu | classname | province  |+----+----------+----------------------------------+------+------+-----+-----------+-----------+|  1 | 小强 | 202cb962ac59075b964b07152d234b70 |0 |18 |2 | jave  | 内蒙古|+----+----------+----------------------------------+------+------+-----+-----------+-----------+1 row in set (0.00 sec)mysql> INSERT INTO user (useame ,pwd,classname ,province) VALUES('小Q',md5(123),'jŠŠ罆򙅸罆^Cmysql> INSERT INTO user (useame ,pwd,classname ,province) VALUES('小强',md5(123),'jave','内蒙古');INSERT INTO user (useame ,pwd,classname ,province) VALUES('小强',md5(123),'jave','内蒙古')[1]+  Stopped mysql -u root -p[root@mysql.bktwo.quan.bbs ~]$mysql -u root -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 134Server version: 5.7.29-log Source distributionCopyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> use qqqERROR 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 monReading table information for completion of table and column namesYou can tu off this feature to get a quicker startup with -ADatabase changedmysql>  INSERT INTO user (useame ,pwd,classname ,province) VALUES('小xx',md5(123),'jave','内蒙古'),('小jj',md5(1234),'javed','湛江');Query OK, 2 rows affected (0.00 sec)Records: 2  Duplicates: 0  Waings: 0mysql> SELECT * FROM user;+----+----------+----------------------------------+------+------+-----+-----------+-----------+| id | useame | 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 1mysql> INSERT INTO user VALUES(default,'小米',md5(1245),1,66,3,'py','背景');Query OK, 1 row affected (0.00 sec)mysql> SELECT * FROM user;+----+----------+----------------------------------+------+------+-----+-----------+-----------+| id | useame | 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  Waings: 0mysql> SELECT * FROM user;+----+----------+----------------------------------+------+------+-----+-----------+-----------+| id | useame | 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 useame='root',pwd=md5(3453),classname='dada',province='天津'-> ^Cmysql> INSERT INTO user SET useame='root',pwd=md5(3453),classname='dada',province='天津';Query OK, 1 row affected (0.00 sec)mysql> SELECT * FROM user;+----+----------+----------------------------------+------+------+-----+-----------+-----------+| id | useame | 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 | useame | 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 1mysql> UPDATE user SET age = age + 5;Query OK, 7 rows affected (0.09 sec)Rows matched: 7  Changed: 7  Waings: 0mysql> SELECT * FROM user;+----+----------+----------------------------------+------+------+-----+-----------+-----------+| id | useame | 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  Waings: 0mysql> SELECT * FROM user;+----+----------+----------------------------------+------+------+-----+-----------+-----------+| id | useame | 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 1mysql> 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 1mysql> 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 1mysql> UPDATE user SET age = age + 10 WHERE id%2 =0;Query OK, 3 rows affected (0.00 sec)Rows matched: 3  Changed: 3  Waings: 0mysql> SELECT * FROM user;+----+----------+----------------------------------+------+------+-----+-----------+-----------+| id | useame | 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)

 

作者:linux——quan
来源链接:https://www.cnblogs.com/betterquan/p/12518074.html

版权声明:
1、JavaClub(https://www.javaclub.cn)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。

2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。





本文链接:https://www.javaclub.cn/database/118298.html

标签:1364:Field
分享给朋友:

“mingling” 的相关文章

MySQL触发器 2022年05月16日 21:53:36
MYSQL的存储过程 2022年05月16日 21:54:19
Oracle SQL 2022年06月05日 03:43:59
mysql 查询1小时内 2022年06月06日 12:59:30
MySQL 查询指定时间范围内的数据 2022年06月06日 16:59:25
mysql数据查询——复杂查询 2022年06月09日 23:08:26
mysql 查询数据结果计算百分比 2022年06月11日 10:01:40