daily pastebin goal
54%
SHARE
TWEET

Untitled

a guest Mar 19th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ```sql
  2. CREATE TABLE products (
  3.     product_id INT(11) PRIMARY KEY AUTO_INCREMENT,
  4.     product_desc  VARCHAR(250) NOT NULL UNIQUE,
  5.     imagesrc VARCHAR(250)    
  6. );
  7.  
  8. SELECT
  9. CONCAT('INSERT INTO products (product_id, product_desc) VALUES (', @rownum, ',\'', product_id, '\');') AS sql_stmt,
  10. CONCAT('UPDATE local set product_id = ', @rownum, ' WHERE product_id = \'', product_id, '\';') AS sql_stmt,
  11. product_id,
  12. @rownum := @rownum + 1
  13. FROM
  14. (
  15. SELECT
  16.     DISTINCT product_id
  17. FROM
  18.   LOCAL
  19. WHERE product_id IS NOT NULL
  20.   AND product_id <> ''
  21. ) AS tbl
  22. ,(SELECT @rownum := 1) r;
  23.  
  24.  
  25. ALTER TABLE `local` CHANGE `product_id` `product_id` INT(11) NOT NULL;
  26. ```
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top