INT NOT NULL列を具体的に設定せずにテーブルに行を挿入できるという問題が発生しています(デフォルトは0で、私の目的には無効です)。
この方法でテーブルを作成します。
CREATE TABLE inventorycontrol (
ID INT NOT NULL UNIQUE AUTO_INCREMENT
,nodeID INT NOT NULL CHECK (nodeID > 0)
,custom1 VARCHAR(128) NOT NULL DEFAULT ''
,custom2 VARCHAR(128) NOT NULL DEFAULT ''
,custom3 VARCHAR(128) NOT NULL DEFAULT ''
,custom4 VARCHAR(128) NOT NULL DEFAULT ''
,articlekey VARCHAR(32) NOT NULL
,amount INT NOT NULL
,orderID INT NULL
,supplierID INT NULL
,customerID INT NULL
,datecreated DATETIME NOT NULL
,expectedcompletion DATETIME NOT NULL
,datecompleted DATETIME NULL
,PRIMARY KEY (articlekey, datecreated)
)
GO
CREATE INDEX ix_InventoryArticle ON inventorycontrol ( articlekey )
GO
CREATE INDEX ix_InventoryArticle_Custom ON inventorycontrol ( nodeID, custom1, custom2, custom3, custom4 )
GO
CREATE INDEX ix_InventoryAmount ON inventorycontrol ( amount )
GO
CREATE INDEX ix_InventoryCreated ON inventorycontrol ( datecreated )
GO
CREATE INDEX ix_InventoryCompleted ON inventorycontrol ( datecompleted )
GO
ALTER TABLE inventorycontrol
ADD FOREIGN KEY fk_nodeID (nodeID) REFERENCES node(ID)
GO
私はこの挿入が失敗することを期待します:
INSERT INTO inventorycontrol ( articlekey, amount, datecreated, expectedcompletion, datecompleted )
VALUES
( 'abc', -10, '2009-01-27', '2009-01-27', NULL )
GO
残念ながら、これはうまくいきます。(ノードWHERE ID = 0はありません)
挿入のトリガーを作成せずに、この挿入を強制的に失敗させる方法はありますか?
前もって感謝します、
クリス
PS私はmysqlVer14.12 Distrib 5.0.45を使用しており、readline 5.0を使用するredhat-linux-gnu(x86_64)用です