Foreign Key constraints in MySQL

user3572396

I am a newbie to PHP. I have been given the code snippet below as homework:

CREATE  TABLE `admin_log`   (
`id`    INT(11) NOT NULL    AUTO_INCREMENT,
`statusdate`    DATETIME    DEFAULT NULL,
`type` INT(11) DEFAULT  NULL
PRIMARY KEY (`id`)  

)   ENGINE=MYISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin 

Why will it not be possible to set up any foreign key constraints using this table?

I have done some research on Google and I cant find a reason why foreign key constraints are not possible. Please help

sdespont

You can do that like this :

CREATE  TABLE `admin_log`   (
`id`    INT(11) NOT NULL    AUTO_INCREMENT,
`statusdate`    DATETIME    DEFAULT NULL,
`type` INT(11) DEFAULT  NULL,

 INDEX (type),
 FOREIGN KEY (type)
    REFERENCES type(id)
    ON UPDATE CASCADE ON DELETE RESTRICT,

PRIMARY KEY (`id`)  
)   ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=latin 

Notice the engine INNODB insetad of MYISAM which doesn't permit foreign key.

Or using MySQLAdmin in the "structure" tab, click on the "relationals view" link below the table description.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Backup MySQL schema with foreign key table constraints

From Dev

Cannot INSERT because of Foreign key constraints - mysql

From Dev

Problem with foreign key constraints and construction of Mysql DB

From Dev

What is wrong with my mysql foreign key constraints?

From Dev

MySQL DB is ignoring foreign key constraints

From Dev

Foreign key with additional constraints?

From Dev

"polymorphism" for FOREIGN KEY constraints

From Dev

Foreign Key Constraints Hell

From Dev

Magento Foreign Key Constraints

From Dev

Doctrine not generating cross-database foreign key constraints in MySQL

From Dev

MySQL - Can't create table (errno: 150) - Foreign key constraints

From Dev

SQL - Foreign key constraints and cardinality

From Dev

mysqldbcopy combining foreign key constraints?

From Dev

Primary & Foreign Key Constraints Confusion

From Dev

Foreign key constraints in Yesod/Persistent?

From Dev

Cannot add foreign key constraints

From Dev

SQL - Foreign key constraints and cardinality

From Dev

mysqldbcopy combining foreign key constraints?

From Dev

MySQL Error Code: 1452 when adding index and foreign key constraints to an existing table

From Dev

Dynamically delete multiple foreign key constraints

From Dev

Knex truncate table with foreign key constraints

From Dev

How does SqlBulkCopy circumnavigate foreign key constraints?

From Dev

postgres: foreign key constraints involving multiple tables

From Dev

CASCADE DELETE on two foreign key constraints

From Dev

How to clear a database with foreign key constraints?

From Dev

Cross-table foreign key constraints

From Dev

SQL Server foreign key constraints issue

From Dev

Unit Test foreign key constraints in Django models

From Dev

Generate insert statements with foreign key constraints

Related Related

  1. 1

    Backup MySQL schema with foreign key table constraints

  2. 2

    Cannot INSERT because of Foreign key constraints - mysql

  3. 3

    Problem with foreign key constraints and construction of Mysql DB

  4. 4

    What is wrong with my mysql foreign key constraints?

  5. 5

    MySQL DB is ignoring foreign key constraints

  6. 6

    Foreign key with additional constraints?

  7. 7

    "polymorphism" for FOREIGN KEY constraints

  8. 8

    Foreign Key Constraints Hell

  9. 9

    Magento Foreign Key Constraints

  10. 10

    Doctrine not generating cross-database foreign key constraints in MySQL

  11. 11

    MySQL - Can't create table (errno: 150) - Foreign key constraints

  12. 12

    SQL - Foreign key constraints and cardinality

  13. 13

    mysqldbcopy combining foreign key constraints?

  14. 14

    Primary & Foreign Key Constraints Confusion

  15. 15

    Foreign key constraints in Yesod/Persistent?

  16. 16

    Cannot add foreign key constraints

  17. 17

    SQL - Foreign key constraints and cardinality

  18. 18

    mysqldbcopy combining foreign key constraints?

  19. 19

    MySQL Error Code: 1452 when adding index and foreign key constraints to an existing table

  20. 20

    Dynamically delete multiple foreign key constraints

  21. 21

    Knex truncate table with foreign key constraints

  22. 22

    How does SqlBulkCopy circumnavigate foreign key constraints?

  23. 23

    postgres: foreign key constraints involving multiple tables

  24. 24

    CASCADE DELETE on two foreign key constraints

  25. 25

    How to clear a database with foreign key constraints?

  26. 26

    Cross-table foreign key constraints

  27. 27

    SQL Server foreign key constraints issue

  28. 28

    Unit Test foreign key constraints in Django models

  29. 29

    Generate insert statements with foreign key constraints

HotTag

Archive