2016-12-02 18 views
-2

私は日Northwindデータベース上で動作するようにしよう、とされている私は何が起こったのかの「星座図に基づいて」DW_Northwindを作成したとき:SQL Server 2008のデータウェアハウス

create database DW_Northwind2 
go 
-- table de fait 1 
create table TF_LIV_CMD 
( ID_client nchar(5), 
    ID_Employee int, 
    Mois   datetime, 
    Année  datetime, 
    NB_CMD_LIV int, 
    NB_CMD_NONLIV int 
) 
go 
-- table de fait 2 
create table TF_Product 
( SupplierID int, 
    CategoryID int , 
    PriceLevel varchar (50), 
    StockLevel varchar (50) 
    ) 
go 
-- table de fait 3 
create table TF_Client 
( Country nvarchar (15), 
    City  nvarchar (15), 
    OrderLevel varchar (50) , 
    SalesLevel varchar (50) 
    ) 
go 
-- table de fait 4 
create table TF_CA 
( Année  datetime, 
    Mois  datetime, 
    ID_client nchar(5), 
    CategoryID int , 
    ID_product int 
    ) 
go 
-- table de fait 5 
create table TF_RemisAcc 
( Année  datetime, 
    Mois  datetime, 
    ID_client nchar(5), 
    Discount real 
) 
go 
-- creation des table de dimmension 
create table TD_client 
( ID_client nchar(5), 
    CompanyName nvarchar(40), 
    Country  nvarchar (15), 
    City  nvarchar (15)  
) 
go 
Create table TD_Employee 
( ID_Employee int, 
    LastName nvarchar (20), 
    FirstName nvarchar (20), 
    Country  nvarchar (15), 
    City  nvarchar (15) 
) 
go 
create table TD_Mois 
     (Mois datetime) 
go 
create table TD_Année 
     (Année datetime) 
go 
create table TD_Supplier 
( SupplierID int, 
    CompanyName nvarchar(40), 
    Country  nvarchar (15), 
    City  nvarchar (15) 
    ) 
go 
create table TD_Category 
( CategoryID int , 
    CategoryName nvarchar (50) 
    ) 
go 
create table TD_Country 
     ( Country nvarchar (15)) 
go 
create table TD_City 
( City nvarchar (15)) 
go 
create table TD_Product 
( ProductID int, 
    ProductName nvarchar (40) 
    ) 
go 


Alter table TF_LIV_CMD 
    add Constraint FK_TF_LIV_CMD Foreign key (ID_client) references TD_client (ID_client); 

Alter table TF_LIV_CMD 
    add Constraint FK_TF_LIV_CMD1 Foreign key (ID_Employee) references TD_Employee (ID_Employee); 
Alter Table TF_Product 
    add Constraint FK_TF_Product Foreign key (SupplierID) references TD_Supplier (SupplierID); 
Alter Table TF_Product 
    add Constraint  FK_TF_Product1 Foreign key (CategoryID) references TD_Catgoery (CategoryID); 
Alter Table TF_Client 
    add Constraint FK_TF_Client Foreign key (Country)  references TD_Country (Country); 

Alter Table TF_Client 
    add Constraint FK_TF_Client1 Foreign key (City)   references TD_City (City); 
Alter Table TF_CA 
    add Constraint FK_TF_CA  Foreign key (ID_client)  references TD_client (ID_client); 
Alter Table TF_CA 
    add Constraint FK_TF_CA1  Foreign key (CategoryID) references TD_Catgoery (CategoryID); 

Alter Table TF_CA 
    add Constraint FK_TF_CA2  Foreign key (ProductID)  references TD__Product (ProductID); 
Alter Table TF_RemisAcc 
    add Constraint FK_TF_RemisAcc  Foreign key (ID_client)  references TD_client (ID_client); 

Alter Table TF_RemisAcc 
    add Constraint FK_TF_RemisAcc1  Foreign key (Mois)   references TD_Mois  (Mois); 

Alter Table TF_RemisAcc 
    add Constraint FK_TF_RemisAccs2 Foreign key (Année)   references TD_Année  (Année); 

Alter table TD_client 
    add Constraint PK_Client  Primary Key NonClustered (ID_Client); 

Alter table TD_Employee 
    add Constraint PK_TD_Employee Primary Key NonClustered (ID_Employee); 

Alter table TD_Mois 
    add Constraint PK_TD_Mois  Primary Key NonClustered (Mois); 

Alter table TD_Année 
    add Constraint PK_TD_Année  Primary Key NonClustered (Année); 

Alter table TD_SUpplier 
    add Constraint PK_TD_SupplierID Primary Key NonClustered (SpplierID); 

Alter table TD_Category 
    add Constraint PK_TD_CategoryID Primary Key NonClustered (CategoryID); 

Alter table TD_Country 
    add Constraint PK_TD_Country  Primary Key NonClustered (Country); 

ALter Table TD_City 
    add Constraint PK_TD_City   Primary Key NonClustered (City); 

Alter table TD_Product 
    add Constraint PK_TD_Product Primary Key NonClustered (ID_Product); 

エラー:

Msg 2714, Level 16, State 6, Line 3 
There is already an object named 'TF_LIV_CMD' in the database. 
Msg 2714, Level 16, State 6, Line 2 
There is already an object named 'TF_Product' in the database. 
Msg 2714, Level 16, State 6, Line 2 
There is already an object named 'TF_Client' in the database. 
Msg 2714, Level 16, State 6, Line 2 
There is already an object named 'TF_CA' in the database. 
Msg 2714, Level 16, State 6, Line 2 
There is already an object named 'TF_RemisAcc' in the database. 
Msg 2714, Level 16, State 6, Line 2 
There is already an object named 'TD_client' in the database. 
Msg 2714, Level 16, State 6, Line 1 
There is already an object named 'TD_Employee' in the database. 
Msg 2714, Level 16, State 6, Line 2 
There is already an object named 'TD_Mois' in the database. 
Msg 2714, Level 16, State 6, Line 1 
There is already an object named 'TD_Année' in the database. 
Msg 2714, Level 16, State 6, Line 2 
There is already an object named 'TD_Supplier' in the database. 
Msg 2714, Level 16, State 6, Line 2 
There is already an object named 'TD_Category' in the database. 
Msg 2714, Level 16, State 6, Line 2 
There is already an object named 'TD_Country' in the database. 
Msg 2714, Level 16, State 6, Line 2 
There is already an object named 'TD_City' in the database. 
Msg 2714, Level 16, State 6, Line 1 
There is already an object named 'TD_Product' in the database. 
Msg 8111, Level 16, State 1, Line 38 
Cannot define PRIMARY KEY constraint on nullable column in table 'TD_client'. 
Msg 1750, Level 16, State 0, Line 38 
Could not create constraint. See previous errors. 
+0

エラーは自明です:オブジェクトが既に存在しています。 – Dai

+0

あなたはgoogle 'SQL Serverには既に...という名前のオブジェクトがありますか?' – dfundako

+0

ええ、私は前にそれをしました、そして、私はそれを作成する前にテーブルを落とさなければならないと言いますが、それが存在しなければ落とす理由はありませんps:私は古いものをmanupilatingしない新しいデータベースを作成しています – user3676872

答えて

1

オブジェクトはすでにデータベースに存在します。クエリの先頭に各テーブルのためにこれを入れて

、あなたは問題ないはず

IF OBJECT_ID('dbo.TF_LIV_CMD', 'U') IS NOT NULL 
    DROP TABLE dbo.TF_LIV_CMD; 
+1

おかげさまで、あなたは男です....多くのエラーがありますが、結局のところ、コマンドは正常に完了しました。 - – user3676872