Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

DROP TABLE IF EXISTS `Person`; /*!40101 SET @saved_cs_client = @@character_set_c

ID: 3735024 • Letter: D

Question

DROP TABLE IF EXISTS `Person`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
/*create a new table Person;*/

create table Person (PersonCode varchar(255) not null , PersonName varchar(255) , PersonAddressID int ,emailID int, primary key (PersonCode));

-- make Person can not insert the same value

alter table Person add constraint PersonCode unique (PersonCode);

/*add foreign key into Person*/

alter table Person add foreign key (emailID) references email(emailID);

alter table Person add foreign key (PersonAddressID) references address(PersonAddressID);

-- insert index into Person

ALTER TABLE Person ADD INDEX stupid1 (PersonCode,PersonName,PersonAddressID);

/*insert Check method in Person*/

ALTER TABLE Person ADD CHECK (PersonAddressID>0);

-- insert default method in Person

ALTER TABLE Person ALTER PersonName SET DEFAULT 'Sydyne';

DROP TABLE IF EXISTS `email`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
/*create a new table email;*/

create table email(emailID int,email1 varchar(255),email2 varchar(255),email3 varchar(255),email4 varchar(255));


alter table email add primary key (emailID);

alter table email add constraint emialID unique (emailID);

Always show errors----

Explanation / Answer

From the issue you have included, it seems that you are not abe to create the table 'email'.

And the issue you are getting usually happens when the FOREIGN KEY relationship is not defined properly. For example, if 'email' table has a foregin key which references another key from another table and that key is not a primary key, then you will get this error.

Does your table 'email' has any FOREIGN KEY?

Because the error is happening while creating 'email' table and not during creating 'Person' table.