从脚本文件创建本地数据库?

时间:2012-04-10 15:32:09

标签: c# sql visual-studio-2010

我是整个数据库的新手。我想知道如何使用下面这两个文件将信息传递到C#中的本地数据库。

如果有人可以创建数据库并通过电子邮件发送给我,我将非常感激!

mssql.create.sql

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Tb_Requests_Tb_Consumer]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Tb_Requests] DROP CONSTRAINT FK_Tb_Requests_Tb_Consumer
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Tb_Transactions_Tb_Consumer]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Tb_Transactions] DROP CONSTRAINT FK_Tb_Transactions_Tb_Consumer
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_TB_Offers_Tb_Product]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[TB_Offers] DROP CONSTRAINT FK_TB_Offers_Tb_Product
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Tb_Requests_Tb_Product]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Tb_Requests] DROP CONSTRAINT FK_Tb_Requests_Tb_Product
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Tb_Transactions_Tb_Product]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Tb_Transactions] DROP CONSTRAINT FK_Tb_Transactions_Tb_Product
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_TB_Offers_Tb_Supplier]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[TB_Offers] DROP CONSTRAINT FK_TB_Offers_Tb_Supplier
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Tb_Transactions_Tb_Supplier]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Tb_Transactions] DROP CONSTRAINT FK_Tb_Transactions_Tb_Supplier
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TB_Offers]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[TB_Offers]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Tb_Consumer]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Tb_Consumer]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Tb_Product]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Tb_Product]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Tb_Requests]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Tb_Requests]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Tb_Supplier]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Tb_Supplier]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Tb_Transactions]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Tb_Transactions]
GO

CREATE TABLE [dbo].[TB_Offers] (
    [Supp_ID] [int] NOT NULL ,
    [Prod_ID] [int] NOT NULL ,
    [Price] [money] NULL ,
    [Quantity] [float] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Tb_Consumer] (
    [Con_ID] [int] IDENTITY (1, 1) NOT NULL ,
    [Name] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [City] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Tb_Product] (
    [Prod_ID] [int] IDENTITY (1, 1) NOT NULL ,
    [Name] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [MU] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Tb_Requests] (
    [Con_ID] [int] NOT NULL ,
    [Prod_ID] [int] NOT NULL ,
    [Price] [money] NULL ,
    [Quantity] [float] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Tb_Supplier] (
    [Supp_ID] [int] IDENTITY (1, 1) NOT NULL ,
    [Name] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [City] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Tb_Transactions] (
    [Tran_ID] [int] IDENTITY (1, 1) NOT NULL ,
    [Supp_ID] [int] NOT NULL ,
    [Con_ID] [int] NOT NULL ,
    [Prod_ID] [int] NOT NULL ,
    [Price] [money] NULL ,
    [Quantity] [float] NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[TB_Offers] WITH NOCHECK ADD 
    CONSTRAINT [PK_TB_Offers] PRIMARY KEY  CLUSTERED 
    (
        [Supp_ID],
        [Prod_ID]
    )  ON [PRIMARY] ,
    CONSTRAINT [CK_TB_Offers] CHECK ([Price] > 0.00),
    CONSTRAINT [CK_TB_Offers_1] CHECK ([Quantity] >= 0)
GO

ALTER TABLE [dbo].[Tb_Consumer] WITH NOCHECK ADD 
    CONSTRAINT [PK_Tb_Consumer] PRIMARY KEY  CLUSTERED 
    (
        [Con_ID]
    )  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Tb_Product] WITH NOCHECK ADD 
    CONSTRAINT [PK_Tb_Product] PRIMARY KEY  CLUSTERED 
    (
        [Prod_ID]
    )  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Tb_Requests] WITH NOCHECK ADD 
    CONSTRAINT [PK_Tb_Requests] PRIMARY KEY  CLUSTERED 
    (
        [Con_ID],
        [Prod_ID]
    )  ON [PRIMARY] ,
    CONSTRAINT [CK_Tb_Requests] CHECK ([Price] > 0.00),
    CONSTRAINT [CK_Tb_Requests_1] CHECK ([Quantity] >= 0)
GO

ALTER TABLE [dbo].[Tb_Supplier] WITH NOCHECK ADD 
    CONSTRAINT [PK_Tb_Supplier] PRIMARY KEY  CLUSTERED 
    (
        [Supp_ID]
    )  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Tb_Transactions] WITH NOCHECK ADD 
    CONSTRAINT [PK_Tb_Transactions] PRIMARY KEY  CLUSTERED 
    (
        [Tran_ID]
    )  ON [PRIMARY] ,
    CONSTRAINT [CK_Tb_Transactions] CHECK ([Price] > 0.00),
    CONSTRAINT [CK_Tb_Transactions_1] CHECK ([Quantity] > 0)
GO

ALTER TABLE [dbo].[TB_Offers] ADD 
    CONSTRAINT [FK_TB_Offers_Tb_Product] FOREIGN KEY 
    (
        [Prod_ID]
    ) REFERENCES [dbo].[Tb_Product] (
        [Prod_ID]
    ),
    CONSTRAINT [FK_TB_Offers_Tb_Supplier] FOREIGN KEY 
    (
        [Supp_ID]
    ) REFERENCES [dbo].[Tb_Supplier] (
        [Supp_ID]
    )
GO

ALTER TABLE [dbo].[Tb_Requests] ADD 
    CONSTRAINT [FK_Tb_Requests_Tb_Consumer] FOREIGN KEY 
    (
        [Con_ID]
    ) REFERENCES [dbo].[Tb_Consumer] (
        [Con_ID]
    ),
    CONSTRAINT [FK_Tb_Requests_Tb_Product] FOREIGN KEY 
    (
        [Prod_ID]
    ) REFERENCES [dbo].[Tb_Product] (
        [Prod_ID]
    )
GO

ALTER TABLE [dbo].[Tb_Transactions] ADD 
    CONSTRAINT [FK_Tb_Transactions_Tb_Consumer] FOREIGN KEY 
    (
        [Con_ID]
    ) REFERENCES [dbo].[Tb_Consumer] (
        [Con_ID]
    ),
    CONSTRAINT [FK_Tb_Transactions_Tb_Product] FOREIGN KEY 
    (
        [Prod_ID]
    ) REFERENCES [dbo].[Tb_Product] (
        [Prod_ID]
    ),
    CONSTRAINT [FK_Tb_Transactions_Tb_Supplier] FOREIGN KEY 
    (
        [Supp_ID]
    ) REFERENCES [dbo].[Tb_Supplier] (
        [Supp_ID]
    )
GO

mssql.insert.sql

DELETE FROM TB_TRANSACTIONS;
DELETE FROM TB_OFFERS;
DELETE FROM TB_REQUESTS;
DELETE FROM TB_PRODUCT;
DELETE FROM TB_CONSUMER;
DELETE FROM TB_SUPPLIER;

--Suppliers
INSERT INTO TB_SUPPLIER VALUES('Joe','Madison')
INSERT INTO TB_SUPPLIER VALUES('Herman','Madison')
INSERT INTO TB_SUPPLIER VALUES('Bernstein','Madison')
INSERT INTO TB_SUPPLIER VALUES('Smith','Madison')

INSERT INTO TB_SUPPLIER VALUES('Redfield','Wausau')
INSERT INTO TB_SUPPLIER VALUES('Godman','Wausau')
INSERT INTO TB_SUPPLIER VALUES('James','Wausau')
INSERT INTO TB_SUPPLIER VALUES('Wells','Wausau')
INSERT INTO TB_SUPPLIER VALUES('Wolf','Wausau')

INSERT INTO TB_SUPPLIER VALUES('Thomas','Chicago')
INSERT INTO TB_SUPPLIER VALUES('Traiger','Chicago')

INSERT INTO TB_SUPPLIER VALUES('Strong','Stevens Point')
INSERT INTO TB_SUPPLIER VALUES('Deitel','Stevens Point')
INSERT INTO TB_SUPPLIER VALUES('Troelsen','Stevens Point')

INSERT INTO TB_SUPPLIER VALUES('Stronger','London')
INSERT INTO TB_SUPPLIER VALUES('Wolfgang','London')

INSERT INTO TB_SUPPLIER VALUES('Jones','Madison')
INSERT INTO TB_SUPPLIER VALUES('Jaques','Paris')

--Consumers
INSERT INTO TB_CONSUMER VALUES('Steel','New York')
INSERT INTO TB_CONSUMER VALUES('Hammer','New York')
INSERT INTO TB_CONSUMER VALUES('Iron','New York')

INSERT INTO TB_CONSUMER VALUES('Hoffer','Wausau')
INSERT INTO TB_CONSUMER VALUES('Gray','Wausau')
INSERT INTO TB_CONSUMER VALUES('Fisher','Wausau')
INSERT INTO TB_CONSUMER VALUES('Franklin','Wausau')
INSERT INTO TB_CONSUMER VALUES('Smith','Wausau')
INSERT INTO TB_CONSUMER VALUES('Schafer','Wausau')
INSERT INTO TB_CONSUMER VALUES('Johnson','Wausau')

INSERT INTO TB_CONSUMER VALUES('Jacob','Chicago')
INSERT INTO TB_CONSUMER VALUES('Metzker','Chicago')
INSERT INTO TB_CONSUMER VALUES('Boggs','Chicago')

--Products
INSERT INTO TB_PRODUCT VALUES('Computer','Pieces')
INSERT INTO TB_PRODUCT VALUES('Auto','Pieces')
INSERT INTO TB_PRODUCT VALUES('TV','Pieces')
INSERT INTO TB_PRODUCT VALUES('Milk','Gallon')
INSERT INTO TB_PRODUCT VALUES('Oil','Gallon')
INSERT INTO TB_PRODUCT VALUES('Orange','Lb')
INSERT INTO TB_PRODUCT VALUES('Truck','Pieces')
INSERT INTO TB_PRODUCT VALUES('Airplane','Pieces')

--Offers
INSERT INTO TB_OFFERS VALUES(1,1,799.99,100)
INSERT INTO TB_OFFERS VALUES(1,2,7899.99,10)
INSERT INTO TB_OFFERS VALUES(1,3,199.99,1000)
INSERT INTO TB_OFFERS VALUES(1,4,1.99,10000)
INSERT INTO TB_OFFERS VALUES(1,5,1.09,100000)
INSERT INTO TB_OFFERS VALUES(1,6,0.99,100)

INSERT INTO TB_OFFERS VALUES(2,1,795.99,100)
INSERT INTO TB_OFFERS VALUES(2,2,7897.99,10)
INSERT INTO TB_OFFERS VALUES(2,3,191.99,1000)
INSERT INTO TB_OFFERS VALUES(2,4,1.89,10000)
INSERT INTO TB_OFFERS VALUES(2,5,1.09,100000)
INSERT INTO TB_OFFERS VALUES(2,6,0.99,100)
INSERT INTO TB_OFFERS VALUES(2,7,11.09,100000)
INSERT INTO TB_OFFERS VALUES(2,8,100.99,100)

INSERT INTO TB_OFFERS VALUES(3,1,789.99,100)
INSERT INTO TB_OFFERS VALUES(3,6,0.99,100)

INSERT INTO TB_OFFERS VALUES(4,1,769.99,100)
INSERT INTO TB_OFFERS VALUES(4,2,7899.99,10)
INSERT INTO TB_OFFERS VALUES(4,3,199.99,1000)
INSERT INTO TB_OFFERS VALUES(4,6,0.99,100)

INSERT INTO TB_OFFERS VALUES(5,1,799.99,100)
INSERT INTO TB_OFFERS VALUES(5,2,7899.99,10)
INSERT INTO TB_OFFERS VALUES(5,4,1.99,10000)
INSERT INTO TB_OFFERS VALUES(5,5,1.09,100000)
INSERT INTO TB_OFFERS VALUES(5,6,0.99,100)
INSERT INTO TB_OFFERS VALUES(5,7,11.09,100000)
INSERT INTO TB_OFFERS VALUES(5,8,100.99,100)

INSERT INTO TB_OFFERS VALUES(9,1,799.99,100)
INSERT INTO TB_OFFERS VALUES(9,2,7809.99,10)
INSERT INTO TB_OFFERS VALUES(9,3,189.99,1000)
INSERT INTO TB_OFFERS VALUES(9,4,1.99,10000)
INSERT INTO TB_OFFERS VALUES(9,5,1.19,100000)
INSERT INTO TB_OFFERS VALUES(9,6,0.90,100)
INSERT INTO TB_OFFERS VALUES(9,7,11.09,100000)
INSERT INTO TB_OFFERS VALUES(9,8,100.99,100)

INSERT INTO TB_OFFERS VALUES(8,1,799.99,100)
INSERT INTO TB_OFFERS VALUES(10,1,7809.99,10)
INSERT INTO TB_OFFERS VALUES(11,1,189.99,1000)
INSERT INTO TB_OFFERS VALUES(12,1,1.99,10000)
INSERT INTO TB_OFFERS VALUES(14,1,1.09,100000)
INSERT INTO TB_OFFERS VALUES(15,1,0.89,100)

INSERT INTO TB_OFFERS VALUES(8,7,37990.99,100)
INSERT INTO TB_OFFERS VALUES(10,7,80900.99,10)
INSERT INTO TB_OFFERS VALUES(12,7,100000.99,10000)

INSERT INTO TB_OFFERS VALUES(11,8,18.99,1000)
INSERT INTO TB_OFFERS VALUES(12,8,1.99,10000)
INSERT INTO TB_OFFERS VALUES(14,8,1.09,100000)

--Requests
INSERT INTO TB_REQUESTS VALUES(1,1,798.99,100)
INSERT INTO TB_REQUESTS VALUES(1,2,7897.99,10)
INSERT INTO TB_REQUESTS VALUES(1,3,196.99,1000)
INSERT INTO TB_REQUESTS VALUES(1,4,1.90,10000)
INSERT INTO TB_REQUESTS VALUES(1,5,1.00,100000)
INSERT INTO TB_REQUESTS VALUES(1,6,0.90,100)
INSERT INTO TB_REQUESTS VALUES(1,7,1.00,100000)
INSERT INTO TB_REQUESTS VALUES(1,8,89.90,100)

INSERT INTO TB_REQUESTS VALUES(2,1,790.99,100)
INSERT INTO TB_REQUESTS VALUES(2,2,7890.99,10)
INSERT INTO TB_REQUESTS VALUES(2,3,190.99,1000)
INSERT INTO TB_REQUESTS VALUES(2,5,1.09,100000)
INSERT INTO TB_REQUESTS VALUES(2,6,0.99,100)

INSERT INTO TB_REQUESTS VALUES(4,1,760.99,100)
INSERT INTO TB_REQUESTS VALUES(4,3,190.99,1000)
INSERT INTO TB_REQUESTS VALUES(4,6,0.8,100)

INSERT INTO TB_REQUESTS VALUES(5,1,798.99,100)
INSERT INTO TB_REQUESTS VALUES(5,2,788.99,10)
INSERT INTO TB_REQUESTS VALUES(5,4,1.8,10000)
INSERT INTO TB_REQUESTS VALUES(5,5,1.00,100000)
INSERT INTO TB_REQUESTS VALUES(5,6,0.95,100)

INSERT INTO TB_REQUESTS VALUES(6,1,790.99,100)
INSERT INTO TB_REQUESTS VALUES(6,2,7809.99,10)
INSERT INTO TB_REQUESTS VALUES(6,3,186.99,1000)
INSERT INTO TB_REQUESTS VALUES(6,4,1.99,10000)
INSERT INTO TB_REQUESTS VALUES(6,5,1.09,100000)
INSERT INTO TB_REQUESTS VALUES(6,6,0.90,100)

INSERT INTO TB_REQUESTS VALUES(7,1,799.99,100)
INSERT INTO TB_REQUESTS VALUES(7,2,7809.99,10)
INSERT INTO TB_REQUESTS VALUES(7,3,189.99,1000)
INSERT INTO TB_REQUESTS VALUES(7,4,1.99,10000)
INSERT INTO TB_REQUESTS VALUES(7,5,1.09,100000)
INSERT INTO TB_REQUESTS VALUES(7,6,0.89,100)

--Transactions
INSERT INTO TB_TRANSACTIONS VALUES(1,1,1,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(1,1,2,7897.99,10)
INSERT INTO TB_TRANSACTIONS VALUES(1,1,3,196.99,1000)
INSERT INTO TB_TRANSACTIONS VALUES(1,1,4,1.90,10000)
INSERT INTO TB_TRANSACTIONS VALUES(1,1,5,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(1,1,6,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(1,1,7,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(1,1,8,0.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(1,2,1,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(1,2,2,7897.99,10)
INSERT INTO TB_TRANSACTIONS VALUES(1,2,3,196.99,1000)
INSERT INTO TB_TRANSACTIONS VALUES(1,2,5,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(1,2,6,0.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(1,4,1,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(1,4,3,196.99,1000)
INSERT INTO TB_TRANSACTIONS VALUES(1,4,6,0.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(1,5,1,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(1,6,2,7897.99,10)
INSERT INTO TB_TRANSACTIONS VALUES(1,7,6,0.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(1,1,1,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(1,2,2,7897.99,10)
INSERT INTO TB_TRANSACTIONS VALUES(1,3,3,196.99,1000)
INSERT INTO TB_TRANSACTIONS VALUES(1,4,4,1.90,10000)
INSERT INTO TB_TRANSACTIONS VALUES(1,5,5,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(1,6,6,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(1,7,7,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(1,8,8,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(1,9,7,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(1,10,8,0.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(2,1,1,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(2,1,2,7897.99,10)
INSERT INTO TB_TRANSACTIONS VALUES(2,1,3,196.99,1000)
INSERT INTO TB_TRANSACTIONS VALUES(2,1,4,1.90,10000)
INSERT INTO TB_TRANSACTIONS VALUES(2,1,5,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(2,1,6,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(2,1,7,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(2,1,8,0.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(2,1,1,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(2,2,2,7897.99,10)
INSERT INTO TB_TRANSACTIONS VALUES(2,3,3,196.99,1000)
INSERT INTO TB_TRANSACTIONS VALUES(2,4,4,1.90,10000)
INSERT INTO TB_TRANSACTIONS VALUES(2,5,5,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(2,6,6,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(2,7,7,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(2,8,8,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(2,9,7,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(2,10,8,0.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(2,2,1,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(2,2,2,7897.99,10)
INSERT INTO TB_TRANSACTIONS VALUES(2,2,6,0.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(2,4,1,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(2,4,3,196.99,1000)
INSERT INTO TB_TRANSACTIONS VALUES(2,4,6,0.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(2,5,1,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(2,5,2,7897.99,10)
INSERT INTO TB_TRANSACTIONS VALUES(2,5,6,0.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(3,1,1,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,2,1,7897.99,10)
INSERT INTO TB_TRANSACTIONS VALUES(3,3,1,196.99,1000)
INSERT INTO TB_TRANSACTIONS VALUES(3,4,1,1.90,10000)
INSERT INTO TB_TRANSACTIONS VALUES(3,5,1,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,6,1,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,7,1,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,8,1,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,9,1,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,10,1,0.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(3,1,2,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,2,2,7897.99,10)
INSERT INTO TB_TRANSACTIONS VALUES(3,3,2,196.99,1000)
INSERT INTO TB_TRANSACTIONS VALUES(3,4,2,1.90,10000)
INSERT INTO TB_TRANSACTIONS VALUES(3,5,2,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,6,2,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,7,2,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,8,2,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,9,2,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,10,2,0.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(3,1,3,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,2,3,7897.99,10)
INSERT INTO TB_TRANSACTIONS VALUES(3,3,3,196.99,1000)
INSERT INTO TB_TRANSACTIONS VALUES(3,4,3,1.90,10000)
INSERT INTO TB_TRANSACTIONS VALUES(3,5,3,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,6,3,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,7,3,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,8,3,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,9,3,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,10,3,0.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(3,1,4,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,2,4,7897.99,10)
INSERT INTO TB_TRANSACTIONS VALUES(3,3,4,196.99,1000)
INSERT INTO TB_TRANSACTIONS VALUES(3,4,4,1.90,10000)
INSERT INTO TB_TRANSACTIONS VALUES(3,5,4,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,6,4,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,7,4,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,8,4,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,9,4,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,10,4,0.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(3,1,5,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,2,5,7897.99,10)
INSERT INTO TB_TRANSACTIONS VALUES(3,3,5,196.99,1000)
INSERT INTO TB_TRANSACTIONS VALUES(3,4,5,1.90,10000)
INSERT INTO TB_TRANSACTIONS VALUES(3,5,5,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,6,5,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,7,5,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,8,5,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,9,5,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,10,5,0.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(3,1,6,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,2,6,7897.99,10)
INSERT INTO TB_TRANSACTIONS VALUES(3,3,6,196.99,1000)
INSERT INTO TB_TRANSACTIONS VALUES(3,4,6,1.90,10000)
INSERT INTO TB_TRANSACTIONS VALUES(3,5,6,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,6,6,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,7,6,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,8,6,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,9,6,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,10,6,0.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(3,1,7,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,2,7,7897.99,10)
INSERT INTO TB_TRANSACTIONS VALUES(3,3,7,196.99,1000)
INSERT INTO TB_TRANSACTIONS VALUES(3,4,7,1.90,10000)
INSERT INTO TB_TRANSACTIONS VALUES(3,5,7,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,6,7,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,7,7,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,8,7,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,9,7,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,10,7,0.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(3,1,8,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,2,8,7897.99,10)
INSERT INTO TB_TRANSACTIONS VALUES(3,3,8,196.99,1000)
INSERT INTO TB_TRANSACTIONS VALUES(3,4,8,1.90,10000)
INSERT INTO TB_TRANSACTIONS VALUES(3,5,8,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,6,8,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,7,8,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,8,8,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(3,9,8,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(3,10,8,0.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(9,4,4,1.90,10000)
INSERT INTO TB_TRANSACTIONS VALUES(9,5,5,1.00,100000)
INSERT INTO TB_TRANSACTIONS VALUES(9,6,5,0.90,100)
INSERT INTO TB_TRANSACTIONS VALUES(9,7,2,798.99,100)

INSERT INTO TB_TRANSACTIONS VALUES(9,2,1,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(9,2,6,0.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(9,4,1,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(9,4,3,196.99,1000)
INSERT INTO TB_TRANSACTIONS VALUES(9,4,6,0.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(9,5,1,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(9,5,2,7897.99,10)
INSERT INTO TB_TRANSACTIONS VALUES(9,5,6,99.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(11,1,2,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(11,5,4,7897.99,10)
INSERT INTO TB_TRANSACTIONS VALUES(11,7,6,99.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(13,2,2,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(13,5,4,7897.99,10)
INSERT INTO TB_TRANSACTIONS VALUES(13,8,7,99.90,100)

INSERT INTO TB_TRANSACTIONS VALUES(15,2,2,798.99,100)
INSERT INTO TB_TRANSACTIONS VALUES(15,5,4,7897.99,10)
INSERT INTO TB_TRANSACTIONS VALUES(15,8,7,99.90,100)

3 个答案:

答案 0 :(得分:2)

这些文件是SQL脚本。他们所做的就是创建一组表并填充它们。一旦创建,它们就无法访问数据库中的数据。

它们旨在在SQL数据库上执行,很可能是SQL Server。

通常可以使用SQL Server Management Studio来完成。

答案 1 :(得分:1)

这是快速而又脏的代码,但你可以稍微玩一下来获得你需要的代码

using System;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace Test {
    internal class Class1 {
        public const string sqlDataConnectionDetails = "Data Source=SQL_SERVER;Initial Catalog=DATABASE_NAME;Persist Security Info=True;User ID=USERNAME;Password=PASSWORD";
        private void TestWrite() {
            const string preparedCommand =
                @"

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Tb_Requests_Tb_Consumer]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Tb_Requests] DROP CONSTRAINT FK_Tb_Requests_Tb_Consumer
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Tb_Transactions_Tb_Consumer]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Tb_Transactions] DROP CONSTRAINT FK_Tb_Transactions_Tb_Consumer
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_TB_Offers_Tb_Product]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[TB_Offers] DROP CONSTRAINT FK_TB_Offers_Tb_Product
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Tb_Requests_Tb_Product]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Tb_Requests] DROP CONSTRAINT FK_Tb_Requests_Tb_Product
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Tb_Transactions_Tb_Product]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Tb_Transactions] DROP CONSTRAINT FK_Tb_Transactions_Tb_Product
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_TB_Offers_Tb_Supplier]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[TB_Offers] DROP CONSTRAINT FK_TB_Offers_Tb_Supplier
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Tb_Transactions_Tb_Supplier]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Tb_Transactions] DROP CONSTRAINT FK_Tb_Transactions_Tb_Supplier
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TB_Offers]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[TB_Offers]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Tb_Consumer]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Tb_Consumer]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Tb_Product]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Tb_Product]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Tb_Requests]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Tb_Requests]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Tb_Supplier]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Tb_Supplier]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Tb_Transactions]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Tb_Transactions]
GO

CREATE TABLE [dbo].[TB_Offers] (
    [Supp_ID] [int] NOT NULL ,
    [Prod_ID] [int] NOT NULL ,
    [Price] [money] NULL ,
    [Quantity] [float] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Tb_Consumer] (
    [Con_ID] [int] IDENTITY (1, 1) NOT NULL ,
    [Name] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [City] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Tb_Product] (
    [Prod_ID] [int] IDENTITY (1, 1) NOT NULL ,
    [Name] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [MU] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Tb_Requests] (
    [Con_ID] [int] NOT NULL ,
    [Prod_ID] [int] NOT NULL ,
    [Price] [money] NULL ,
    [Quantity] [float] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Tb_Supplier] (
    [Supp_ID] [int] IDENTITY (1, 1) NOT NULL ,
    [Name] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [City] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Tb_Transactions] (
    [Tran_ID] [int] IDENTITY (1, 1) NOT NULL ,
    [Supp_ID] [int] NOT NULL ,
    [Con_ID] [int] NOT NULL ,
    [Prod_ID] [int] NOT NULL ,
    [Price] [money] NULL ,
    [Quantity] [float] NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[TB_Offers] WITH NOCHECK ADD 
    CONSTRAINT [PK_TB_Offers] PRIMARY KEY  CLUSTERED 
    (
        [Supp_ID],
        [Prod_ID]
    )  ON [PRIMARY] ,
    CONSTRAINT [CK_TB_Offers] CHECK ([Price] > 0.00),
    CONSTRAINT [CK_TB_Offers_1] CHECK ([Quantity] >= 0)
GO

ALTER TABLE [dbo].[Tb_Consumer] WITH NOCHECK ADD 
    CONSTRAINT [PK_Tb_Consumer] PRIMARY KEY  CLUSTERED 
    (
        [Con_ID]
    )  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Tb_Product] WITH NOCHECK ADD 
    CONSTRAINT [PK_Tb_Product] PRIMARY KEY  CLUSTERED 
    (
        [Prod_ID]
    )  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Tb_Requests] WITH NOCHECK ADD 
    CONSTRAINT [PK_Tb_Requests] PRIMARY KEY  CLUSTERED 
    (
        [Con_ID],
        [Prod_ID]
    )  ON [PRIMARY] ,
    CONSTRAINT [CK_Tb_Requests] CHECK ([Price] > 0.00),
    CONSTRAINT [CK_Tb_Requests_1] CHECK ([Quantity] >= 0)
GO

ALTER TABLE [dbo].[Tb_Supplier] WITH NOCHECK ADD 
    CONSTRAINT [PK_Tb_Supplier] PRIMARY KEY  CLUSTERED 
    (
        [Supp_ID]
    )  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Tb_Transactions] WITH NOCHECK ADD 
    CONSTRAINT [PK_Tb_Transactions] PRIMARY KEY  CLUSTERED 
    (
        [Tran_ID]
    )  ON [PRIMARY] ,
    CONSTRAINT [CK_Tb_Transactions] CHECK ([Price] > 0.00),
    CONSTRAINT [CK_Tb_Transactions_1] CHECK ([Quantity] > 0)
GO

ALTER TABLE [dbo].[TB_Offers] ADD 
    CONSTRAINT [FK_TB_Offers_Tb_Product] FOREIGN KEY 
    (
        [Prod_ID]
    ) REFERENCES [dbo].[Tb_Product] (
        [Prod_ID]
    ),
    CONSTRAINT [FK_TB_Offers_Tb_Supplier] FOREIGN KEY 
    (
        [Supp_ID]
    ) REFERENCES [dbo].[Tb_Supplier] (
        [Supp_ID]
    )
GO

ALTER TABLE [dbo].[Tb_Requests] ADD 
    CONSTRAINT [FK_Tb_Requests_Tb_Consumer] FOREIGN KEY 
    (
        [Con_ID]
    ) REFERENCES [dbo].[Tb_Consumer] (
        [Con_ID]
    ),
    CONSTRAINT [FK_Tb_Requests_Tb_Product] FOREIGN KEY 
    (
        [Prod_ID]
    ) REFERENCES [dbo].[Tb_Product] (
        [Prod_ID]
    )
GO

ALTER TABLE [dbo].[Tb_Transactions] ADD 
    CONSTRAINT [FK_Tb_Transactions_Tb_Consumer] FOREIGN KEY 
    (
        [Con_ID]
    ) REFERENCES [dbo].[Tb_Consumer] (
        [Con_ID]
    ),
    CONSTRAINT [FK_Tb_Transactions_Tb_Product] FOREIGN KEY 
    (
        [Prod_ID]
    ) REFERENCES [dbo].[Tb_Product] (
        [Prod_ID]
    ),
    CONSTRAINT [FK_Tb_Transactions_Tb_Supplier] FOREIGN KEY 
    (
        [Supp_ID]
    ) REFERENCES [dbo].[Tb_Supplier] (
        [Supp_ID]
    )
GO
";
            using (SqlConnection varConnection = sqlConnectOneTime(sqlDataConnectionDetails)) {
                using (var sqlWrite = new SqlCommand(preparedCommand, varConnection)) {
                    sqlWrite.ExecuteNonQuery();
                }
            }
        }
        private static SqlConnection sqlConnectOneTime(string varSqlConnectionDetails) {
            var sqlConnection = new SqlConnection(varSqlConnectionDetails);
            try {
                sqlConnection.Open();
            } catch {
                DialogResult result = MessageBox.Show(new Form {
                                                                   TopMost = true
                                                               }, "Error connecting to database", "Error (000001)", MessageBoxButtons.YesNo, MessageBoxIcon.Stop);
                if (result == DialogResult.No) {
                    if (Application.MessageLoop) {
                        Application.Exit(); // Use this since we are a WinForms app
                    } else {
                        Environment.Exit(1); // Use this since we are a console app// Use this since we are a console app
                    }
                } else {
                    sqlConnection = sqlConnectOneTime(varSqlConnectionDetails);
                }
            }
            return sqlConnection;
        }
    }
}

答案 2 :(得分:0)

这些SQL文件包含SQL Server的SQL,T-SQL方言,因此您需要一个SQL Server实例来运行它们 - 与C#无关。如果您没有SQL Server,那么您可以查看下载和安装快速版本。安装完成后,您将拥有一个名为SQL Server Management Studio的应用程序,您可以使用该应用程序打开然后执行这两个文件。

我建议您在SQL Server上购买一本书,并阅读前几章以熟悉它。