MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
Katta hajmli ma’lumotlat
Amaliy ish №1
Bajardi: Qosimov Sherzodbek
Tekshirdi: Abdug‘aniyev Muxriddin
Guruh: 223-21
TOSHKENT 2023
Mavzu: Ma’lumolar bazasining strukturasini tashkil etish
Online kitob savdosi ma’lumotlar bazasining strukturasini qurdim.
PostgreSQL dagi kodi:
CREATE TABLE "categories" (
"id" serial PRIMARY KEY,
"name" varchar(255)
);
CREATE TABLE "books" (
"id" serial PRIMARY KEY,
"title" varchar(255),
"price" numeric,
"publication_year" integer,
"description" text,
"stock_quantity" integer,
"image_path" varchar(255),
"author_id" integer,
"category_id" integer,
"created_at" timestamp DEFAULT (now()),
"updated_at" timestamp DEFAULT (now()),
"deleted_at" timestamp
);
CREATE TABLE "authors" (
"id" serial PRIMARY KEY,
"full_name" varchar(255),
"biography" text,
"image_path" varchar(255)
);
CREATE TABLE "users" (
"id" serial PRIMARY KEY,
"first_name" varchar(255) NOT NULL,
"last_name" varchar(255),
"phone_number" varchar(13) UNIQUE NOT NULL,
"address" text,
"created_at" timestamp DEFAULT (now())
);
CREATE TABLE "carts" (
"id" serial PRIMARY KEY,
"user_id" integer
);
CREATE TABLE "cart_books" (
"id" serial,
"cart_id" integer,
"book_id" integer,
"quantity" integer
);
ALTER TABLE "books" ADD FOREIGN KEY ("author_id") REFERENCES "authors" ("id");
ALTER TABLE "books" ADD FOREIGN KEY ("category_id") REFERENCES "categories" ("id");
ALTER TABLE "cart_books" ADD FOREIGN KEY ("book_id") REFERENCES "books" ("id");
ALTER TABLE "carts" ADD FOREIGN KEY ("user_id") REFERENCES "users" ("id");
ALTER TABLE "cart_books" ADD FOREIGN KEY ("cart_id") REFERENCES "carts" ("id");
Do'stlaringiz bilan baham: |