0

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
Tator
  • 19
  • 5

1 Answers1

0

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

Suchit kumar
  • 11,809
  • 3
  • 22
  • 44
  • @Tator use the show sql which i have posted to know constraint name. – Suchit kumar Dec 03 '14 at 18:04
  • You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '//table name' at line 1 – Tator Dec 03 '14 at 18:10
  • when I do that it shows CREATE TABLE `blogs` ( `blogid` int(11) NOT NULL AUTO_INCREMENT, `blogdate` date NOT NULL, `title` varchar(50) NOT NULL, `description` varchar(8000) NOT NULL, `category` varchar(50) NOT NULL, `studentid` int(11) NOT NULL, PRIMARY KEY (`blogid`), KEY `studentid` (`studentid`) ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1 – Tator Dec 03 '14 at 18:16
  • if your problem is solved then you can accept the answer and close this topic. – Suchit kumar Dec 03 '14 at 18:22