我有一個表horse
和一個視圖view_horse
從horse
表中選擇除主鍵(主鍵是自動遞增整數),然後將其呈現給用戶的每一列,我想插入數據到該視圖的基礎表自然期望主鍵自動生成。但是當我嘗試向其中插入任何數據時,我總是收到一個SQL異常,聲明「視圖view_horse
底層沒有默認值」。插入到帶有自動增量主鍵的視圖中?
編輯 -
CREATE TABLE IF NOT EXISTS `TRC`.`horse` (
`horse_id` INT NOT NULL AUTO_INCREMENT,
`registered_name` VARCHAR(20) NOT NULL,
`stable_name` VARCHAR(20) NOT NULL,
`horse_birth_year` DATE NOT NULL,
`horse_height` DECIMAL(3,1) NOT NULL,
`horse_location` VARCHAR(50) NOT NULL DEFAULT 'TRC',
`arrival_date` DATE NOT NULL,
`passport_no` MEDIUMTEXT NULL,
`is_deceased` TINYINT(1) NOT NULL,
`arrival_weight` DECIMAL NOT NULL,
`horse_sex` VARCHAR(8) NOT NULL,
`microchip_no` VARCHAR(15) NULL,
`date_of_death` DATE NULL,
PRIMARY KEY (`horse_id`),
INDEX `fk_Horses_SexLookup1_idx` (`horse_sex` ASC),
CONSTRAINT `fk_Horses_SexLookup1`
FOREIGN KEY (`horse_sex`)
REFERENCES `TRC`.`lookup_sex` (`sex`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
USE `TRC`;
CREATE OR REPLACE VIEW `TRC`.`view_horse` AS SELECT
registered_name AS 'Registered Name',
stable_name AS 'Stable Name',
horse_birth_year AS 'Age',
horse_height AS 'Height',
arrival_weight AS 'Weight on Arrival',
horse_sex AS 'Sex',
horse_location AS 'Location',
arrival_date AS 'Date of Arrival',
passport_no AS 'Passport no.',
microchip_no AS 'Microchip no.',
is_deceased AS 'Alive?'
FROM `horse`;
如果我插入的觀點沒有具體說明實際完成確定的列。但不是當我給視圖中指定的列。
你能張貼了一份sqlfiddle? – Strawberry