我有表product_to_store
(它是opencart
表),product_id
和store_id
作爲列標題。表被填充數據(下面實施例):複製錶行,但與另一個值
+------------+----------+
| product_id | store_id |
+------------+----------+
| 123 | 0 |
| 124 | 0 |
| 125 | 0 |
| 126 | 0 |
| 125 | 1 |
+------------+----------+
幫助(從MySQL錶轉儲):
CREATE TABLE `product_to_store` (
`product_id` int(11) NOT NULL,
`store_id` int(11) NOT NULL DEFAULT '0'
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `product_to_store` (`product_id`, `store_id`) VALUES
(123, 0),
(124, 0),
(125, 0),
(126, 0),
(125, 1);
ALTER TABLE `product_to_store`
ADD PRIMARY KEY (`product_id`,`store_id`);
我想複製具有0值作爲STORE_ID所有行。而不是0值,我希望它們具有值1(例如)。我如何使用mysql語法來做到這一點?
所以最後的表應該是這個樣子
+------------+----------+
| product_id | store_id |
+------------+----------+
| 123 | 0 |
| 124 | 0 |
| 125 | 0 |
| 126 | 0 |
| 125 | 1 |
| 123 | 1 |
| 124 | 1 |
| 126 | 1 |
+------------+----------+
謝謝大家提前爲您解答!
你似乎沒有PRIMARY KEY。這在適當的時候可能會有問題。 – Strawberry
@Strawberry我編輯了我的問題(alter table) – AlFra