Mã nguồn

Khóa học SQL Server cơ bản: Tạo CSDL và Tables

Script tạo Cơ sở dữ liệu và các bảng phục vụ khóa học SQL Server cơ bản

CREATE DATABASE IT1PHUT_2021
 GO
 USE  IT1PHUT_2021
 GO
SET QUOTED_IDENTIFIER ON
GO
 
CREATE TABLE [dbo].[tblNhomHanghoa](
[NHH_ID] [uniqueidentifier] NOT NULL CONSTRAINT [DF_tblNhomHanghoa_NHH_ID]  DEFAULT (newid()),
[NHH_MA] [nvarchar](50) NULL,
[NHH_TEN] [nvarchar](250) NULL,
[NHH_ACTIVE] [int] NULL CONSTRAINT [DF_tblNhomHanghoa_NHH_ACTIVE]  DEFAULT ((1)),
[NHH_NGAYTAO] [datetime] NULL CONSTRAINT [DF_Table_1_HH_NGAYTAO]  DEFAULT (getdate()),
[NHH_NGUOITAO] [nvarchar](50) NULL,
[NHH_NGAYSUA] [datetime] NULL,
[NHH_NGUOISUA] [nvarchar](50) NULL,
 CONSTRAINT [PK_tblNhomHanghoa] PRIMARY KEY CLUSTERED 
(
[NHH_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
 
GO
 
 
CREATE TABLE [dbo].[tblHanghoa](
[HH_ID] [uniqueidentifier] NOT NULL CONSTRAINT [DF_tblHanghoa_HH_ID]  DEFAULT (newid()),
[HH_MA] [nvarchar](50) NULL,
[HH_TEN] [nvarchar](250) NULL,
[HH_DONVI] [nvarchar](10) NULL,
[HH_GIANHAP] [float] NULL,
[HH_GIABAN] [float] NULL,
[HH_NHH_ID] [uniqueidentifier] NULL,
[HH_ACTIVE] [int] NULL CONSTRAINT [DF_tblHanghoa_HH_ACTIVE]  DEFAULT ((1)),
[HH_NGAYTAO] [datetime] NULL CONSTRAINT [DF_tblHanghoa_HH_NGAYTAO]  DEFAULT (getdate()),
[HH_NGUOITAO] [nvarchar](50) NULL,
[HH_NGAYSUA] [datetime] NULL,
[HH_NGUOISUA] [nvarchar](50) NULL,
[LOAI] [float] NULL CONSTRAINT [DF_tblHanghoa_LOAI]  DEFAULT ((10)),
[thutu] [int] IDENTITY(1,1) NOT NULL,
[hh_ten_timkiem] [nvarchar](1000) NULL,
[HH_Soton] [float] NULL,
 CONSTRAINT [PK_tblHanghoa] PRIMARY KEY CLUSTERED 
(
[HH_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
 
GO
 
ALTER TABLE [dbo].[tblHanghoa]  WITH NOCHECK ADD  CONSTRAINT [FK_tblHanghoa_tblNhomHanghoa] FOREIGN KEY([HH_NHH_ID])
REFERENCES [dbo].[tblNhomHanghoa] ([NHH_ID])
ON UPDATE SET DEFAULT
ON DELETE SET DEFAULT
GO
 
ALTER TABLE [dbo].[tblHanghoa] NOCHECK CONSTRAINT [FK_tblHanghoa_tblNhomHanghoa]
GO
 
 
GO