CREATE SCHEMA or DATABASE has a difference? and placing the CONSTRAINT before an FK is necessary?

1

I have those doubts in SQL .. It is a language that is not so strict and 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 this he works with SCHEMA and I really do have something that word has marred me .. all my short studio life of sql had been DATABASE: S

On the other hand taking advantage of the question .. also the Workbench 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 the Foreignkey just place 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 database name.tablename, besides, I do not put anything in the parentheses of references and it does not create the foreign field cedula_c

How do I look for the subject of the points ... [db]. [table] as it is called, is that point the same as putting FROM or something similar? that has a name to look well for that topic that nobody gave it to me. <

    
asked by HeckDan 24.05.2017 в 01:05
source

1 answer

1

I answer your first question only. I think that, according to the rules of the site, it is better to ask a question per case, because it is more useful for the future and because answering several questions may require too much effort and the same question could be closed because it is considered too broad.

Then:

  

What exactly is the difference between CREATE SCHEMA and CREATE?   DATEBASE

The exact difference is one, they are called different, but they do the same thing. This is what the MySQL documentation states:

  

CREATE DATABASE creates a database with the given name. To use this   statement, you need the CREATE privilege for the database. CREATE SCHEMA is a synonym for CREATE DATABASE .

CREATE DATABASE   create a database with the given name. To use this   statement, the CREATE privilege is required for the database. CREATE SCHEMA is synonymous with CREATE DATABASE .      

CREATE DATABASE in MySQL documentation

Also in the MySQL glossary the following is said:

  

schema

     

Conceptually, a schema is an interrelated set of   database objects, such as tables, table columns,   data types of columns, indexes, external keys, and so on   successively. These objects are connected through the syntax   SQL, because the columns represent the tables, the keys   External refer to tables and columns, and so on.   Ideally, they are logically connected in that they work together   as part of a unified application or flexible framework. For example,   in the databases INFORMATION_SCHEMA and performance_schema   use " schema " in their names to highlight the narrow ones   relationships between tables and columns that contain.

     

In MySQL, physically, schema and database are synonyms, so in the SQL syntax you can use the keyword SCHEMA instead   of DATABASE , for example, instead of using CREATE SCHEMA you can   use CREATE DATABASE .

     

Some other database products establish a distinction.   For example, in the Oracle database product, a% co_of% only   represents a part of a database diagram: the tables and   other objects owned by a single user.

     

schema in the MySQL glossary

P. D .: I think the other question should be put aside, you will get better answers and it will be more useful to the rest of the OS community.

    
answered by 24.05.2017 / 01:20
source