1. Rômulo Sorato
  2. PowerBuilder
  3. Friday, 4 October 2019 20:16 PM UTC

when i run this sql in interactive sql it trows an error

You have an error in your SQL syntax; it seems the error is around: 'autoincrement, nome varchar(60) not null, sigla char(2) not null, primary ' at line 2

this is the sql


create table estados(
id integer not null default autoincrement,
nome varchar(60) not null,
sigla char(2) not null,
primary key(id) )

create table cidades(
id integer not null default autoincrement,
nome varchar(60) not null,
estado_id integer not null,
primary key(id) )

alter table cidades
add foreign key fk_cidades_estados(estado_id)
references estados(id) on delete restrict

create table pessoas(
id integer not null,
nome varchar(60) not null,
data_nascimento date not null,
cpf char(11) not null unique,
cidade_id integer not null,
primary key(id) )

alter table pessoas
add foreign key fk_pessoas_cidades(cidade_id)
references cidades(id) on delete restrict

create table contratos(
id integer not null,
pessoa_id integer not null,
data_assinatura date not null,
valor numeric(13,2) not null,
primary key(id) )

alter table contratos
add foreign key fk_contratos_pessoas(pessoa_id)
references pessoas(id) on delete restrict

insert into estados(nome, sigla) values ('Santa Catarina', 'SC'),
('Rio grande do Sul', 'RS'),
('Paraná', 'PR'),
('São Paulo', 'SP'),
('Rio de Janeiro', 'RJ'),
('Minas Gerais', 'MG'),
('Bahia', 'BA'),
('Espirito Santo', 'ES');

insert into cidades(nome, estado_id) values ('Criciúma', 1),
('Tubarão', 1),
('Florianópolis', 1),
('Porto Alegre', 2),
('Gramado', 2),
('Pelotas', 2),
('Curitiba', 3),
('Londrina', 3),
('Foz do Iguaçu', 3),
('São Paulo', 4),
('Campinas', 2),
('São José dos Campos', 4),
('Rio de Janeiro', 5),
('Búzios', 5),
('Petrópolis', 5),
('Belo Horizonte', 6),
('Pato de minas', 6),
('Patrocínio', 6),
('Salvador', 7),
('Feira de Santana', 7),
('Barreiras', 7),
('Vitória', 8);

Accepted Answer
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 4 October 2019 20:46 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi Rômulo;

   Every DML command statement must end with a ";".

In your case, for example ...

create table estados(
id integer not null default autoincrement,
nome varchar(60) not null,
sigla char(2) not null,
primary key(id) )  ;             <=

HTH

Regards ... Chris

Comment
There are no comments made yet.
David Peace (Powersoft) Accepted Answer Pending Moderation
  1. Monday, 7 October 2019 13:20 PM UTC
  2. PowerBuilder
  3. # 1

This works fine for me on SQL Anywhere V12:

create table estados(
id integer not null default autoincrement,
nome varchar(60) not null,
sigla char(2) not null,
primary key(id) );

create table cidades(
id integer not null default autoincrement,
nome varchar(60) not null,
estado_id integer not null,
primary key(id) );

alter table cidades
add foreign key fk_cidades_estados(estado_id)
references estados(id) on delete restrict;

create table pessoas(
id integer not null,
nome varchar(60) not null,
data_nascimento date not null,
cpf char(11) not null unique,
cidade_id integer not null,
primary key(id) );

alter table pessoas
add foreign key fk_pessoas_cidades(cidade_id)
references cidades(id) on delete restrict;

create table contratos(
id integer not null,
pessoa_id integer not null,
data_assinatura date not null,
valor numeric(13,2) not null,
primary key(id) );

alter table contratos
add foreign key fk_contratos_pessoas(pessoa_id)
references pessoas(id) on delete restrict;

insert into estados(nome, sigla) values ('Santa Catarina', 'SC'),
('Rio grande do Sul', 'RS'),
('Paraná', 'PR'),
('São Paulo', 'SP'),
('Rio de Janeiro', 'RJ'),
('Minas Gerais', 'MG'),
('Bahia', 'BA'),
('Espirito Santo', 'ES');

insert into cidades(nome, estado_id) values ('Criciúma', 1),
('Tubarão', 1),
('Florianópolis', 1),
('Porto Alegre', 2),
('Gramado', 2),
('Pelotas', 2),
('Curitiba', 3),
('Londrina', 3),
('Foz do Iguaçu', 3),
('São Paulo', 4),
('Campinas', 2),
('São José dos Campos', 4),
('Rio de Janeiro', 5),
('Búzios', 5),
('Petrópolis', 5),
('Belo Horizonte', 6),
('Pato de minas', 6),
('Patrocínio', 6),
('Salvador', 7),
('Feira de Santana', 7),
('Barreiras', 7),
('Vitória', 8);

Comment
  1. Chris Pollach @Appeon
  2. Monday, 7 October 2019 14:55 PM UTC
Hi David ... yes, a ";" after every command block. :-)
  1. Helpful
  1. David Peace (Powersoft)
  2. Monday, 7 October 2019 15:35 PM UTC
Indeed Chris, But I had to prove it first ;-)
  1. Helpful
There are no comments made yet.
Michael Kramer Accepted Answer Pending Moderation
  1. Friday, 4 October 2019 20:46 PM UTC
  2. PowerBuilder
  3. # 2

Hey Romulo,

What DBMS are you using? It looks like SQL Anywhere but to be sure before troubleshooting further

Thanks /Michael

Comment
  1. David Peace (Powersoft)
  2. Monday, 7 October 2019 13:22 PM UTC
I'm with Michael... What DB are you targeting?
  1. Helpful
  1. Michael Kramer
  2. Monday, 7 October 2019 14:37 PM UTC
Code is definitely SQL Anywhere - without semicolons required by PB IDE's Interactive SQL.

I have often seen complaints that ASE/MSSQL/Oracle fail to execute SQLAny syntax. :)
  1. Helpful
  1. Rômulo Sorato
  2. Friday, 1 November 2019 14:40 PM UTC
It´s Sybase!
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.