1
Every time I create a DER(Entity-Relationship Diagram) in a database, and then type this diagram in the Entity-Relationship Model, to scan the created diagram and also to perform the insertion of records and their respective queries in the database. Whenever I start creating a table, I type the following commands:
USE db_evento;
CREATE TABLE tb_aluno(
id_aluno INT(6) NOT NULL PRIMARY KEY,
cd_rm_aluno INT(5),
nm_aluno VARCHAR(100) NOT NULL,
dt_nascimento_aluno DATE NOT NULL
);
When I put this code to run on Mysql, the first line is executed without any exception, but in the second line, the program recognizes a logical error by saying that the table tb_aluno
already exists. An error code of nº 1050.
To solve this problem, I put the IF NOT EXISTS
next to the CREATE TABLE
to eliminate the 1050 error and create an existing table in the template, only I typed the following code and the console display returned these results:
CREATE TABLE IF NOT EXISTS tb_aluno( // CRIAR TABELA SE NÃO EXISTIR tb_aluno
id_aluno INT(6) NOT NULL PRIMARY KEY,
cd_rm_aluno INT(5),
nm_aluno VARCHAR(100) NOT NULL,
dt_nascimento_aluno DATE NOT NULL
);
Result in the code snippet above in Mysql:
Result in checking all tables I’ve created within Mysql:
This way I got confused when using this
IF NOT EXISTS
when it comes to implementing this operator in all the tables I’ve done. There is another way to create tables without this type of alert in the console, so that all lines of code are checked without any error?
@Fr. Math enlightened?
– RXSD
Sorry for the delay I gave up using the stack overflow. @RXSD
– pe.Math
All right buddy, welcome back!
– RXSD