Created
March 10, 2014 05:11
-
-
Save ColtonPhillips/9459811 to your computer and use it in GitHub Desktop.
An attempt at a simple sql problem for a job application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#--# | |
#--# Database structure for Pretio | |
#--# | |
DROP TABLE IF EXISTS Folders; | |
DROP TABLE IF EXISTS Files; | |
DROP TABLE IF EXISTS Users; | |
DROP TABLE IF EXISTS Contents; | |
CREATE TABLE Users ( | |
userid Integer AUTO_INCREMENT, | |
name varchar(255) NOT NULL, | |
PRIMARY KEY(userid) | |
); | |
CREATE TABLE Files ( | |
userid Integer NOT NULL, | |
fileid Integer AUTO_INCREMENT, | |
name varchar(255) NOT NULL, | |
url varchar(1024), | |
PRIMARY KEY (fileid), | |
FOREIGN KEY (userid) REFERENCES Users(userid) | |
); | |
CREATE TABLE Folders ( | |
userid Integer NOT NULL, | |
folderid Integer AUTO_INCREMENT, | |
name varchar(255) NOT NULL, | |
PRIMARY KEY (folderid), | |
FOREIGN KEY (userid) REFERENCES Users(userid) | |
); | |
CREATE TABLE Contents ( | |
contentid Integer AUTO_INCREMENT, | |
parentid Integer, | |
# the Folder or File (or User?) | |
content Integer NOT NULL, | |
PRIMARY KEY (contentid) | |
); | |
# Create 2 users | |
INSERT INTO Users (name) | |
VALUES ("Colton"); | |
INSERT INTO Users (name) | |
VALUES ("Nicolas"); | |
# Create an inaccessable File | |
INSERT INTO Files (userid, name, url) | |
VALUES (1 /*SELECT userid FROM Users WHERE name='Colton'*/, "ColtonFile", "http://www.coltonphillips.ca"); | |
#Create an inaccessable Folder | |
INSERT INTO Folders(userid,name) | |
VALUES (2 /*SELECT userid FROM Users WHERE name='Colton'*/, "ColtonFolder"); | |
#The ColtonFolder has no parent | |
INSERT INTO Contents(content,parentid) | |
VALUES (3 /*SELECT folderid FROM Folders WHERE name='ColtonFolder'*/, NULL); | |
#The ColtonFile is inside of the ColtonFolder | |
INSERT INTO Contents(content,parentid) | |
VALUES (4 /*SELECT fileid FROM Folders WHERE name='ColtonFile'*/ | |
,5 /*SELECT folderid FROM Folders WHERE name='ColtonFolder'*/); | |
# Display all users | |
select * from Users; | |
#Display Contents of a directory | |
select * from Contents where parentid=6 /*SELECT folderid FROM Folders WHERE name='ColtonFolder'*/; | |
select * from Contents; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment