Advertisement
Guest User

Untitled

a guest
May 24th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. #DROP DATABASE fh_web4_bookshop;
  2. CREATE DATABASE fh_web4_bookshop;
  3. USE fh_web4_bookshop;
  4.  
  5. -- KEY == index!
  6. CREATE TABLE books (
  7. id int(11) NOT NULL AUTO_INCREMENT,
  8. categoryId int(11) NOT NULL,
  9. title varchar(255) NOT NULL,
  10. author varchar(255) NOT NULL,
  11. isbn varchar(255) NOT NULL,
  12. price decimal(10,2) NOT NULL,
  13. PRIMARY KEY (id),
  14. KEY categoryId (categoryId)
  15. );
  16.  
  17. CREATE TABLE categories (
  18. id int(11) NOT NULL AUTO_INCREMENT,
  19. name varchar(255) NOT NULL,
  20. PRIMARY KEY (id)
  21. );
  22.  
  23.  
  24. CREATE TABLE orderedbooks (
  25. id int(11) NOT NULL AUTO_INCREMENT,
  26. orderId int(11) NOT NULL,
  27. bookId int(11) NOT NULL,
  28. PRIMARY KEY (id),
  29. KEY orderId (orderId),
  30. KEY bookId (bookId)
  31. );
  32.  
  33. CREATE TABLE orders (
  34. id int(11) NOT NULL AUTO_INCREMENT,
  35. userId int(11) NOT NULL,
  36. creditCardNumber char(16) NOT NULL,
  37. creditCardHolder varchar(255) NOT NULL,
  38. PRIMARY KEY (id),
  39. KEY userId (userId)
  40.  
  41. );
  42.  
  43. CREATE TABLE users (
  44. id int(11) NOT NULL AUTO_INCREMENT,
  45. userName varchar(255) NOT NULL,
  46. passwordHash char(40) NOT NULL,
  47. PRIMARY KEY (id),
  48. UNIQUE KEY userName (userName)
  49.  
  50. );
  51.  
  52.  
  53. ALTER TABLE books
  54. ADD CONSTRAINT books_ibfk_1 FOREIGN KEY (categoryId) REFERENCES categories (id) ON DELETE CASCADE ON UPDATE CASCADE;
  55.  
  56. ALTER TABLE orderedbooks
  57. ADD CONSTRAINT orderedbooks_ibfk_2 FOREIGN KEY (bookId) REFERENCES books (id) ON DELETE CASCADE ON UPDATE CASCADE,
  58.  
  59. ADD CONSTRAINT orderedBooks_ibfk_1 FOREIGN KEY (orderid) REFERENCES orders (id) ON DELETE CASCADE ON UPDATE CASCADE;
  60.  
  61.  
  62. ALTER TABLE orders
  63. ADD CONSTRAINT orders_ibfk_1 FOREIGN KEY (userId) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE;
  64.  
  65.  
  66. INSERT INTO categories VALUES (1, 'Mobile & Wireless Computing');
  67. INSERT INTO categories VALUES (2, 'Functional Programming');
  68. INSERT INTO categories VALUES (3, 'C / C++');
  69. INSERT INTO categories VALUES (4, '<< New Publications >>');
  70.  
  71. INSERT INTO books VALUES (1, 1, 'Hello, Android: Introducing Google''s Mobile Development Platform', 'Ed Burnette', '9781934356562', 19.97);
  72. INSERT INTO books VALUES (2, 1, 'Android Wireless Application Development', 'Shane Conder, Lauren Darcey', '0321743016', 31.22);
  73. INSERT INTO books VALUES (5, 1, 'Professional Flash Mobile Development', 'Richard Wagner', '0470620072', 19.90);
  74. INSERT INTO books VALUES (7, 1, 'Mobile Web Design For Dummies', 'Janine Warner, David LaFontaine', '9780470560969', 16.32);
  75. INSERT INTO books VALUES (11, 2, 'Introduction to Functional Programming using Haskell', 'Richard Bird', '9780134843469', 74.75);
  76. INSERT INTO books VALUES (12, 2, 'Scripting (Attacks) for Beginners - <script type="text/javascript">alert(''All your base are belong to us!'');</script>', 'John Doe', '1234567890', 9.99);
  77. INSERT INTO books VALUES (14, 2, 'Expert F# (Expert''s Voice in .NET)', 'Antonio Cisternino, Adam Granicz, Don Syme', '9781590598504', 47.64);
  78. INSERT INTO books VALUES (16, 3, 'C Programming Language (2nd Edition)', 'Brian W. Kernighan, Dennis M. Ritchie', '0131103628', 48.36);
  79. INSERT INTO books VALUES (27, 3, 'C++ Primer Plus (5th Edition)', 'Stephan Prata', ' 9780672326974', 36.94);
  80. INSERT INTO books VALUES (29, 3, 'The C++ Programming Language', 'Bjarne Stroustrup', '0201700735', 67.49);
  81.  
  82. INSERT INTO users VALUES (1, 'scm4', 'a8af855d47d091f0376664fe588207f334cdad22');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement