Skip to content

Instantly share code, notes, and snippets.

@des-virus
Created November 6, 2017 04:34
Show Gist options
  • Save des-virus/6242192a4384349d3e43ef2bff2351ad to your computer and use it in GitHub Desktop.
Save des-virus/6242192a4384349d3e43ef2bff2351ad to your computer and use it in GitHub Desktop.
Database SQL
--
-- Cấu trúc bảng cho bảng `category`
--
CREATE TABLE `category` (
`id` int(11) NOT NULL,
`name` text COLLATE utf8_unicode_ci NOT NULL,
`note` text COLLATE utf8_unicode_ci NOT NULL,
`is_deleted` tinyint(1) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- --------------------------------------------------------
--
-- Cấu trúc bảng cho bảng `customer`
--
CREATE TABLE `customer` (
`id` int(11) NOT NULL,
`name` text COLLATE utf8_unicode_ci NOT NULL,
`note` text COLLATE utf8_unicode_ci NOT NULL,
`is_deleted` tinyint(1) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- --------------------------------------------------------
--
-- Cấu trúc bảng cho bảng `order_in`
--
CREATE TABLE `order_in` (
`id` int(11) NOT NULL,
`staff_id` int(11) NOT NULL,
`provider_id` int(11) NOT NULL,
`date` datetime NOT NULL,
`note` text COLLATE utf8_unicode_ci NOT NULL,
`is_deleted` tinyint(1) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- --------------------------------------------------------
--
-- Cấu trúc bảng cho bảng `order_in_detail`
--
CREATE TABLE `order_in_detail` (
`order_in_id` int(11) NOT NULL,
`product_id` int(11) NOT NULL,
`product_quantity` int(11) NOT NULL,
`product_price` double NOT NULL,
`note` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- --------------------------------------------------------
--
-- Cấu trúc bảng cho bảng `order_out`
--
CREATE TABLE `order_out` (
`id` int(11) NOT NULL,
`staff_id` int(11) NOT NULL,
`customer_id` int(11) NOT NULL,
`date` datetime NOT NULL,
`note` text COLLATE utf8_unicode_ci NOT NULL,
`is_deleted` tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- --------------------------------------------------------
--
-- Cấu trúc bảng cho bảng `order_out_detail`
--
CREATE TABLE `order_out_detail` (
`order_out_id` int(11) NOT NULL,
`product_id` int(11) NOT NULL,
`product_quantity` int(11) NOT NULL,
`product_price` double NOT NULL,
`note` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- --------------------------------------------------------
--
-- Cấu trúc bảng cho bảng `product`
--
CREATE TABLE `product` (
`id` int(11) NOT NULL,
`cat_id` int(11) NOT NULL,
`name` text COLLATE utf8_unicode_ci NOT NULL,
`price` double NOT NULL,
`note` text COLLATE utf8_unicode_ci NOT NULL,
`is_deleted` tinyint(1) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- --------------------------------------------------------
--
-- Cấu trúc bảng cho bảng `provider`
--
CREATE TABLE `provider` (
`id` int(11) NOT NULL,
`name` text COLLATE utf8_unicode_ci NOT NULL,
`note` text COLLATE utf8_unicode_ci NOT NULL,
`is_deleted` tinyint(1) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- --------------------------------------------------------
--
-- Cấu trúc bảng cho bảng `staff`
--
CREATE TABLE `staff` (
`id` int(11) NOT NULL,
`name` text COLLATE utf8_unicode_ci NOT NULL,
`username` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`password` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`note` int(11) NOT NULL,
`is_active` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- Chỉ mục cho các bảng đã đổ
--
--
-- Chỉ mục cho bảng `category`
--
ALTER TABLE `category`
ADD PRIMARY KEY (`id`);
--
-- Chỉ mục cho bảng `customer`
--
ALTER TABLE `customer`
ADD PRIMARY KEY (`id`);
--
-- Chỉ mục cho bảng `order_in`
--
ALTER TABLE `order_in`
ADD KEY `FK_OrderIn_OrderInDetail` (`id`),
ADD KEY `staff_id` (`staff_id`),
ADD KEY `provider_id` (`provider_id`);
--
-- Chỉ mục cho bảng `order_in_detail`
--
ALTER TABLE `order_in_detail`
ADD KEY `order_in_id` (`order_in_id`);
--
-- Chỉ mục cho bảng `order_out`
--
ALTER TABLE `order_out`
ADD PRIMARY KEY (`id`),
ADD KEY `customer_id` (`customer_id`),
ADD KEY `staff_id` (`staff_id`);
--
-- Chỉ mục cho bảng `order_out_detail`
--
ALTER TABLE `order_out_detail`
ADD KEY `order_out_id` (`order_out_id`);
--
-- Chỉ mục cho bảng `product`
--
ALTER TABLE `product`
ADD PRIMARY KEY (`id`),
ADD KEY `cat_id` (`cat_id`);
--
-- Chỉ mục cho bảng `provider`
--
ALTER TABLE `provider`
ADD PRIMARY KEY (`id`);
--
-- Chỉ mục cho bảng `staff`
--
ALTER TABLE `staff`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `username_unique` (`username`);
--
-- AUTO_INCREMENT cho các bảng đã đổ
--
--
-- AUTO_INCREMENT cho bảng `category`
--
ALTER TABLE `category`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT cho bảng `customer`
--
ALTER TABLE `customer`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT cho bảng `order_out`
--
ALTER TABLE `order_out`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT cho bảng `product`
--
ALTER TABLE `product`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT cho bảng `provider`
--
ALTER TABLE `provider`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT cho bảng `staff`
--
ALTER TABLE `staff`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- Các ràng buộc cho các bảng đã đổ
--
--
-- Các ràng buộc cho bảng `category`
--
ALTER TABLE `category`
ADD CONSTRAINT `FK_Category_Product` FOREIGN KEY (`id`) REFERENCES `product` (`cat_id`);
--
-- Các ràng buộc cho bảng `order_in`
--
ALTER TABLE `order_in`
ADD CONSTRAINT `FK_OrderIn_OrderInDetail` FOREIGN KEY (`id`) REFERENCES `order_in_detail` (`order_in_id`),
ADD CONSTRAINT `order_in_ibfk_1` FOREIGN KEY (`provider_id`) REFERENCES `provider` (`id`),
ADD CONSTRAINT `order_in_ibfk_2` FOREIGN KEY (`staff_id`) REFERENCES `staff` (`id`);
--
-- Các ràng buộc cho bảng `order_out`
--
ALTER TABLE `order_out`
ADD CONSTRAINT `order_out_ibfk_1` FOREIGN KEY (`staff_id`) REFERENCES `staff` (`id`),
ADD CONSTRAINT `order_out_ibfk_2` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`);
--
-- Các ràng buộc cho bảng `order_out_detail`
--
ALTER TABLE `order_out_detail`
ADD CONSTRAINT `order_out_detail_ibfk_1` FOREIGN KEY (`order_out_id`) REFERENCES `order_out` (`id`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment