1
I want you to forgive me for this posting, maybe it’s someone’s question, but come on...
I know that the programmer has to master some things, and these things are considered as triads, for example; Every programmer has to know advanced English not to be dependent on courses but on official documentation of a certain technology, Every programmer has to know Object Orientation and every programmer has to know the basics of SQL, so... I don’t know all these things but I’m learning moderately the subjects.
I had the habit of creating my applications in Mysql, but I’m with a client who wants to do the system anyway in Postgresql, with it has no talk, but today I was without a job and has emerged these quick jobs to do, so I’m hugging and I really need your help.
Currently I need to implement the security system of an application, and I need to create some tables with SQL statement, the project I’m doing it already does a lot for me, and creates some tables automatically, I’m using Spring Boot, however the security part is necessary to create the tables through SQL statement, I know to do without any problem in Mysql database, but in the same way that I know to do in Mysql do not know to perform the creation of the database in Posgresql, I’m encountering syntax errors, and unfortunately I don’t have a test database to create the system, I know this is a huge mistake, but I will try to solve this problem later.
I tried to research Free courses on how to create tables in SQL, but there is little information on the Internet regarding this, of course there is a lot of information in English, but I’m not able to understand why I’m still learning English.
The tables are just these below, I’m trying to create these tables in Postgresql, but it seems that to create an auto key increment has to create it separately, I made some attempts, but I’m afraid that damage the database settings on the Heroku server.
CREATE TABLE usuario (
codigo BIGINT(20) PRIMARY KEY AUTO_INCREMENT,
nome VARCHAR(50) NOT NULL,
email VARCHAR(50) NOT NULL,
senha VARCHAR(120) NOT NULL,
ativo BOOLEAN DEFAULT true,
data_nascimento DATE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE grupo (
codigo BIGINT(20) PRIMARY KEY,
nome VARCHAR(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE permissao (
codigo BIGINT(20) PRIMARY KEY,
nome VARCHAR(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE usuario_grupo (
codigo_usuario BIGINT(20) NOT NULL,
codigo_grupo BIGINT(20) NOT NULL,
PRIMARY KEY (codigo_usuario, codigo_grupo),
FOREIGN KEY (codigo_usuario) REFERENCES usuario(codigo),
FOREIGN KEY (codigo_grupo) REFERENCES grupo(codigo)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE grupo_permissao (
codigo_grupo BIGINT(20) NOT NULL,
codigo_permissao BIGINT(20) NOT NULL,
PRIMARY KEY (codigo_grupo, codigo_permissao),
FOREIGN KEY (codigo_grupo) REFERENCES grupo(codigo),
FOREIGN KEY (codigo_permissao) REFERENCES permissao(codigo)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Could someone kindly tell me what these tables would look like if they were made in Posgresql ?
When trying to execute the query of the creation of user_group gave the following error;
ERROR: syntax error at or near "("
LINE 2: codigo_usuario BIGINT(20) NOT NULL,
^
********** Error **********
ERROR: syntax error at or near "("
SQL state: 42601
Character: 55
Could you give me one more help? What would the user table look like ?
– wladyband
@wladyband gave any error? this table has no serial field.
– rray
I updated my post, take a look please :(
– wladyband
@wladyband in whole types you do not specify the size, can remove that
(20)
after theBIGINT
– rray
thank you very much worked out.
– wladyband