Skip to content

How to make a column a foreign key in PHPmyadmin xampp?

DROP TABLE IF EXISTS `Customer`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `Customer` (
  `CustomerID` varchar(45) NOT NULL,
  `Username` varchar(45) NOT NULL,
  `Password` varchar(45) NOT NULL,
  `Gender` varchar(45) NOT NULL,
  `DoB` date NOT NULL,
  `AddressID` varchar(45) NOT NULL,
  `ContactID` varchar(45) NOT NULL,
  `Picture` blob NOT NULL,
  PRIMARY KEY (`CustomerID`),
  KEY `AddressID` (`AddressID`),
  KEY `ContactID` (`ContactID`),
  CONSTRAINT `AddressID` FOREIGN KEY (`AddressID`) REFERENCES `Addresses` (`AddressID`) ON DELETE CASCADE ON UPDATE CASCADE,
  // There Must be a Table Called Addresses which holds a Column AddressID as PRIMARY KEY
  CONSTRAINT `ContactID` FOREIGN KEY (`ContactID`) REFERENCES `Contacts` (`ContactID`) ON DELETE CASCADE ON UPDATE CASCADE
    // There Must be a Table Called Contacts which holds a Column ContactID as PRIMARY KEY
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

@Zenonymous
See also  How to enter a int in Python?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.