亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

將其他字段設置為自增主鍵

發布時間:2020-06-13 12:57:56 來源:網絡 閱讀:574 作者:Stereor 欄目:MySQL數據庫

1、創建測試表,查看表結構

mysql> desc test_autoinc;

+-------+--------------+------+-----+---------+----------------+

| Field | Type         | Null | Key | Default | Extra          |

+-------+--------------+------+-----+---------+----------------+

| id    | int(11)      | NO   | PRI | NULL    | auto_increment |

| c1    | int(11)      | YES  | UNI | NULL    |                |

| c2    | varchar(100) | YES  |     | NULL    |                |

| id_no | int(20)      | NO   |     | NULL    |                |

+-------+--------------+------+-----+---------+----------------+

4 rows in set (0.00 sec)


2、將其他字段設置為自增主鍵(當前表上已經有自增主鍵,設置其他字段為自增主鍵報錯)

mysql> 

mysql> alter table test_autoinc modify id_no int(11) auto_increment,add primary key(id_no);

ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key

mysql> 

mysql> desc test_autoinc;

+-------+--------------+------+-----+---------+----------------+

| Field | Type         | Null | Key | Default | Extra          |

+-------+--------------+------+-----+---------+----------------+

| id    | int(11)      | NO   | PRI | NULL    | auto_increment |

| c1    | int(11)      | YES  | UNI | NULL    |                |

| c2    | varchar(100) | YES  |     | NULL    |                |

| id_no | int(20)      | NO   |     | NULL    |                |

+-------+--------------+------+-----+---------+----------------+

4 rows in set (0.00 sec)


3、刪除表上的約束

mysql> 

mysql> alter table test_autoinc change id id int;

Query OK, 5 rows affected (0.07 sec)

Records: 5  Duplicates: 0  Warnings: 0


mysql> 

mysql> desc test_autoinc;

+-------+--------------+------+-----+---------+-------+

| Field | Type         | Null | Key | Default | Extra |

+-------+--------------+------+-----+---------+-------+

| id    | int(11)      | NO   | PRI | NULL    |       |

| c1    | int(11)      | YES  | UNI | NULL    |       |

| c2    | varchar(100) | YES  |     | NULL    |       |

| id_no | int(20)      | NO   |     | NULL    |       |

+-------+--------------+------+-----+---------+-------+

4 rows in set (0.00 sec)


5、刪除表上的主鍵

mysql> alter table test_autoinc drop primary key;

Query OK, 5 rows affected (0.07 sec)

Records: 5  Duplicates: 0  Warnings: 0


mysql> 

mysql> desc test_autoinc;

+-------+--------------+------+-----+---------+-------+

| Field | Type         | Null | Key | Default | Extra |

+-------+--------------+------+-----+---------+-------+

| id    | int(11)      | NO   |     | NULL    |       |

| c1    | int(11)      | YES  | UNI | NULL    |       |

| c2    | varchar(100) | YES  |     | NULL    |       |

| id_no | int(20)      | NO   |     | NULL    |       |

+-------+--------------+------+-----+---------+-------+

4 rows in set (0.00 sec)


mysql> show variables like 'sql_mode'; 

+---------------+-------------------------------------------------------------------------------------------------------------------------------------------+

| Variable_name | Value                                                                                                                                     |

+---------------+-------------------------------------------------------------------------------------------------------------------------------------------+

| sql_mode      | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |

+---------------+-------------------------------------------------------------------------------------------------------------------------------------------+

1 row in set (0.00 sec)


mysql> select * from test_autoinc;

+----+------+-------+-------+

| id | c1   | c2    | id_no |

+----+------+-------+-------+

|  6 |    1 | abc   |     0 |

|  8 |    3 | abcdd |     0 |

|  9 |    4 | abcdd |     0 |

| 10 |    5 | abcdd |     0 |

| 11 |    2 | eeee  |     0 |

+----+------+-------+-------+

5 rows in set (0.00 sec)


mysql> update test_autoinc set id_no=1 ;

Query OK, 5 rows affected (0.14 sec)

Rows matched: 5  Changed: 5  Warnings: 0


mysql> 

mysql> select * from test_autoinc;

+----+------+-------+-------+

| id | c1   | c2    | id_no |

+----+------+-------+-------+

|  6 |    1 | abc   |     1 |

|  8 |    3 | abcdd |     1 |

|  9 |    4 | abcdd |     1 |

| 10 |    5 | abcdd |     1 |

| 11 |    2 | eeee  |     1 |

+----+------+-------+-------+

5 rows in set (0.00 sec)


mysql> alter table test_autoinc add primary key(id_no) ,modify id_no int(11) auto_increment;

ERROR 1062 (23000): ALTER TABLE causes auto_increment resequencing, resulting in duplicate entry '1' for key 'PRIMARY'

mysql> alter table test_autoinc add primary key(id_no);

ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'

mysql> update test_autoinc set id_no=2 where id=7 ;

Query OK, 0 rows affected (0.00 sec)

Rows matched: 0  Changed: 0  Warnings: 0


mysql> update test_autoinc set id_no=3 where id=8 ;

Query OK, 1 row affected (0.01 sec)

Rows matched: 1  Changed: 1  Warnings: 0


mysql> update test_autoinc set id_no=4 where id=9 ;

Query OK, 1 row affected (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 0


mysql> update test_autoinc set id_no=5 where id=10 ;

Query OK, 1 row affected (0.01 sec)

Rows matched: 1  Changed: 1  Warnings: 0


mysql> update test_autoinc set id_no=6 where id=11 ;

Query OK, 1 row affected (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 0


mysql> 

mysql> select * from test_autoinc;

+----+------+-------+-------+

| id | c1   | c2    | id_no |

+----+------+-------+-------+

|  6 |    1 | abc   |     1 |

|  8 |    3 | abcdd |     3 |

|  9 |    4 | abcdd |     4 |

| 10 |    5 | abcdd |     5 |

| 11 |    2 | eeee  |     6 |

+----+------+-------+-------+

5 rows in set (0.00 sec)


mysql> 

mysql> alter table test_autoinc add primary key(id_no) ,modify id_no int(11) auto_increment;

Query OK, 5 rows affected (0.27 sec)

Records: 5  Duplicates: 0  Warnings: 0


mysql> 

mysql> show create table test_autoinc\G;

*************************** 1. row ***************************

       Table: test_autoinc

Create Table: CREATE TABLE `test_autoinc` (

  `id` int(11) NOT NULL,

  `c1` int(11) DEFAULT NULL,

  `c2` varchar(100) DEFAULT NULL,

  `id_no` int(11) NOT NULL AUTO_INCREMENT,

  PRIMARY KEY (`id_no`),

  UNIQUE KEY `c1` (`c1`)

) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8

1 row in set (0.00 sec)


ERROR: 

No query specified


mysql> 


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

河南省| 密山市| 岱山县| 黄平县| 封开县| 吉安市| 台东市| 璧山县| 闵行区| 潜江市| 杭锦旗| 聂拉木县| 上蔡县| 汉沽区| 十堰市| 新乐市| 太和县| 天全县| 乐东| 平定县| 仙居县| 辉县市| 广昌县| 三门峡市| 乐安县| 溧水县| 松溪县| 溧阳市| 嘉定区| 永登县| 安阳市| 综艺| 科技| 铜梁县| 瑞安市| 阿克陶县| 孝昌县| 桐城市| 临潭县| 德安县| 屏东县|