2012-11-25 94 views
1
Create Table Person (
ID integer primary key 
, [name] character(15) not null 
, address character(15) 
, phone integer 
); 

Create Table Surveyor (
surveyID integer 
, certificationDate Datetime 
, ID integer 
, primary KEY (surveyID,ID) 
, FOREIGN KEY (ID) REFERENCES Person 
); 

Create Table Points (
PntID integer primary key 
, N float not null 
, E float not null 
, Height float not null 
); 

Create Table Polygon (
polyID integer primary key 
, area float not null 
, atleastonepoint integer not null 
, foreign key (atleastonepoint) references Points(PntID) 
, check (area > 0) 
); 



Create Table Block (
blockID integer 
, blockName character (15) not null 
, polyID integer 
, polyLength float not null 
    , primary KEY (blockID,polyID) 
, onemunicipalAuthority character (15) not null 
, foreign key (polyID) references polygon 
    , check (polyLength > 0) 
); 


Create Table Parcel (
    parcelname character (15) 
    , blockID integer 
, polyID integer 
    , primary KEY (parcelname,blockID,polyID) 
, foreign key (polyID) references polygon 
, foreign key (blockID) REFERENCES block 
); 

錯誤的問題:關係必須在相同數量的字段具有相同的數據類型,當我嘗試執行最後一個,CREATE =>包裹
我有一個SQL語句

感謝名單預先

+1

'Block'具有由化合物主鍵**兩列**(BLOCKID,polyID),因此任何外鍵引用THA噸PK必須**還**使用這兩列 - 錯誤是非常明確的.... –

回答

1

嘗試此命令:

Create Table Parcel (
    parcelname character (15) 
    , blockID integer 
, polyID integer 
    , primary KEY (parcelname,blockID,polyID) 
, foreign key (polyID) references polygon 
, foreign key (blockID,polyID) REFERENCES block 
); 
+0

謝謝你!!!!! – Rawhi