DROP TABLE posts;
DROP TABLE topics;
DROP TABLE categories;
DROP TABLE users;

CREATE TABLE categories (
catNo INT(8) NOT NULL AUTO_INCREMENT,
catName VARCHAR(255) NOT NULL,
catDescr VARCHAR(255) NOT NULL,
PRIMARY KEY (catNo)
);

CREATE TABLE users (
userNo INT(8) NOT NULL AUTO_INCREMENT,
userName VARCHAR(255) NOT NULL,
userPass VARCHAR(255) NOT NULL,
userEmail VARCHAR(255) NOT NULL,
userDate DATETIME NOT NULL,
userLevel INT(8) NOT NULL,
PRIMARY KEY (userNo)
);

CREATE TABLE topics (
topicNo INT(8) NOT NULL AUTO_INCREMENT,
topicSubject VARCHAR(255) NOT NULL,
topicDate DATETIME NOT NULL,
topicCat INT(8) NOT NULL,
topicBy INT(8) NOT NULL,
PRIMARY KEY (topicNo),
FOREIGN KEY (topicCat) REFERENCES categories (catNo),
FOREIGN KEY (topicBy) REFERENCES users (userNo)
);

CREATE TABLE posts (
postNo INT(8) NOT NULL AUTO_INCREMENT,
postContent VARCHAR(255) NOT NULL,
postDate DATETIME NOT NULL,
postTopic INT(8) NOT NULL,
postBy INT(8) NOT NULL,
PRIMARY KEY (postNo),
FOREIGN KEY (postTopic) REFERENCES topics (topicNo),
FOREIGN KEY (postBy) REFERENCES users (userNo)
);