I have these doubts in SQL... it is a not so strict language and it runs despite the different ways of writing it... What exactly is the difference between CREATE SCHEMA and CREATE DATEBASE when I started to see the code generated by Workbech, it works with SCHEMA and really, that word has me a bit sick... all my short life of studying sql had been DATABASE: S
On the other hand, taking advantage of the question... the Workbench also makes use of the CONSTRAINT in front of the FOREIGNKEY
Here is an example of code generated by Workbench
CREATE TABLE IF NOT EXISTS `tallermecanico_hd`.`e_vehiculos` (
`placa` INT NOT NULL,
`marca` VARCHAR(25) NULL,
`modelo` VARCHAR(25) NULL,
`anio` VARCHAR(4) NULL,
`observ` VARCHAR(255) NULL,
`serial` VARCHAR(25) NULL,
`color` VARCHAR(25) NULL,
`puertas` INT,
`motor` VARCHAR(25) NULL,
`transmision` VARCHAR(25) NULL,
//<<<aqui yo colocaria el campo foraneo cedula_c pero workbench no lo hizo<<<
PRIMARY KEY (`placa`),
CONSTRAINT `cedula_c`
FOREIGN KEY ()
REFERENCES `tallermecanico_hd`.`c_clientes` ()
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;
I was used to just placing the Foreignkey like this:
FOREINGN KEY(cedula_c)REFERENCES c_clientes
and if it works the same but what is the difference D: what does the CONSTRAINT do??? In addition, the Workbench uses the name of the database. name of the table. In addition, I do not put anything inside the parentheses of references and it does not create the foreign field cedula_c
How do I look for the theme of the points... [db].[table] what is that called that point is the same as putting FROM or something similar? that has some name to look for that topic well that nobody gave me >.<
I answer your first question only. I think that, according to the rules of the site, it is better to ask one question per case, because it is more useful for the future and because answering several questions could require too much effort and the same question could be closed because it is considered too broad.
Then:
The exact difference is only one, they are called different, but they do the same thing. This is what the MySQL documentation states:
Also in the MySQL glossary it says the following:
PS: I think the other question should be asked separately, you will get better answers and it will be more useful to the rest of the SO community.