This repository has been archived on 2026-09-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
ku-web-comp/DATABASE.md
T
2026-09-20 13:07:50 +07:00

4.1 KiB

// SQL-compatible database

CREATE TABLE item (itemId INT UNSIGNED NOT NULL AUTO_INCREMENT, image VARCHAR(256) NOT NULL, title VARCHAR(128) NOT NULL, price DECIMAL(7,3) NOT NULL, description TEXT NOT NULL, PRIMARY KEY (itemId), UNIQUE KEY (title) );

CREATE TABLE comment (commentId INT UNSIGNED NOT NULL AUTO_INCREMENT, usernameId INT UNSIGNED NOT NULL, itemId INT UNSIGNED NOT NULL, comment TEXT, PRIMARY KEY (commentId), FOREIGN KEY (usernameId) REFERENCES user(usernameId), FOREIGN KEY (itemId) REFERENCES item(itemId) );

CREATE TABLE star (starId INT UNSIGNED NOT NULL AUTO_INCREMENT, usernameId INT UNSIGNED NOT NULL, itemId INT UNSIGNED NOT NULL, star DECIMAL(2,2) UNSIGNED, PRIMARY KEY (starId), FOREIGN KEY (usernameId) REFERENCES user(usernameId), FOREIGN KEY (itemId) REFERENCES item(itemId) );

CREATE TABLE user (usernameId INT UNSIGNED NOT NULL AUTO_INCREMENT, username VARCHAR(16) NOT NULL, PRIMARY KEY (usernameId), UNIQUE KEY (username) );

// SAMPLE DATA

// Users (to be honest, a FAKE user.) // Sample // INSERT user(usernameId, username) VALUES(1,'Diskette');

INSERT user VALUES (1,'Diskette'), (2,'NorthEatGrass'), (3,'KPJR'), (4,'DuckyWay'), (5,'Tacklezaza'), (6,'NuRedFox'), (7,'Dan'), (8,'LinesOfCodes'), (9,'IcePha'), (10,'Ind') ;

// Items/Product, whatever you call it // Sample // INSERT item(itemId, image, title, description, price) VALUES(1,'icecream.png','nICE CREAM','The patent pending nICE CREAM is really really good Ice Cream product, its so good that you'll even forget what it was',25)

INSERT item(itemId, image, title, description, price) VALUES (1,'icecream.png','nICE CREAM','The patent pending nICE CREAM is really really good Ice Cream product, its so good that you'll even forget what it was',25.00), (2,'deathknife.png','Death Knife','Instant kill knife, not recommended near kids and children. This knife is from the hit-game, UNDERTALE. With the functional killer blade that will murder any victim instantly. Please note that we are not responsible for the damages caused by the usage of this knife',9999.99), (3,'weaklaptop.png','TrashBook 9000','This laptop is equipped with Incel Celery 9000m low-end with 512MiB of DDR2 memory and 240p web camera. Suitable for home schooling',6000.00), (4,'chattop.png','ChadBook T12000','This laptop is equipped with AMB Riser 10-9990k with 64GiB of DDR6L memory and gaming keyboard that will bind your eyes. Suitable for multiple VM workloads',50000.00), (5,'console.png','Gaming console Pro Max','Super hyper ultra pro max retina XDR gaming console with 128GiB of memory, runs at 8GHz with super-hyper threading and it can render 16k resolution at 1 frames per second',35000.00), (6,'portablepc.png','Portable PC','Portable mini computer for use anywhere, with it using Incel Core n5-9000m with Novideo Forces 9800m 512MiB of VRAM',10000.00), (7,'processor.png','Core Super m9-19990kxt','A super high performance ultra super duper retina XDR product thingy, I'm just typing here because I do not have a placeholder. Oh wait, I do. Notice that the keyword INTO was added here. This is optional and has no effect on MariaDB. It's only a matter of grammatical preference. In this example we not only name the columns, but we list them in a different order. This is acceptable to MariaDB. Just be sure to list the values in the same order. An INSERT statement takes priority over read statements (i.e., SELECT statements). An INSERT will lock the table and force other clients to wait until it's finished. On a busy MariaDB server that has many simultaneous requests for data, this could cause users to experience delays when you run a script that performs a series of INSERT statements',90000.00);

// Star // Sample // INSERT star(starId, usernameId, itemId, star) VALUES(1,1,1,5.0);

INSERT star(starId, usernameId, itemId, star) VALUES (1,1,1,5.0), (2,5,1,4.0), (3,2,1,1.0), (4,5,2,4.5), (5,6,2,1.0), (6,7,3,2.5), (7,4,3,5.0), (8,8,4,4.0), (9,2,4,1.0), (10,3,5,4.5), (11,9,6,1.0), (12,10,6,2.5), (13,4,7,5.0);

INSERT star(starId, usernameId, itemId, star) VALUES (1,1,1,5), (2,5,1,4), (3,2,1,1), (4,5,2,4.5), (5,6,2,1), (6,7,3,2.5), (7,4,3,5), (8,8,4,4), (9,2,4,1), (10,3,5,4.5), (11,9,6,1), (12,10,6,2.5), (13,4,7,5);