2017-09-16 14 views
0

(ページの一番下にあるERROR)Oracleは私は今、このエラーが発生している..私はそれが長すぎる場所を確認するように見えるカント表現

CREATE TABLE Menu_Item_Ingredient 
(
    Menu_Item_Number Number(5,0)CONSTRAINT NN_MenuItemIngredient_MenuItemNumber Not null, 
    CONSTRAINT FK_MenuItemIngredient_MenuItemNumber Foreign Key(Menu_Item_Number) References Bill_Item(Menu_item_Number), 
    Ingredient_Number Number(5,0) CONSTRAINT NN_MenuItemIngredient_IngredientNumber Not null, 
    CONSTRAINT FK_MenuItemIngredient_IngredientNumber Foreign Key(Ingredient_Number) References Ingredient(Ingredient_Number), 
    Quantity_Needed Number(5,2) DEFAULT 0 CONSTRAINT NN_MenuItemIngredient_QuantityNeeded Not null 
    CONSTRAINT CK_MenuItemIngredient_QuantityNeeded CHECK(Quantity_Needed >= 0), 
    CONSTRAINT PK_BillItem_Ingredient Primary key(Menu_Item_Number,Ingredient_Number) 
) 

エラーレポートの欠落 - SQLエラー:ORA-00972:識別子をが長すぎます 00972です。00000 - "識別子が長すぎます" *原因:30文字を超える識別子が指定されました。 *処置:最大30文字を指定してください。

+0

質問に実際のエラーメッセージを追加できますか? –

+0

通知のおかげで...私はあなたのためにそれを追加しました:)...ページの上部に今すぐ; infoの – Lost

+0

あなたのスキーマの一部をテストしたところ、エラーはCONSTRAINTの部分にあるようです。 [ここをクリック](http://www.sqlfiddle.com/#!4/5543e/1) –

答えて

0

下記を実行してください。クエリでは、bill_itemテーブルにdiscountという列を宣言しているときにカンマが表示されません。

CREATE TABLE Bill_Item3 
(
    Bill_Number  NUMBER(6,0) CONSTRAINT NN_BillItem_BillNumber NOT NULL, 
    Menu_Item_Number NUMBER(5,0) CONSTRAINT NN_BillItem_MenuItemNumber NOT NULL, 
    Discount   NUMBER(5,2) CONSTRAINT N_BillItem_Discount NULL, 
    --colum Discount format '%'00.00, 
    Quaintity_Sold NUMBER(3,0)CONSTRAINT NN_BillItem_QuaintitySold NOT NULL, 
    Selling_Price NUMBER(6,2) default 0 CONSTRAINT NN_BillItem_SellingPrice NOT NULL, 
    CONSTRAINT CK_BillItem_SellingPrice CHECK (Selling_Price >= 0 ), 
    CONSTRAINT PK_Bill_MenuItem PRIMARY KEY (Bill_Number,Menu_Item_Number), 
    CONSTRAINT FK_BillItem_Bill FOREIGN KEY (Bill_Number) REFERENCES bill (Bill_Number), 
    CONSTRAINT FK_BillItem_MenuItemNumber FOREIGN KEY (Menu_Item_Number) REFERENCES Menu_Item_Ingredient(Menu_Item_Number), 
    CONSTRAINT CK_BillItem_Discount CHECK (Discount BETWEEN 0 AND 100) 
); 
+0

私は実際に最後のエラーを解決しました。しかし、すべての時間に感謝します....私は間違いなくあなたの人のために投票します:) – Lost

0

あなたの問題は、外部キー制約は別のテーブルの列への参照を与えるために使用される、クエリで使用すると、以下のような制約を与えている、制約に

  1. ある -

    "CONSTRAINT FK_BillItem_Bill Foreign key (Bill_Number) References Primary(Bill_Number),これで何をしようとしていますか?

    あなたが使用する必要がある構文があるべき -

    CONSTRAINT constraint_name FOREIGN KEY (column_in_current_table) REFERENCES Other_Table_Name(column_name_you_want_to_refer_in_other_table) 
    
  2. 限り私が見てきたように、これは動作しません、あなたがチェック制約にDEFAULTを使用することはできません。

    constraint CK_BillItem_SellingPrice check (Selling_Price >= 0 OR DEFAULT = 0) 
    

    あなたはDEFAULT制約を強制したい場合は、以下のようなものを使用する必要があります -

    CREATE TABLE Persons (
        ID int NOT NULL, 
        LastName varchar(255) NOT NULL, 
        FirstName varchar(255), 
        Age int, 
        City varchar(255) DEFAULT 'Sandnes' 
    ); 
    

    次のように最終的なテーブルをすることができます -

    CREATE TABLE Bill_Item 
    (
        Bill_Number Number(6,0) constraint NN_BillItem_BillNumber not null, 
        --CONSTRAINT FK_BillItem_Bill Foreign key (Bill_Number) References Primary(Bill_Number), 
        Menu_Item_Number Number(5,0) CONSTRAINT NN_BillItem_MenuItemNumber Not null, 
        --CONSTRAINT FK_BillItem_MenuItemNumber Foreign Key (Menu_Item_Number) References Primary(Menu_Item_Number), 
        Discount Number(5,2) CONSTRAINT N_BillItem_Discount Null 
        CONSTRAINT CK_BillItem_Discount Check (Discount BETWEEN 0 and 100), 
        --colum Discount format '%'00.00, 
        Quaintity_Sold Number(3,0)CONSTRAINT NN_BillItem_QuaintitySold not null, 
        Selling_Price Number(6,2) DEFAULT 0.0 CONSTRAINT NN_BillItem_SellingPrice not null, -- You can remove "DEFAULT 0.0" if you do not want to default your Selling_Price to 0.0 
        constraint CK_BillItem_SellingPrice check (Selling_Price >= 0), 
        CONSTRAINT PK_Bill_MenuItem Primary key (Bill_Number,Menu_Item_Number) 
    ); 
    
  3. すべてあなたの他のテーブルも同じ問題を抱えています。上記の例のようにcheck制約からDEFAULTを削除し、 "Default"制約を指定してください列定義そのもの。

  4. また、2番目のテーブル "Bill"には "Waiter"テーブルを参照する外部キー制約があるなど、他のテーブルで参照されるテーブルを作成するので、 "Waiter"最初にテーブル。

まだお気付きがありましたら教えてください。

+0

私はそれを編集しました。 menu_item_ingredient ....ああ、ちょっと感謝して情報を...非常に役に立ちました – Lost

+0

同じことが役に立ったなら、投票がうまくいくでしょう、ありがとう –

関連する問題

 関連する問題