Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何添加列_Python_Sql_Indexing - Fatal编程技术网

Python 如何添加列

Python 如何添加列,python,sql,indexing,Python,Sql,Indexing,我正在寻找一个sql或python解决方案,以便将am索引添加到我的表中: 假设我有: +-------+-------+-------+ | City | State | ZIP | +-------+-------+-------+ | MIAMI | FL | 33157 | | MIAMI | FL | 33158 | | MIAMI | FL | 33159 | +-------+-------+-------+ 我希望该表添加一个城市和州唯一的索引,该索引与

我正在寻找一个sql或python解决方案,以便将am索引添加到我的表中:

假设我有:

+-------+-------+-------+
| City  | State |  ZIP  |
+-------+-------+-------+
| MIAMI | FL    | 33157 |
| MIAMI | FL    | 33158 |
| MIAMI | FL    | 33159 |
+-------+-------+-------+
我希望该表添加一个城市和州唯一的索引,该索引与zipcode无关,如下所示:

+-------+-------+-------+-------+
| City  | State |  ZIP  | Index |
+-------+-------+-------+-------+
| MIAMI | FL    | 33157 |     1 |
| MIAMI | FL    | 33158 |     2 |
| MIAMI | FL    | 33159 |     3 |
+-------+-------+-------+-------+

在MySQL中,可以使用以下SQL命令:

ALTER TABLE `table_name` ADD `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;
添加的“id”列对于每个记录都是唯一的。并将在每条记录中自动递增1。
我认为这在其他SQL数据库引擎中也是可能的。

我已经尝试了改变表'cities'添加索引'id'('city','state');但是我没有看到id列添加了任何想法?因为您只是将('city'、'state')列作为索引,而不是创建新列。如何创建新列?我已经编写了添加新列的SQL命令
ALTER TABLE`TABLE\u name`ADD`id`INT NOT NULL自动增量主键优先您正在使用哪些RDBMS?