Guestbook Project - SQL
Guestbook Project - SQL
mysql>
mysql> USE guestbook;
Database changed
mysql>
mysql> CREATE TABLE Users (
-> user_id INT PRIMARY KEY AUTO_INCREMENT,
-> username VARCHAR(50) NOT NULL UNIQUE,
-> email VARCHAR(100) NOT NULL UNIQUE,
-> created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
-> );
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> CREATE TABLE Messages (
-> message_id INT PRIMARY KEY AUTO_INCREMENT,
-> user_id INT NOT NULL,
-> message_content TEXT NOT NULL,
-> posted_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
-> FOREIGN KEY (user_id) REFERENCES Users(user_id)
-> );
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> CREATE TABLE Admin (
-> admin_id INT PRIMARY KEY AUTO_INCREMENT,
-> admin_username VARCHAR(50) NOT NULL UNIQUE,
-> admin_password VARCHAR(255) NOT NULL,
-> email VARCHAR(100) NOT NULL UNIQUE,
-> created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
-> );
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> INSERT INTO Users (username, email) VALUES
-> ('john_doe', '[email protected]'),
-> ('jane_smith', '[email protected]'),
-> ('alice_wonder', '[email protected]'),
-> ('bob_builder', '[email protected]'),
-> ('charlie_brown', '[email protected]');
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql>
mysql> INSERT INTO Messages (user_id, message_content) VALUES
-> (1, 'Hello, this is John!'),
-> (2, 'Hi everyone, Jane here!'),
-> (3, 'Alice says hi to all!'),
-> (4, 'Bob wants to join the chat.'),
-> (5, 'Charlie is happy to be here!'),
-> (1, 'Another message from John.'),
-> (2, 'Jane is posting again.'),
-> (3, 'Alice loves this guestbook!'),
-> (4, 'Bob has more to say.'),
-> (5, 'Charlie just can’t stop talking!');
Query OK, 10 rows affected (0.00 sec)
Records: 10 Duplicates: 0 Warnings: 0
mysql>
mysql> INSERT INTO Admin (admin_username, admin_password, email) VALUES
-> ('admin1', 'securepassword1', '[email protected]'),
-> ('admin2', 'securepassword2', '[email protected]');
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql>
mysql> SHOW TABLES;
+---------------------+
| Tables_in_guestbook |
+---------------------+
| Admin |
| Messages |
| Users |
+---------------------+
3 rows in set (0.01 sec)