sql问题,请教 有个表a,主键id,我想创建个临时表从表a中拿数据,并重新设置自增长的主键uids。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 详细说明,并重新设置自增长的主键uids:A表? IDENTITY (1,1) PRIMARY KEY) create temporary table aa(uids int primary key auto_increment,num text)select num from a;把表a的num字段给临时表aa的num字段这样? num 是我自己一个测试的字段,你把你自己表上的字段放上去撒. create table cmp as select f1,f2 from a;ALTER TABLE cmp ADD id INT AUTO_INCREMENT PRIMARY KEY create table a(id int auto_increment primary key,f int);insert into a values (1,1),(2,2),(3,3);create table temp_a as select * from a;mysql> desc a;+-------+---------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+-------+---------+------+-----+---------+----------------+| id | int(11) | NO | PRI | NULL | auto_increment || f | int(11) | YES | | NULL | |+-------+---------+------+-----+---------+----------------+2 rows in set (0.01 sec)mysql> select * from a;+----+------+| id | f |+----+------+| 1 | 1 || 2 | 2 || 3 | 3 |+----+------+3 rows in set (0.00 sec)mysql> alter table temp_a add uids int auto_increment primary key;Query OK, 3 rows affected (0.09 sec)Records: 3 Duplicates: 0 Warnings: 0mysql> desc temp_a;+-------+---------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+-------+---------+------+-----+---------+----------------+| id | int(11) | NO | | 0 | || f | int(11) | YES | | NULL | || uids | int(11) | NO | PRI | NULL | auto_increment |+-------+---------+------+-----+---------+----------------+3 rows in set (0.02 sec)mysql> select * from temp_a;+----+------+------+| id | f | uids |+----+------+------+| 1 | 1 | 1 || 2 | 2 | 2 || 3 | 3 | 3 |+----+------+------+3 rows in set (0.00 sec)mysql> mysql 触发器 求教高手 如何删除数据库中的乱码的信息 MYSQL集群中冗余节点问题 高手来帮下 哥哥们啊 tomcat中的显示的一个java.sql.SQLException 请看看 日期存在整型字段中,怎样提取当天记录. 死钻牛角尖之 模式匹配中 LIKE 子句转义符的使用 ASP访问MySQL!!!!!! 关于sql的查询 及 书籍推荐 ??? 请教下关于电子商务网站后台Mysql架构问题及硬件规格问题 请教一个mysql时间的查询问题 请教一个flex问题
并重新设置自增长的主键uids:A表?
select num from a;
把表a的num字段给临时表aa的num字段这样?
ALTER TABLE cmp ADD id INT AUTO_INCREMENT PRIMARY KEY
insert into a values (1,1),(2,2),(3,3);create table temp_a as select * from a;
mysql> desc a;
+-------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| f | int(11) | YES | | NULL | |
+-------+---------+------+-----+---------+----------------+
2 rows in set (0.01 sec)mysql> select * from a;
+----+------+
| id | f |
+----+------+
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
+----+------+
3 rows in set (0.00 sec)mysql> alter table temp_a add uids int auto_increment primary key;
Query OK, 3 rows affected (0.09 sec)
Records: 3 Duplicates: 0 Warnings: 0mysql> desc temp_a;
+-------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+----------------+
| id | int(11) | NO | | 0 | |
| f | int(11) | YES | | NULL | |
| uids | int(11) | NO | PRI | NULL | auto_increment |
+-------+---------+------+-----+---------+----------------+
3 rows in set (0.02 sec)mysql> select * from temp_a;
+----+------+------+
| id | f | uids |
+----+------+------+
| 1 | 1 | 1 |
| 2 | 2 | 2 |
| 3 | 3 | 3 |
+----+------+------+
3 rows in set (0.00 sec)mysql>