Error in POSTGRESQL Bank Creation

0

I'm having the following error when creating a POSTGRESQL database:

SQL CODE:

CREATE DATABASE pesadaum;

CREATE TABLE user(
    user_id int PRIMARY KEY NOT NULL AUTO_INCREMENT,
    email varchar(255) NOT NULL,
    heavy_pass varchar(255) NOT NULL
);

CREATE TABLE admin_user(
    admin_user_id int PRIMARY KEY NOT NULL AUTO_INCREMENT,
    email varchar(255) NOT NULL,
    heavy_pass varchar(255) NOT NULL,
    admin_name varchar(255) NOT NULL,
    rg varchar(15) NOT NULL,
    cpf varchar(15) NOT NULL,
    access_lvl boolean NOT NULL,
);

CREATE TABLE problem(
    problem_id int PRIMARY KEY NOT NULL AUTO_INCREMENT,
    address point,
    description text
    user_id int NOT NULL REFERENCES user(user_id)
);

CREATE TABLE img(
    img_id int PRIMARY KEY NOT NULL AUTO_INCREMENT,
    url varchar(255) NOT NULL,
    status_acc boolean,
    problem_id int NOT NULL REFERENCES problem_id(problem_id)
);

CREATE TABLE error(
    error_id int PRIMARY KEY NOT NULL AUTO_INCREMENT,
    error_name varchar(255),
    error_description TEXT,
);

CREATE TABLE error_problem_plug(
    problem_id int NOT NULL REFERENCES problem(problem_id),
    error_id int NOT NULL REFERENCES error(error_id)
);
    
asked by anonymous 08.06.2016 / 14:43

3 answers

2

Follow your converted script, but do not get accustomed not: D

CREATE DATABASE pesadaum;

CREATE TABLE "user"(
    user_id  serial NOT NULL ,
    email varchar(255) NOT NULL,
    heavy_pass varchar(255) NOT NULL,
     PRIMARY KEY (user_id)
);

CREATE TABLE admin_user(
    admin_user_id serial  NOT NULL ,
    email varchar(255) NOT NULL,
    heavy_pass varchar(255) NOT NULL,
    admin_name varchar(255) NOT NULL,
    rg varchar(15) NOT NULL,
    cpf varchar(15) NOT NULL,
    access_lvl boolean NOT NULL,
    PRIMARY KEY(admin_user_id)
);

CREATE TABLE problem(
    problem_id serial NOT NULL ,
    address point,
    description text,
    user_id int ,
    PRIMARY KEY(problem_id),
    FOREIGN KEY (user_id) REFERENCES "user" (user_id)
);

CREATE TABLE img(
    img_id serial NOT NULL ,
    url varchar(255) NOT NULL,
    status_acc boolean,
    problem_id int NOT NULL REFERENCES "problem"(problem_id),
    PRIMARY KEY(img_id)
);

CREATE TABLE error(
    error_id serial NOT NULL ,
    error_name varchar(255),
    error_description TEXT,
    PRIMARY KEY (error_id)
);

CREATE TABLE error_problem_plug(
    problem_id int NOT NULL REFERENCES "problem"(problem_id),
    error_id int NOT NULL REFERENCES "error"(error_id)
);
    
08.06.2016 / 17:08
3

This syntax is not from PostgreSQL, it is the SQL from another database.

Begins with AUTO_INCREMENT . The correct serial use SERIAL .

You have an error that I did not identify, it may have occurred as a result of these. You need to learn to interpret mistakes on your own, several will happen.

    
08.06.2016 / 14:55
1

Script with error looks like MySQL.

The first error is syntax error at or near "user" this occurs because there is an object called user in portgres.

If you run the query "select user" it will return the logged in user.

When you define a table attribute as serial, a sequence is created and the default value of the attribute becomes nextval ()

The script of the user table would look like this:

  CREATE TABLE "user"(
user_id  serial NOT NULL ,
email varchar(255) NOT NULL,
heavy_pass varchar(255) NOT NULL,
PRIMARY KEY (user_id));
    
10.06.2016 / 17:05