Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
¿Es necesario especificar un nombre de restricción al agregar una clave externa en MySQL?

Hasta ahora, he creado las tablas manualmente de esta manera y no tuve ningún problema.

 CREATE TABLE users ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, email VARCHAR(100) NOT NULL, cityId BIGINT(20) UNSIGNED NULL DEFAULT NULL, PRIMARY KEY (id), FOREIGN KEY (cityId) REFERENCES cities (id));

Ahora, estoy usando MySQL Workbench que genera la secuencia de comandos SQL para mí, y la secuencia de comandos SQL se ve un poco diferente.

 CREATE TABLE users ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, email VARCHAR(100) NOT NULL, cityId BIGINT(20) UNSIGNED NULL DEFAULT NULL, PRIMARY KEY (id), CONSTRAINT cityId FOREIGN KEY (cityId) REFERENCES locations (id) ON DELETE NO ACTION ON UPDATE NO ACTION);

Me pregunto si hay alguna diferencia entre estas dos consultas.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

No es necesario que proporcione un nombre para una clave externa y, si no lo hace, se le asignará un nombre generado automáticamente. Habiendo dicho eso, es una buena práctica y facilitará su trabajo de mantenimiento.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!