MySql 怎样修改某字段的属性?使其不自动增长?? MySql 怎样修改某字段的属性?使其不自动增长?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 alter table tx modify id int not null ;就可以了如下。mysql> create table tx( -> id int not null primary key auto_increment, -> c1 int -> );Query OK, 0 rows affected (0.13 sec)mysql>mysql> insert into tx values (null,11);Query OK, 1 row affected (0.01 sec)mysql> insert into tx values (null,22);Query OK, 1 row affected (0.05 sec)mysql> select * from tx;+----+------+| id | c1 |+----+------+| 1 | 11 || 2 | 22 |+----+------+2 rows in set (0.00 sec)mysql> alter table tx modify id int not null ;Query OK, 2 rows affected (0.42 sec)Records: 2 Duplicates: 0 Warnings: 0mysql> show create table tx \G*************************** 1. row *************************** Table: txCreate Table: CREATE TABLE `tx` ( `id` int(11) NOT NULL, `c1` int(11) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=latin11 row in set (0.00 sec)mysql> select * from tx;+----+------+| id | c1 |+----+------+| 1 | 11 || 2 | 22 |+----+------+2 rows in set (0.00 sec)mysql> insert into tx values (null,33);ERROR 1048 (23000): Column 'id' cannot be nullmysql> insert into tx values (3,33);Query OK, 1 row affected (0.06 sec)mysql> select * from tx;+----+------+| id | c1 |+----+------+| 1 | 11 || 2 | 22 || 3 | 33 |+----+------+3 rows in set (0.00 sec) mysql> show create table a;+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| Table | Create Table |+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| a | CREATE TABLE `a` ( `id` int(255) NOT NULL AUTO_INCREMENT, `titile` varchar(255) NOT NULL, `num` int(255) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 |+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.03 sec)mysql> select * from a;+----+--------+-----+| id | titile | num |+----+--------+-----+| 1 | aa | 4 || 2 | pp | 2 || 3 | ii | 2 |+----+--------+-----+3 rows in set (0.02 sec)mysql> alter table a modify column id int not null;Query OK, 3 rows affected (0.19 sec)Records: 3 Duplicates: 0 Warnings: 0mysql> select * from a;+----+--------+-----+| id | titile | num |+----+--------+-----+| 1 | aa | 4 || 2 | pp | 2 || 3 | ii | 2 |+----+--------+-----+3 rows in set (0.02 sec)mysql> insert into a(titile,num) values('aaa',23);Query OK, 1 row affected, 1 warning (0.05 sec)mysql> select * from a;+----+--------+-----+| id | titile | num |+----+--------+-----+| 0 | aaa | 23 || 1 | aa | 4 || 2 | pp | 2 || 3 | ii | 2 |+----+--------+-----+4 rows in set (0.00 sec) MySQL启动不起来,大哥们帮看看怎么解决,谢谢了。 mysql 修改变量值操作无效 数据库监控程序 如何判断mysql等协议包 mysql本地连接不了 通过mysql front可以 有关日期判断查询表的问题 请问mysql有中文版吗? 一个简单问题 alter的用法 sql server2000数据导入mysql问题 麻烦大佬给看下这两句sql能不能合并查询呢 请教以下代码那里有问题,谢谢!! mysql 的BUG..看看谁有办法解决?
-> id int not null primary key auto_increment,
-> c1 int
-> );
Query OK, 0 rows affected (0.13 sec)mysql>
mysql> insert into tx values (null,11);
Query OK, 1 row affected (0.01 sec)mysql> insert into tx values (null,22);
Query OK, 1 row affected (0.05 sec)mysql> select * from tx;
+----+------+
| id | c1 |
+----+------+
| 1 | 11 |
| 2 | 22 |
+----+------+
2 rows in set (0.00 sec)mysql> alter table tx modify id int not null ;
Query OK, 2 rows affected (0.42 sec)
Records: 2 Duplicates: 0 Warnings: 0mysql> show create table tx \G
*************************** 1. row ***************************
Table: tx
Create Table: CREATE TABLE `tx` (
`id` int(11) NOT NULL,
`c1` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)mysql> select * from tx;
+----+------+
| id | c1 |
+----+------+
| 1 | 11 |
| 2 | 22 |
+----+------+
2 rows in set (0.00 sec)mysql> insert into tx values (null,33);
ERROR 1048 (23000): Column 'id' cannot be null
mysql> insert into tx values (3,33);
Query OK, 1 row affected (0.06 sec)mysql> select * from tx;
+----+------+
| id | c1 |
+----+------+
| 1 | 11 |
| 2 | 22 |
| 3 | 33 |
+----+------+
3 rows in set (0.00 sec)
+-------+-----------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------------------+
| Table | Create Table |
+-------+-----------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------------------+
| a | CREATE TABLE `a` (
`id` int(255) NOT NULL AUTO_INCREMENT,
`titile` varchar(255) NOT NULL,
`num` int(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 |
+-------+-----------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------------------+
1 row in set (0.03 sec)mysql> select * from a;
+----+--------+-----+
| id | titile | num |
+----+--------+-----+
| 1 | aa | 4 |
| 2 | pp | 2 |
| 3 | ii | 2 |
+----+--------+-----+
3 rows in set (0.02 sec)mysql> alter table a modify column id int not null;
Query OK, 3 rows affected (0.19 sec)
Records: 3 Duplicates: 0 Warnings: 0mysql> select * from a;
+----+--------+-----+
| id | titile | num |
+----+--------+-----+
| 1 | aa | 4 |
| 2 | pp | 2 |
| 3 | ii | 2 |
+----+--------+-----+
3 rows in set (0.02 sec)mysql> insert into a(titile,num) values('aaa',23);
Query OK, 1 row affected, 1 warning (0.05 sec)mysql> select * from a;
+----+--------+-----+
| id | titile | num |
+----+--------+-----+
| 0 | aaa | 23 |
| 1 | aa | 4 |
| 2 | pp | 2 |
| 3 | ii | 2 |
+----+--------+-----+
4 rows in set (0.00 sec)