Demo entry 6647841

建表

   

Submitted by anonymous on Oct 21, 2017 at 20:13
Language: SQL. Code size: 8.5 kB.

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[REGION]') AND type
in (N'U'))
BEGIN
CREATE TABLE [dbo].[REGION](
[R_REGIONKEY] [int] NOT NULL,
[R_NAME] [char](25) NOT NULL,
[R_COMMENT] [varchar](152) NULL,
CONSTRAINT [PK_REGION] PRIMARY KEY CLUSTERED
(
[R_REGIONKEY] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS =
ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PART]') AND type
in (N'U'))
BEGIN
CREATE TABLE [dbo].[PART](
[P_PARTKEY] [int] NOT NULL,
[P_NAME] [varchar](55) NOT NULL,
[P_MFGR] [char](25) NOT NULL,
[P_BRAND] [char](10) NOT NULL,
[P_TYPE] [varchar](25) NOT NULL,
[P_SIZE] [int] NOT NULL,
[P_CONTAINER] [char](10) NOT NULL,
[P_RETAILPRICE] [decimal](15, 2) NOT NULL,
[P_COMMENT] [varchar](23) NOT NULL,
CONSTRAINT [PK_PART] PRIMARY KEY CLUSTERED
(
[P_PARTKEY] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS =
ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ORDERS]') AND type
in (N'U'))
BEGIN
CREATE TABLE [dbo].[ORDERS](
[O_ORDERKEY] [int] NOT NULL,
[O_CUSTKEY] [int] NOT NULL,[O_CUSTKEY] [int] NOT NULL,
[O_ORDERSTATUS] [char](1) NOT NULL,
[O_TOTALPRICE] [decimal](15, 2) NOT NULL,
[O_ORDERDATE] [datetime] NOT NULL,
[O_ORDERPRIORITY] [char](15) NOT NULL,
[O_CLERK] [char](15) NOT NULL,
[O_SHIPPRIORITY] [int] NOT NULL,
[O_COMMENT] [varchar](79) NOT NULL,
CONSTRAINT [PK_ORDERS_1] PRIMARY KEY CLUSTERED
(
[O_ORDERKEY] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS =
ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[LINEITEM]') AND
type in (N'U'))
BEGIN
CREATE TABLE [dbo].[LINEITEM](
[L_ORDERKEY] [int] NOT NULL,
[L_PARTKEY] [int] NOT NULL,
[L_SUPPKEY] [int] NOT NULL,
[L_LINENUMBER] [int] NOT NULL,
[L_QUANTITY] [decimal](15, 2) NOT NULL,
[L_EXTENDEDPRICE] [decimal](15, 2) NOT NULL,
[L_DISCOUNT] [decimal](15, 2) NOT NULL,
[L_TAX] [decimal](15, 2) NOT NULL,
[L_RETURNFLAG] [char](1) NOT NULL,
[L_LINESTATUS] [char](1) NOT NULL,
[L_SHIPDATE] [datetime] NOT NULL,
[L_COMMITDATE] [datetime] NOT NULL,
[L_RECEIPTDATE] [datetime] NOT NULL,
[L_SHIPINSTRUCT] [char](25) NOT NULL,
[L_SHIPMODE] [char](10) NOT NULL,
[L_COMMENT] [varchar](44) NOT NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CUSTOMER]') AND
type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CUSTOMER](
[C_CUSTKEY] [int] NOT NULL,
[C_NAME] [varchar](25) NOT NULL,
[C_ADDRESS] [varchar](40) NOT NULL,[C_ADDRESS] [varchar](40) NOT NULL,
[C_NATIONKEY] [int] NOT NULL,
[C_PHONE] [char](15) NOT NULL,
[C_ACCTBAL] [decimal](15, 2) NOT NULL,
[C_MKTSEGMENT] [char](10) NOT NULL,
[C_COMMENT] [varchar](117) NOT NULL,
CONSTRAINT [PK_CUSTOMER] PRIMARY KEY CLUSTERED
(
[C_CUSTKEY] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS =
ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SUPPLIER]') AND
type in (N'U'))
BEGIN
CREATE TABLE [dbo].[SUPPLIER](
[S_SUPPKEY] [int] NOT NULL,
[S_NAME] [char](25) NOT NULL,
[S_ADDRESS] [varchar](40) NOT NULL,
[S_NATIONKEY] [int] NOT NULL,
[S_PHONE] [char](15) NOT NULL,
[S_ACCTBAL] [decimal](15, 2) NOT NULL,
[S_COMMENT] [varchar](101) NOT NULL,
CONSTRAINT [PK_SUPPLIER] PRIMARY KEY CLUSTERED
(
[S_SUPPKEY] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS =
ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[NATION]') AND type
in (N'U'))
BEGIN
CREATE TABLE [dbo].[NATION](
[N_NATIONKEY] [int] NOT NULL,
[N_NAME] [char](25) NOT NULL,
[N_REGIONKEY] [int] NOT NULL,
[N_COMMENT] [varchar](152) NULL,
CONSTRAINT [PK_NATION] PRIMARY KEY CLUSTERED
(
[N_NATIONKEY] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS =ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PARTSUPP]') AND
type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PARTSUPP](
[PS_PARTKEY] [int] NOT NULL,
[PS_SUPPKEY] [int] NOT NULL,
[PS_AVAILQTY] [int] NOT NULL,
[PS_SUPPLYCOST] [decimal](15, 2) NOT NULL,
[PS_COMMENT] [varchar](199) NOT NULL,
CONSTRAINT [PK_PARTSUPP] PRIMARY KEY CLUSTERED
(
[PS_PARTKEY] ASC,
[PS_SUPPKEY] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS =
ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].
[FK_ORDERS_CUSTOMER]') AND parent_object_id = OBJECT_ID(N'[dbo].[ORDERS]'))
ALTER TABLE [dbo].[ORDERS] WITH CHECK ADD CONSTRAINT [FK_ORDERS_CUSTOMER] FOREIGN
KEY([O_CUSTKEY])
REFERENCES [dbo].[CUSTOMER] ([C_CUSTKEY])
GO
ALTER TABLE [dbo].[ORDERS] CHECK CONSTRAINT [FK_ORDERS_CUSTOMER]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].
[FK_LINEITEM_ORDERS]') AND parent_object_id = OBJECT_ID(N'[dbo].[LINEITEM]'))
ALTER TABLE [dbo].[LINEITEM] WITH NOCHECK ADD CONSTRAINT [FK_LINEITEM_ORDERS] FOREIGN
KEY([L_ORDERKEY])
REFERENCES [dbo].[ORDERS] ([O_ORDERKEY])
GO
ALTER TABLE [dbo].[LINEITEM] CHECK CONSTRAINT [FK_LINEITEM_ORDERS]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].
[FK_LINEITEM_PARTSUPP]') AND parent_object_id = OBJECT_ID(N'[dbo].[LINEITEM]'))
ALTER TABLE [dbo].[LINEITEM] WITH NOCHECK ADD CONSTRAINT [FK_LINEITEM_PARTSUPP] FOREIGN
KEY([L_PARTKEY], [L_SUPPKEY])
REFERENCES [dbo].[PARTSUPP] ([PS_PARTKEY], [PS_SUPPKEY])
GO
ALTER TABLE [dbo].[LINEITEM] CHECK CONSTRAINT [FK_LINEITEM_PARTSUPP]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].
[FK_CUSTOMER_NATION]') AND parent_object_id = OBJECT_ID(N'[dbo].[CUSTOMER]'))
ALTER TABLE [dbo].[CUSTOMER] WITH CHECK ADD CONSTRAINT [FK_CUSTOMER_NATION] FOREIGN3)导入数据
KEY([C_NATIONKEY])
REFERENCES [dbo].[NATION] ([N_NATIONKEY])
GO
ALTER TABLE [dbo].[CUSTOMER] CHECK CONSTRAINT [FK_CUSTOMER_NATION]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].
[FK_SUPPLIER_NATION]') AND parent_object_id = OBJECT_ID(N'[dbo].[SUPPLIER]'))
ALTER TABLE [dbo].[SUPPLIER] WITH CHECK ADD CONSTRAINT [FK_SUPPLIER_NATION] FOREIGN
KEY([S_NATIONKEY])
REFERENCES [dbo].[NATION] ([N_NATIONKEY])
GO
ALTER TABLE [dbo].[SUPPLIER] CHECK CONSTRAINT [FK_SUPPLIER_NATION]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].
[FK_NATION_REGION]') AND parent_object_id = OBJECT_ID(N'[dbo].[NATION]'))
ALTER TABLE [dbo].[NATION] WITH CHECK ADD CONSTRAINT [FK_NATION_REGION] FOREIGN
KEY([N_REGIONKEY])
REFERENCES [dbo].[REGION] ([R_REGIONKEY])
GO
ALTER TABLE [dbo].[NATION] CHECK CONSTRAINT [FK_NATION_REGION]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].
[FK_PARTSUPP_PART]') AND parent_object_id = OBJECT_ID(N'[dbo].[PARTSUPP]'))
ALTER TABLE [dbo].[PARTSUPP] WITH CHECK ADD CONSTRAINT [FK_PARTSUPP_PART] FOREIGN
KEY([PS_PARTKEY])
REFERENCES [dbo].[PART] ([P_PARTKEY])
GO
ALTER TABLE [dbo].[PARTSUPP] CHECK CONSTRAINT [FK_PARTSUPP_PART]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].
[FK_PARTSUPP_SUPPLIER]') AND parent_object_id = OBJECT_ID(N'[dbo].[PARTSUPP]'))
ALTER TABLE [dbo].[PARTSUPP] WITH CHECK ADD CONSTRAINT [FK_PARTSUPP_SUPPLIER] FOREIGN
KEY([PS_SUPPKEY])
REFERENCES [dbo].[SUPPLIER] ([S_SUPPKEY])
GO
ALTER TABLE [dbo].[PARTSUPP] CHECK CONSTRAINT [FK_PARTSUPP_SUPPLIER]

This snippet took 0.02 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).