deyanmalinov

04-mysql

Sep 19th, 2020 (edited)
301
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE TABLE `users` (
  2.   `id` INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
  3.   `username` VARCHAR(30) NULL,
  4.   `password` VARCHAR(26) NULL,
  5.   `profile_picture` BLOB NULL,
  6.   `last_login_time` TIME NULL,
  7.   `is_deleted` TINYINT NULL
  8. );
  9.  
  10. INSERT INTO `users` (`id`, `username`, `password`, `last_login_time`, `is_deleted`)
  11. VALUES
  12. ('1', 'user', 'proba123', '12:30', '0'),
  13. ('2', 'user', 'proba123', '12:30', '0'),
  14. ('3', 'user', 'proba123', '12:30', '0'),
  15. ('4', 'user', 'proba123', '12:30', '0'),
  16. ('5', 'user', 'proba123', '12:30', '0');
  17.  
  18. ALTER TABLE `users`
  19. DROP PRIMARY KEY,
  20. ADD PRIMARY KEY (`id`, `username`);
  21.  
  22. ALTER TABLE `users`
  23. CHANGE COLUMN `last_login_time` `last_login_time` TIME NOT NULL ;
  24.  
  25. ALTER TABLE `users`
  26. CHANGE COLUMN `last_login_time` `last_login_time` TIME NOT NULL ,
  27. DROP PRIMARY KEY,
  28. ADD PRIMARY KEY (`id`),
  29. ADD UNIQUE INDEX `username_UNIQUE` (`username` ASC) VISIBLE;
  30.  
  31.  
RAW Paste Data