Guest User

Untitled

a guest
May 25th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. /*
  2. createdb.sql
  3. Tables created:
  4. Business
  5. Business_Hours
  6. Business_Neighborhoods
  7. Business_Attributes
  8. Business_Category
  9. User
  10. Review
  11. */
  12.  
  13.  
  14. -- Business Table
  15. -- Separate tables for category, hours, neighborhoods, attributes
  16. CREATE TABLE Business(
  17. business_id VARCHAR2(100) PRIMARY KEY,
  18. -- encrypted business id
  19. full_address VARCHAR2(200) NOT NULL,
  20. -- localized address
  21. open VARCHAR2(5),
  22. -- true/false if the business is open/closed
  23. city VARCHAR2(50) NOT NULL,
  24. state VARCHAR2 (50) NOT NULL,
  25. latitude NUMBER NOT NULL,
  26. longitude NUMBER NOT NULL,
  27. review_count NUMBER,
  28. business_name VARCHAR2(100),
  29. stars NUMBER,
  30. -- star rating, rounded to half-stars
  31. type VARCHAR2(30)
  32. -- 'business'
  33. );
  34.  
  35. -- Business Hours Table
  36. CREATE TABLE Business_Hours(
  37. business_id VARCHAR2(100) PRIMARY KEY,
  38. business_day VARCHAR2(20),
  39. -- the days of the week
  40. open_time TIMESTAMP,
  41. close_time TIMESTAMP,
  42. FOREIGN KEY business_id REFERENCES Business(business_id) ON DELETE CASCADE
  43. );
  44.  
  45. -- Business Neighborhoods Table
  46. CREATE TABLE Business_Neighborhoods(
  47. business_id VARCHAR2(100) PRIMARY KEY,
  48. neighborhoods VARCHAR2(100),
  49. -- hood names
  50. FOREIGN KEY business_id REFERENCES Business(business_id) ON DELETE CASCADE
  51. );
  52.  
  53. -- Business Attributes Table
  54. CREATE TABLE Business_Attributes(
  55. business_id VARCHAR2(100) PRIMARY KEY,
  56. attributes VARCHAR2(100),
  57. -- business properties
  58. FOREIGN KEY business_id REFERENCES Business(business_id) ON DELETE CASCADE
  59. );
  60.  
  61. -- Business Category Table
  62. CREATE TABLE Business_Category(
  63. business_id VARCHAR2(100),
  64. main_category VARCHAR2(100) NOT NULL,
  65. sub_category VARCHAR2(100),
  66. FOREIGN KEY business_id REFERENCES Business(business_id) ON DELETE CASCADE
  67. );
  68.  
  69.  
  70. -- User Table
  71. CREATE TABLE User(
  72. yelping_since DATE NOT NULL,
  73. useful_votes NUMBER,
  74. funny_votes NUMBER,
  75. cool_votes NUMBER,
  76. review_count NUMBER,
  77. user_name VARCHAR2(100) NOT NULL,
  78. user_id VARCHAR2(100) PRIMARY KEY,
  79. --friends -- "friends": ["abcdeedgs", "dsaggagrtrtgr", ...]
  80. fans NUMBER,
  81. average_stars NUMBER,
  82. type VARCHAR2(30),
  83. --compliments -- "compliments": {"note": 1, "photo": 2, ...}
  84. --elite -- "elite": [2012, 2013, 2014]
  85. );
  86.  
  87.  
  88. -- Review Table
  89. CREATE TABLE Review(
  90. useful_votes NUMBER,
  91. funny_votes NUMBER,
  92. cool_votes NUMBER,
  93. user_id VARCHAR2(100) NOT NULL,
  94. review_id VARCHAR2(100) PRIMARY KEY,
  95. stars NUMBER,
  96. review_date DATE NOT NULL,
  97. review_text VARCHAR2(3000),
  98. type VARCHAR2(30)
  99. business_id VARCHAR2(100),
  100. FOREIGN KEY user_id REFERENCES User(user_id) ON DELETE CASCADE,
  101. FOREIGN KEY business_id REFERENCES Business(business_id) ON DELETE CASCADE
  102. );
Add Comment
Please, Sign In to add comment