Advertisement
Bleser

ON DUPLICATE

Apr 13th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.84 KB | None | 0 0
  1. CREATE TABLE IF NOT EXISTS `table` (
  2.   `id`            INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  3.   `name`          TEXT         NOT NULL,
  4.   `description`   TEXT         NOT NULL,
  5.   `login`         TEXT         NOT NULL,
  6.   `password`      TEXT         NOT NULL,
  7.   `old_passwords` TEXT         NOT NULL,
  8.   `last_update`   TIMESTAMP    NOT NULL DEFAULT CURRENT_TIMESTAMP,
  9.   `created`       TIMESTAMP    NOT NULL DEFAULT CURRENT_TIMESTAMP
  10. );
  11.  
  12. CREATE UNIQUE INDEX uq_name_login ON table (name,login);
  13.  
  14. INSERT INTO `table` (name, description, login, password, old_passwords, last_update, created)
  15. VALUES ("name", "description", "login", "pass", "oldPasswords", CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
  16. ON DUPLICATE KEY UPDATE name = "n", description = "d", login = "l", password = "p", old_passwords = "oldp", last_update = CURRENT_TIMESTAMP;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement