create table `Salary`(
`sa_id` int unsigned,
`es_id` int unsigned,
`po_id` int unsigned,
`value` int (10),
`lose` int (10),
`days` int (10),
`lose_note` varchar (50),
PRIMARY KEY(`sa_id`),
CONSTRAINT po_sa FOREIGN KEY (`po_id`)
REFERENCES Position(`po_id`)
CONSTRAINT es_sa FOREIGN KEY (`es_id`)
REFERENCES Employee_stat(`es_id`)
)ENGINE=InnoDB CHARSET=utf8 COMMENT="Table";
答案 0 :(得分:1)
您在REFERENCES Position(po_id)
答案 1 :(得分:1)
第一次参考后,逗号错过了。您的查询将是:
CREATE TABLE `Salary`(
`sa_id` int unsigned,
`es_id` int unsigned,
`po_id` int unsigned,
`value` int (10),
`lose` int (10),
`days` int (10),
`lose_note` varchar (50),
PRIMARY KEY(`sa_id`),
CONSTRAINT po_sa FOREIGN KEY (`po_id`)
REFERENCES Position(`po_id`), -- missed the comma here
CONSTRAINT es_sa FOREIGN KEY (`es_id`)
REFERENCES Employee_stat(`es_id`)
)ENGINE=InnoDB CHARSET=utf8 COMMENT="Table";
答案 2 :(得分:0)
缺少--
-- Procedure to replicate the value of sequences from source to destination schema
--
-- The database link name must be PROD
--
-- SQL> CREATE DATABASE LINK PROD CONNECT TO ...
--
CREATE OR REPLACE PROCEDURE RESET_SEQUENCES
AS
CURSOR CSEQUENCES
IS
SELECT SEQUENCE_NAME
FROM USER_SEQUENCES@PROD;
L_SEQUENCE_NAME USER_SEQUENCES.SEQUENCE_NAME%TYPE;
L_SRC_SEQ_VALUE USER_SEQUENCES.MAX_VALUE%TYPE;
L_DST_SEQ_VALUE USER_SEQUENCES.MAX_VALUE%TYPE;
L_SQL VARCHAR2(200);
BEGIN
OPEN CSEQUENCES;
LOOP
FETCH CSEQUENCES INTO L_SEQUENCE_NAME;
EXIT WHEN CSEQUENCES%NOTFOUND;
--
-- Select sequence value from source schema
--
L_SQL := 'SELECT '|| L_SEQUENCE_NAME ||'.NEXTVAL@PROD FROM DUAL';
EXECUTE IMMEDIATE L_SQL INTO L_SRC_SEQ_VALUE;
--
-- Select sequence value from destination schema
--
L_SQL := 'SELECT '|| L_SEQUENCE_NAME ||'.NEXTVAL FROM DUAL';
EXECUTE IMMEDIATE L_SQL INTO L_DST_SEQ_VALUE;
DBMS_OUTPUT.PUT_LINE('SEQUENCE_NAME: '||L_SEQUENCE_NAME);
DBMS_OUTPUT.PUT_LINE('::BEFORE => SRC VALUE: '||L_SRC_SEQ_VALUE||' DST VALUE: '||L_DST_SEQ_VALUE);
--
-- Synchronize sequences value, only if necessary
--
IF L_SRC_SEQ_VALUE > L_DST_SEQ_VALUE THEN
--
-- Alter increment by to diference between L_SRC_SEQ_VALUE and L_DST_SEQ_VALUE
--
L_SQL := 'ALTER SEQUENCE '|| L_SEQUENCE_NAME ||' INCREMENT BY '||TO_CHAR(L_SRC_SEQ_VALUE-L_DST_SEQ_VALUE);
EXECUTE IMMEDIATE L_SQL;
--
-- Select sequence value
--
L_SQL := 'SELECT '|| L_SEQUENCE_NAME ||'.NEXTVAL FROM DUAL';
EXECUTE IMMEDIATE L_SQL INTO L_DST_SEQ_VALUE;
--
-- Alter increment by back to 1
--
L_SQL := 'ALTER SEQUENCE '|| L_SEQUENCE_NAME ||' INCREMENT BY 1';
EXECUTE IMMEDIATE L_SQL;
END IF;
DBMS_OUTPUT.PUT_LINE('::AFTER => SRC VALUE: '||L_SRC_SEQ_VALUE||' DST VALUE: '||L_DST_SEQ_VALUE);
END LOOP;
CLOSE CSEQUENCES;
END RESET_SEQUENCES;
/
--
-- EXECUTE RESET_SEQUENCES PROCEDURE AND BE HAPPY!
--
SQL> EXEC RESET_SEQUENCES
运算符,如下所示
,
将您的PRIMARY KEY(`sa_id`),
CONSTRAINT po_sa FOREIGN KEY (`po_id`) <-- Here
声明更改为
CREATE TABLE
答案 3 :(得分:0)
它显示没有反引号的位置,并且缺少逗号是问题。
create table `Salary`(
`sa_id` int unsigned,
`es_id` int unsigned,
`po_id` int unsigned,
`value` int (10),
`lose` int (10),
`days` int (10),
`lose_note` varchar (50),
PRIMARY KEY(`sa_id`),
CONSTRAINT po_sa FOREIGN KEY (`po_id`)
REFERENCES `Position`(`po_id`), --Backticks & comma
CONSTRAINT es_sa FOREIGN KEY (`es_id`)
REFERENCES Employee_stat(`es_id`)
)ENGINE=InnoDB CHARSET=utf8 COMMENT="Table";