我正在尝试从表帐户中删除一行,但是其中一列是另一个表的外键。我尝试运行:ALTER TABLE depositor DROP FOREIGN KEY account_number;
但是它吐出一个错误,说:
ORA-00905: missing keyword
我缺少什么关键字?
我不知道这是否有帮助,但是创建表存放者的原始语句是:
create table depositor
(customer_name varchar(15) not null,
account_number varchar(15) not null,
primary key(customer_name, account_number),
foreign key(account_number) references account(account_number),
foreign key(customer_name) references customer(customer_name));
create table customer
(customer_name varchar(15) not null,
customer_street varchar(12) not null,
customer_city varchar(15) not null,
primary key(customer_name));
create table account
(account_number varchar(15) not null,
branch_name varchar(15) not null,
balance number not null,
primary key(account_number));
实际的表已将它们插入其中:
insert into customer values ('Jones', 'Main', 'Harrison');
insert into customer values ('Smith', 'Main', 'Rye');
insert into customer values ('Hayes', 'Main', 'Harrison');
insert into customer values ('Curry', 'North', 'Rye');
insert into customer values ('Lindsay', 'Park', 'Pittsfield');
insert into customer values ('Turner', 'Putnam', 'Stamford');
insert into customer values ('Williams', 'Nassau', 'Princeton');
insert into customer values ('Adams', 'Spring', 'Pittsfield');
insert into customer values ('Johnson', 'Alma', 'Palo Alto');
insert into customer values ('Glenn', 'Sand Hill', 'Woodside');
insert into customer values ('Brooks', 'Senator', 'Brooklyn');
insert into customer values ('Green', 'Walnut', 'Stamford');
insert into customer values ('Jackson', 'University', 'Salt Lake');
insert into customer values ('Majeris', 'First', 'Rye');
insert into customer values ('McBride', 'Safety', 'Rye');
insert into customer values ('Jones', 'Second', 'Bennington');
insert into account values ('A-101', 'Downtown', 500);
insert into account values ('A-215', 'Mianus', 1000);
insert into account values ('A-102', 'Perryridge', 400);
insert into account values ('A-305', 'Round Hill', 350);
insert into account values ('A-201', 'Perryridge', 900);
insert into account values ('A-222', 'Redwood', 100000);
insert into account values ('A-217', 'Brighton', 7500);
insert into account values ('A-333', 'Central', 8500);
insert into account values ('A-444', 'North Town', 6250);
insert into depositor values ('Johnson','A-101');
insert into depositor values ('Smith', 'A-215');
insert into depositor values ('Hayes', 'A-102');
insert into depositor values ('Hayes', 'A-101');
insert into depositor values ('Turner', 'A-305');
insert into depositor values ('Johnson','A-201');
insert into depositor values ('Jones', 'A-217');
insert into depositor values ('Lindsay', 'A-222');
insert into depositor values ('Majeris', 'A-333');
insert into depositor values ('Smith', 'A-444');
insert into depositor values ('Johnson','A-444');
这是因为创建表时您没有命名CONSTRAINT,所以它是自动生成的。
做一个:
SHOW CREATE TABLE depositor;
它将显示如下内容:
CREATE TABLE `depositor` (
`customer_name` varchar(15) NOT NULL,
`account_number` varchar(15) NOT NULL,
PRIMARY KEY (`customer_name`,`account_number`),
KEY `account_number` (`account_number`),
CONSTRAINT `depositor_ibfk_1` FOREIGN KEY (`account_number`) REFERENCES `account` (`account_number`),
CONSTRAINT `depositor_ibfk_2` FOREIGN KEY (`customer_name`) REFERENCES `customer` (`customer_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
其中depositor_ibfk_1是可以使用命令删除的约束名称:
ALTER TABLE depositor DROP FOREIGN KEY depositor_ibfk_1;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句