0% found this document useful (0 votes)
3 views

Create Database QLBH

The document outlines the creation of a database named QLBH, which includes multiple tables for managing inventory, suppliers, purchase orders, and stock levels. It defines the structure of tables such as tblVATTU for items, tblNHACC for suppliers, and tblDONDH for purchase orders, along with their relationships through foreign keys. Additionally, it includes sample data insertion for these tables to populate the database.

Uploaded by

sangpro9110
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Create Database QLBH

The document outlines the creation of a database named QLBH, which includes multiple tables for managing inventory, suppliers, purchase orders, and stock levels. It defines the structure of tables such as tblVATTU for items, tblNHACC for suppliers, and tblDONDH for purchase orders, along with their relationships through foreign keys. Additionally, it includes sample data insertion for these tables to populate the database.

Uploaded by

sangpro9110
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

create database QLBH

go
use QLBH
go
create table tblVATTU
(
MaVTu char(4)
primary key (Mavtu),
TenVtu nvarchar(30),
DVTinh nvarchar(10),
Dongia int
)
go

create table tblNHACC


( Manhacc char(4)
primary key (manhacc),
Tennhacc nvarchar(30),
Diachi nvarchar(30),
Dienthoai char(15)
)
go

create table tblDONDH


(
SoDH Int
primary key (SoDH),
NgayDH datetime,
Manhacc char(4),
FOREIGN KEY (Manhacc) REFERENCES tblNHACC (Manhacc)
)
go

create table tblCTDONDH


(
SoDH Int,
MaVTu char(4)
primary key (SoDH,MaVTu ),
SLDat int,
FOREIGN KEY (SoDH) REFERENCES tblDONDH (SoDH),
FOREIGN KEY (MaVTu) REFERENCES tblVATTU (MaVTu)
)
go

create table tblPNHAP


(
SoPN char(4)
primary key (SoPN),
SoDH int,
Ngaynhap datetime,
FOREIGN KEY (SoDH) REFERENCES tblDONDH (SoDH)
)
go

create table tblCTPNHAP


(
SoPN char(4),
MaVTu char(4)
primary key (SoPN,MaVTu),
Slnhap int,
FOREIGN KEY (SoPN) REFERENCES tblPNHAP (SoPN),
FOREIGN KEY (MaVTu) REFERENCES tblVATTU (MaVTu)
)
go

create table tblPXUAT


(
SoPX char(4)
primary key (SoPX),
Ngayxuat datetime
)

go

create table tblCTPXUAT


(
SoPX char(4),
MaVTu char(4)
primary key (SoPX,MaVTu),
SLXuat int
FOREIGN KEY (MaVTu) REFERENCES tblVATTU (MaVTu),
FOREIGN KEY (SoPX) REFERENCES tblPXUAT (SoPX)
)
go

create table tblTONKHO


(
NAMTHANG char(7),
MaVTu char(4),
TONGNHAP int,
TONGXUAT int,
SLTonkho int,
FOREIGN KEY (MaVTu) REFERENCES tblVATTU (MaVTu)
)

go

INSERT INTO tblVATTU Values


('DD01',N'Đầu DVD Hitachi',N'gnhg', 145),
('DD02',N'Dầu DVD Samsung',N'nhg', 78),
('DD03',N'Đầu DVD Sony',N'gnhg', 5),
('LO01',N'Loa thùng Hitachi',N'vhb', 123),
('LO02',N'Loa thùng Sony',N'tan', 44),
('LO03',N'Loa thùng Sanyo',N'chiế c', 20),
('TV01',N'Tivi Sony',N'chiế c', 10),
('TV02',N'Tivi Sanyo',N'chiế c', 45),
('VD01',N'Đầu VCD Hitachi',N'chiế c', 98),
('VD02',N'Dầu VCD Sanyo',N'chiế c', 77),
('VT01',N'Gạch',N'Viên', 200),
('VT02',N'Ngói',N'Viên', 9),
('VT03',N'Xi măng',N'kg', 13),
('VT04',N'Sắt',N'kg', 80),
('VT05',N'Vôi',N'tấn', 9),
('VT06',N'Sơn',N'thùng', 45)
go

INSERT INTO tblNHACC Values


(N'CC01', N'Công ty X', N'Thanh Hóa', '03931234567'),
(N'CC02', N'Xây dựng Bình Minh', N'282 Trầ n Hưng Đạo, Hà Nội',
'048951320'),
(N'CC03', N'Cơ khí dân dụng', N'43 Lê Văn Sỹ, Nha Trang',
'0588512230'),
(N'CC04', N'Vật tư thiế t bị GTVT', N'94 Điện Biên Phủ,Hà Nội',
'048533710'),
(N'CC05', N'Cơ Phát', N'129 Nguyễ n Du,Hải Phòng','0318601234'),
(N'CC06', N'Nguyễ n Văn An ', N'129 Nguyễn Du,Hải
Phòng','0318601234'),
(N'CC07', N' Lê B', N'129 Nguyễ n Du,Hải Phòng','0318601234'),
(N'CC08', N' Phạm C ', N'129 Nguyễ n Du,Hải Phòng','0318601234'),
(N'CC09', N' Phạm Nghị ', N'129 Nguyễ n Du,Hải
Phòng','0318601234'),
(N'CC10', N'Hồ ng Ánh', N'129 Nguyễn Du,Hải Phòng','0318601234'),
(N'CC11', N'Nguyễ n Cường', N'129 Nguyễn Du,Hải
Phòng','0318601234'),
(N'CC12', N'Nguyễ n Thế', N'129 Nguyễn Du,Hải
Phòng','0318601234')
go
INSERT INTO tblDONDH Values
( 1, '1-5-2012', 'CC01'),
( 2, '2-7-2012', 'CC02'),
( 3, '7-15-2012', 'CC01'),
( 4, '6-4-2012', 'CC03'),
( 5, '7-8-2012', 'CC04'),
( 6, '9-10-2012','CC01'),
(7,'2012-05-01','CC05'),
(8,'2012-07-15','CC06'),
(9,'2012-07-15','CC07'),
(10,'2012-04-06','CC03'),
(11,'2012-08-07','CC04'),
(12,'2014-03-03','CC05'),
(13,'2014-03-03','CC01'),
(15,'2014-01-01','CC01')
go

INSERT INTO tblCTDONDH Values


(1,'VT01',100),
(1,'VT02',400),
(1,'vt03',700),
(1,'vt04',100),
(1,'vt06',100),
(2,'VT01',80),
(2,'VT02',3),
(2,'vt03',90),
(3,'VT01',250),
(3,'VT02',500),
(3,'VT03',50),
(3,'VT04',49),
(3,'VT05',2),
(4,'VT01',100),
(4,'VT02',70),
(4,'VT03',50),
(5,'VT01',100),
(5,'VT03',300),
(6,'VT01',50),
(6,'VT02',100),
(6,'VT03',50),
(6,'VT04',500),
(6,'vt05',100),
(7,'vt01',80),
(15,'VT01',80),
(15,'VT02',15),
(15,'VT03',17),
( 8, 'VT01',100),
( 8, 'VT02',150),
( 8, 'VT03',120),
( 9, 'VT01',80),
( 9, 'VT04',200),
( 9, 'VT02',500),
( 9, 'VT03',50),
( 10,'VT01',100),
( 10,'VT02',70),
( 10,'VT03',50),
( 11,'VT03',300),
( 11,'VT01',50)
go

INSERT INTO tblPNHAP Values


('PN01',1,'2012-07-08'),
('PN02',1,'2012-08-12'),
('PN03',1,'2012-07-12'),
('PN04',2,'2012-10-02'),
('PN05',2,'2012-07-15'),
('PN06',3,'2012-09-01'),
('PN07',4,'2012-05-03'),
('PN08',5,'2012-09-02'),
('PN09',5,'2012-10-02'),
('PN10',6,'2013-01-31'),
('pn11',8,'2014-03-03'),
('pn12',5,'2014-03-03'),
('PN13',15,'2017-04-20'),
('PN14',15,'2017-04-20'),
('PN16',15,'2017-04-20'),
('PN17',1,'2017-04-20'),
('PN18',1,'2017-04-20'),
('PN19',1,'2017-04-20'),
('PN20',15,'2017-04-03'),
('pn24',15,'2015-02-02'),
('PN26',3,'2017-12-03'),
('pn34',12,'2010-12-03')

go

insert into tblCTPNhap values


('PN01','VT01',20),
('PN01','VT02',50),
('PN01','VT03',30),
('pn01','vt06',100),
('PN02','VT01',30),
('PN02','VT03',50),
('pn02','vt04',345),
('pn02','vt05',35),
('PN03','VT01',20),
('PN03','VT02',80),
('PN03','VT03', 40),
('PN04','VT01',80),
('PN05','VT04',150),
('PN06','VT02',500),
('PN06','VT03',50),
('PN07','VT01',100),
('PN07','VT02',50),
('PN07','VT03',50),
('PN08','VT03',120),
('PN09','VT03',150),
('PN10','VT01',50),
('PN10','VT02',190),
('pn10','vt05',67),
('PN11','VT01', 50),
('PN11','VT02', 20),
('PN12','VT02', 30),
('PN12','VT03', 100),
('PN13','VT02', 100),
('PN13','VT03', 20),
('PN14','VT01', 80),
('PN14','VT04', 100),
('PN16','VT02', 400),
('PN16','VT03', 50),
('PN17','VT01', 100),
('PN17','VT02', 50),
('PN17','VT03', 50),
('PN18','VT03', 150),
('PN19','VT03', 100),
('PN20','VT01', 50)
go

INSERT INTO tblPXUAT Values


('PX01','2012-07-02'),
('PX02','2013-04-06'),
('PX03','2013-04-06'),
('PX04','2011-01-01'),
('PX05','2015-03-03'),
('PX06','2015-03-03')
go
INSERT INTO tblCTPXUAT Values
('PX01','VT01',300),
('PX01','VT03',500),
('PX02','VT01',100),
('PX02','VT02',40),
('PX02','VT03',50),
('px02','vt05',35),
('PX03','VT01',100),
('PX03','VT02',60),
('PX03','VT03',200),
('PX03','VT04',50),
('px04','vt01',60),
('px05','vt01',55),
('px05','vt02',6666),
('px06','vt03',20),
('px06','vt01',30)

You might also like