Yêu cầu thiết kế hệ thống quản trị CSDL cho một của hàng thời trang tại hà nôi
- Thiết kế bảng product gồm các trường
id : trường khoá chính tự tăng
title : tên sản phẩm
thumbnail : đường dẫn hình ảnh
content : kiểu longtext
- Thiết kế bảng danh mục sản phẩm gồm các trường
id : trường khoá tự tăng
name : tên danh mục
- Bổ sung các cột vào bảng sản phẩm
price : giá bán
num: số lượng hàng tồn kho
created_at : ngày đăng sản phẩm
updated_at : ngày sửa thông tin sản phẩm
id_cat : id danh mục => liên kết với column id trong bảng danh mục sản phẩm
Yêu cầu:
Tạo bảng theo thứ tự yêu cầu trên
Thêm 5 sản phẩm vào bảng sản phẩm & 3 sản phầm vào bảng danh mục sản phẩm
sửa giá bán price = 5000 với điều kiện giá bán đang = 0 hoặc rỗng hoặc null
sửa giá bán => giảm 10% giá bán với các sản phẩm đăng trước ngày 2020/06/06 (Ví dụ sản phẩm A có giá 50$ => sản 10% sẽ có giá là : 45$)
Xoá sản phẩm đăng trước ngày 2016/12/31
Theo dõi cập nhật nội dung học trên Youtube
Nguyễn Hữu Hiếu [T2008A]
Ngày viết: 15:56 15/12/2020
create database 1770
use 1770
create table product (
id int primary key identity(1,1),
tilte nvarchar(250),
thumbnail nvarchar(500),
content text,
price money,
num int,
created_at date,
update_at date,
id_category int references category(id)
)
create table category(
id int primary key identity(1,1),
name nvarchar(250)
)
insert into category(name)
values
('Ca phe'),
('Banh'),
('Bia'),
('Keo'),
('Nuoc')
insert into product (tilte,thumbnail,content,price,num,created_at,update_at,id_category)
values
('Ca phe G7','g7.png','Ca phe pha san',32000,20,'2020-09-15','2020-10-20',1),
('Danisa','da.png','Banh ngon lam',1122000,20,'2020-09-20','2020-10-20',2),
('Danisa','da.png','Banh ngon lam',1122000,20,'2020-09-15','2020-10-20',2),
('Danisa','da.png','Banh ngon lam',1122000,20,'2020-09-15','2020-10-20',2),
('Danisa','da.png','Banh ngon lam',1122000,20,'2020-09-15','2020-10-20',2)
select * from product
DELETE FROM product WHERE created_at <= '2020-09-15'
Nguyễn Anh Vũ [T2008A]
Ngày viết: 13:42 30/11/2020
create database BT1770
go
use BT1770
go
create table product (
id int primary key identity(1, 1),
title nvarchar(100),
thumbnail nvarchar(500),
content text
)
go
create table Sanpham (
id int primary key identity(1, 1),
name nvarchar(100) not null
)
go
alter table Sanpham
add price float,
num int,
created_at date,
updated_at date
alter table Sanpham
add id_cat int
select * from product
select * from Sanpham
insert into product(title, thumbnail, content)
values
('Ao da bong 1', 'https://www.sporter.vn/wp-content/uploads/2017/06/Ao-mu-san-nha-1-2-300x300.jpg', 'San pham 1'),
('Ao da bong 2', 'https://www.sporter.vn/wp-content/uploads/2017/06/Ao-mu-san-khach-1-3.jpg', 'San pham 2'),
('Ao da bong 3', 'https://dothethao.net.vn/wp-content/uploads/2020/04/ao-dau-ngoai-hang-anh-2020-manchester-united.jpg', 'San pham 3'),
('Ao da bong 4', 'https://cf.shopee.vn/file/6b93b5930502a32ea5769943909fb175', 'San pham 4'),
('Ao da bong 5', 'https://thumblr.uniid.it/product/186829/928d42dae20c.jpg', 'San pham 5')
insert into Sanpham(name, price, num, created_at, updated_at, id_cat)
values
('Ao 1', 120.000, 12, '2020-11-12', '2020-11-23', 1),
('Ao 2', 120.000, 12, '2020-11-12', '2020-11-23', 2),
('Ao 3', 120.000, 12, '2020-11-12', '2020-11-23', 3),
('Ao 4', 120.000, 12, '2020-11-12', '2020-11-23', 4),
('Ao 5', 120.000, 12, '2020-11-12', '2020-11-23', 5)
update Sanpham
set price = 5000 where price in (0,null,'')
Trần Văn Lâm [T2008A]
Ngày viết: 21:43 28/11/2020
create database quan_li_ban_hang
use quan_li_ban_hang
create table product(
id int primary key identity(1,1),
title nvarchar(50),
thumbnail nvarchar(500),
content text,
)
create table product_directory(
id int identity(1,1),
name nvarchar(50)
)
select * from product
select * from product_directory
alter table product
add price int,
num int,
created_at date,
updated_at date,
id_cat int
insert into product(title,thumbnail,content,price,num,created_at,updated_at,id_cat)
values
('Dao','urlaaa','abcxyz','3000','3','2020-5-5','2020-6-5',1),
('Dao','urlaaa','abcxyz','3000','3','2020-5-5','2020-6-5',2),
('Dao','urlaaa','abcxyz','3000','3','2020-5-5','2020-6-5',3),
('Dao','urlaaa','abcxyz','3000','3','2020-5-5','2020-6-5',4),
('Dao','urlaaa','abcxyz','3000','3','2020-5-5','2020-6-5',5)
insert into product_directory(name)
values
('abc'),
('abc'),
('abc'),
('abc'),
('abc')
update product
set price = 5000
where price = 3000
select * from product
update product
set price = price - price*0.1
where created_at <= '2020-06-05'
Trần Thị Khánh Huyền [T2008A]
Ngày viết: 15:43 27/11/2020
CREATE DATABASE BT1770
CREATE TABLE product(
id varchar(4) PRIMARY KEY,
title varchar(50),
thumbnail varchar(500),
content longtext
)
CREATE TABLE product_list(
id varchar(4) PRIMARY KEY,
name varchar(200)
)
ALTER TABLE product
ADD price varchar(50);
ALTER TABLE product
ADD num varchar(50);
ALTER TABLE product
ADD created_at date;
ALTER TABLE product
ADD updated_at date;
ALTER TABLE product
ADD id_cat varchar(10);
INSERT INTO product (id, title, thumbnail, content, price, num, created_at, updated_at, id_cat)
VALUES('1','SP1','123','abcd', '500', '50', '2020/08/09', '2020/10/10', 'A'),
('2','SP2','124','abce', '500', '0', '2020/02/02', '2020/10/10', 'A'),
('3','SP3','125','abcf', '500', '50', '2020/08/10', '2020/10/10', 'B'),
('4','SP4','126','abcg', '500', '50', '2020/02/09', '2020/10/10', 'B'),
('5','SP5','127','abch', '500', '50', '2020/09/09', '2020/10/10', 'B')
INSERT INTO product_list (id, name)
VALUES ('A', 'SP1'),
('B', 'SP2'),
('C' 'SP3')
UPDATE product
set price=5000,
where price='0' or price='' or price='null'
UPDATE product
set price=price*0.9
where created_at<2020/06/06
DELETE product where created_at <2016/12/31
Triệu Văn Lăng [T2008A]
Ngày viết: 15:03 27/11/2020
create database bt1770
use bt1770
create table product (
id int primary key identity(1,1),
title nvarchar(100),
thumbnail nvarchar(500),
content text
)
go
create table danhmuc (
id int primary key identity(1,1),
name nvarchar(100)
)
go
alter table product
add price float,
num int,
created_at datetime,
update_at datetime;
alter table product
add id_cat int
alter table product
add constraint fk_id_cat foreign key (id_cat) references danhmuc(id)
select * from product
select * from danhmuc
insert into danhmuc(name)
values
('Iphone'),
('Oppo'),
('Samsung')
insert into product(title, thumbnail, content, price, num, created_at, update_at, id_cat)
values
('Iphone 11', 'url_ip1', 'san pham 1', '1000', '10', '2020-11-26 8:00:00', '2020-12-30 23:59:00', '1'),
('Iphone 11 promax', 'url_ip2', 'san pham 1', '2000', '10', '2020-11-26 8:00:00', '2020-12-30 23:59:00', '1'),
('Iphone 11 pro', 'url_ip3', 'san pham 1', '3000', '10', '2020-11-26 8:00:00', '2020-12-30 23:59:00', '1'),
('Iphone 12', 'url_ip4', 'san pham 1', '4000', '10', '2020-11-26 8:00:00', '2020-12-30 23:59:00', '1'),
('Iphone 12 promax', 'url_ip5', 'san pham 1', '5000', '10', '2020-11-26 8:00:00', '2020-12-30 23:59:00', '1')
insert into product(title, thumbnail, content, price, num, created_at, update_at, id_cat)
values
('Oppo reno 3', 'url_op1', 'san pham 2', '1100', '10', '2020-11-26 8:00:00', '2020-12-30 23:59:00', '2'),
('Oppo reno 4', 'url_op2','san pham 2', '2200', '10', '2020-11-26 8:00:00', '2020-12-30 23:59:00', '2'),
('Oppo reno 3 pro', 'url_op3', 'san pham 2', '3300', '10', '2020-11-26 8:00:00', '2020-12-30 23:59:00', '2'),
('Oppo reno 4 pro', 'url_op4', 'san pham 2', '4400', '10', '2020-11-26 8:00:00', '2020-12-30 23:59:00', '2'),
('Oppo reno 3 promax', 'url_op5', 'san pham 2', '5500', '10', '2020-11-26 8:00:00', '2020-12-30 23:59:00', '2')
insert into product(title, thumbnail, content, price, num, created_at, update_at, id_cat)
values
('Samsung 1', 'url_ss1', 'san pham 3', '1500', '10', '2020-11-26 8:00:00', '2020-12-30 23:59:00', '3'),
('Samsung 2', 'url_ss2', 'san pham 3', '2500', '10', '2020-11-26 8:00:00', '2020-12-30 23:59:00', '3'),
('Samsung 3', 'url_ss3', 'san pham 3', '3500', '10', '2020-11-26 8:00:00', '2020-12-30 23:59:00', '3'),
('Samsung 4', 'url_ss4', 'san pham 3', '4500', '10', '2020-11-26 8:00:00', '2020-12-30 23:59:00', '3'),
('Samsung 5', 'url_ss5', 'san pham 3', '5500', '10', '2020-11-26 8:00:00', '2020-12-30 23:59:00', '3')