简体   繁体   中英

How can I drop this Foreign Key Column?

I have looked at some of the other questions similar to this one but have not had any luck. I am trying to delete the whole foreign key column from the blogs table. It is linked to a primary key in my students table as well.

Create table students
(
studentid integer primary key NOT NULL,
ulid varchar(20) NOT NULL,
password varchar(20) NOT NULL,
email varchar(50) NOT NULL
)

Create table blogs
(
blogid integer primary key NOT NULL,
blogdate date NOT NULL,
title varchar(50) NOT NULL,
description varchar(8000) NOT NULL,
category varchar (50) NOT NULL,
studentid integer NOT NULL,
foreign key (studentid) references students (studentid)
)

I tried this and it didn't work

alter table blogs drop column studentid

alter table blogs drop constraint studentid

alter table blogs drop foreign key studentid

try this sql :

alter table blogs drop foreign key keyconstraint   // for you it will be `blogs_ibfk_1` i think

if you have any problem in droping the foreign constraind use:

show create table blogs

here you can see the created foreign key constraint name. then use it in sql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM