Created
March 14, 2019 22:33
-
-
Save gabrieldarezzo/60c1f68b3fb2fbd91776c6aa612c3608 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```sql | |
CREATE TABLE products ( | |
product_id INT(11) PRIMARY KEY AUTO_INCREMENT, | |
product_desc VARCHAR(250) NOT NULL UNIQUE, | |
imagesrc VARCHAR(250) | |
); | |
SELECT | |
CONCAT('INSERT INTO products (product_id, product_desc) VALUES (', @rownum, ',\'', product_id, '\');') AS sql_stmt, | |
CONCAT('UPDATE local set product_id = ', @rownum, ' WHERE product_id = \'', product_id, '\';') AS sql_stmt, | |
product_id, | |
@rownum := @rownum + 1 | |
FROM | |
( | |
SELECT | |
DISTINCT product_id | |
FROM | |
LOCAL | |
WHERE product_id IS NOT NULL | |
AND product_id <> '' | |
) AS tbl | |
,(SELECT @rownum := 1) r; | |
ALTER TABLE `local` CHANGE `product_id` `product_id` INT(11) NOT NULL; | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment