SQL Server DDL "error Incorrect syntax near ')'." - sql

I have the follow DDL query,
query failed:
CREATE TABLE "auxilio_saude_v2"."Solicitacao"
(
"IdSolicitacao" int NOT NULL IDENTITY(1,1),
"Descricao" varchar(-1) NOT NULL,
"Estado" varchar(255) NOT NULL,
"MotivoRecusa" varchar(255),
"BeneficiarioDboIdVinculo" int NOT NULL,
"CadastroDboIdVinculo" int NOT NULL,
"CadastroData" datetime CONSTRAINT "DF_cd6a13f4e589eeff45ef3b3a8ea" DEFAULT getdate(),
"InicioData" datetime CONSTRAINT "DF_4ae713eccf3d4346f40d25c8fe1" DEFAULT getdate(),
"FinalData" datetime,
CONSTRAINT "PK_348326c6affdf7e7d271ac6d672" PRIMARY KEY("IdSolicitacao")
)
But, it's giving me an error when exectuted:
ErrorMessageToken {
name: 'ERROR',
event: 'errorMessage',
number: 102,
state: 1,
class: 15,
message: "Incorrect syntax near ')'.",
serverName: 'SRVALDESENV',
procName: '',
lineNumber: 1
}
I'm no seeing the problem. Could somebody help me?

This is because of this line of your code:
"Descricao" varchar(-1) NOT NULL,
You can not use a negative value for varchar.
This is the syntax of VARCHAR :
varchar [ ( n | max ) ]
Use n to define the string size in bytes and can be a value from 1 through 8,000 or use max to indicate a column constraint size up to a maximum storage of 2^31-1 bytes (2 GB).
Learn more

Related

How do I fix my my table so I don't get that the invalid datatype message?

I am trying to create a table in SQL and every time it I get the following error message:
ORA-00902: invalid datatype
SQL> create table BUSINESS (
2 B_IDINTEGER PRIMARY KEY,
3 B_CITYchar(20) not null,
4 B_NAMECHAR (20) NOT NULL,
5 B_CATEGORY(S) CHAR (25),
6 B_ACCTCHAR (25)
7 );
B_CITYchar(20) not null,
*
ERROR at line 3:
ORA-00902: invalid datatype
It is supposed to say table created but I don't know what is wrong with line 3.
You have several errors in your code. Try something like this:
create table BUSINESS (
B_ID INTEGER PRIMARY KEY,
B_CITY varchar2(20) not null,
B_NAME varchar2(20) NOT NULL,
B_CATEGORY varchar2(25),
B_ACCT varchar2(25)
);
Note that you should generally use variable length strings unless you know the value has a fixed length (which might be true of b_acct but is not true for b_city).

PHPmyadmin won't accept CREATE TABLE statement

I'm trying to use a simple CREATE TABLE statement to create a new table in my very first SQL-database. PHPmyadmin won't accept the code and gives me an error statement.
There doesn't appear to be anything wrong with the syntax of my SQL command. In fact, I receive the same error statement when I copy and past an example code from any internet tutorial to create a table.
this is my SQL command:
CREATE TABLE Guestbook(
ID int AUTO_INCREMENT PRIMARY KEY NOT NULL,
Name varchar(50) NOT NULL,
Message TEXT NOT NULL,
Date datetime,
Sport varchar(30),
Practicioner BOOLEAN default 0,
)
This is the error statement:
Static analysis:
3 errors were found during analysis.
A symbol name was expected! (near "Name" at position 74)
Unexpected beginning of statement. (near "50" at position 87)
Unrecognized statement type. (near "NOT NULL" at position 91)
SQL query:
CREATE TABLE Guestbook( ID int AUTO_INCREMENT PRIMARY KEY NOT NULL, Name varchar(50) NOT NULL, Message TEXT NOT NULL, Date datetime, Sport varchar(30), Practicioner BOOLEAN default 0, )
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 8
I can't imagine why this won't work. I'd like to be able to use to command line in phpMyadmin. and this seems pretty straigtht forward. Yet I've been fiddling around with it for ages and I can't figure out how to create even the simplest possible table.
Can anyone help me out?
You should remove the last comma in your CREATE statement:
CREATE TABLE Guestbook(
ID int AUTO_INCREMENT PRIMARY KEY NOT NULL,
Name varchar(50) NOT NULL,
Message TEXT NOT NULL,
Date datetime,
Sport varchar(30),
Practicioner BOOLEAN default 0
)

Syntax errors whilst creating a table in MonetDB

This is driving me mad and I'm at the point where I'm thinking I must just be missing something very obvious. We are setting up a MonetDB environment with SQiurrel. I though the challenge would be wiring that all up and getting the drivers to work, but as it turns out that is running and I can see the DB in all its glory.
I have a DB in MySQL that I need to rebuild so I just generated the code:
CREATE TABLE "some_database"."some_table" (
key int(11) NOT NULL AUTO_INCREMENT,
column_1 varchar(10) DEFAULT NULL,
column_2 varchar(10) DEFAULT NULL,
column_3 varchar(10) DEFAULT NULL,
column_4 varchar(10) DEFAULT NULL,
column_5 varchar(10) DEFAULT NULL,
column_6 int(11) DEFAULT NULL,
column_7 decimal(10,2) DEFAULT NULL,
column_8 decimal(10,2) DEFAULT NULL,
column_9 int(11) DEFAULT NULL,
PRIMARY KEY (key)
) ENGINE=InnoDB AUTO_INCREMENT=20189170 DEFAULT CHARSET=utf8;
The only difference is that I've changed the column and table names. I'm not sure if this is all compatible for a start but I figured I would just work my way around it as it chucked errors. The first was about using a `. MonetDB seems to not like you.
I removed those and now I get:
Error: syntax error, unexpected '(', expecting ')' or ',' in: "create table "some_database"."some_table" (
SQLState: 42000
ErrorCode: 0
Error: fact_key int("
SQLState: 22000
ErrorCode: 0
For the "key" column I'm also getting the int(11) turn red and tell me I have an "EOF Expected"
If I quickly type out my own CREATE TABLE statement I can create a tables with a type varchar. As soon as I add in an int type it goes mad again.
So for example I just created this table in MonetDB:
CREATE TABLE "some_database"."some_table"
(
something varchar(10),
something2 varchar(10)
);
That worked fine. As soon as I add an int type:
CREATE TABLE "some_database"."some_table"
(
something varchar(10),
something2 varchar(10),
something3 int(10)
);
It goes a bit mental again:
Error: syntax error, unexpected '(', expecting ')' or ',' in: "create table "some_database"."some_table"
SQLState: 42000
ErrorCode: 0
Error: (
SQLState: 22000
ErrorCode: 0
Error: something varchar(10),
SQLState: 22000
ErrorCode: 0
Error: something2 varchar(10),
SQLState: 22000
ErrorCode: 0
Error: something3 int("
SQLState: 22000
ErrorCode: 0
So my question is have I set something up wrong? MonetDB seems to be running well and I can explore everything as one would expect in SQiurrel. I can create basic tables with varchar but as soon as I bring in an int the computer says no. I also don't understand what EOF means? I assumed it was expecting an , but it has that?
Thanks in advance. I'm hoping I just need a fresh mind who knows MonetDB to tell me why I'm missing the obvious!
I think I've worked out my issue. Hopefully someone who is learning their way around MonetDB may find this and save themselves some effort.
The syntax for an int is different.
Rather than:
int(11)
You must just type:
int
Once I removed the (11) from each int in my create statement it ran.

Type Mismatch Null value SQL

I'm having a problem with Null values in my CREATE TABLE for some reason...It's giving me this error message:
Msg 4864, Level 16, State 1, Line 73
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 4, column 7 (Manager).
Here's my code and the data I'm using:
CREATE TABLE SalesReps
(
EmpNum SMALLINT NOT NULL ,
Name VARCHAR(20) NOT NULL,
Age TINYINT NOT NULL,
RepOffice TINYINT NULL,
Title VARCHAR(20) NULL,
HireDate DATE,
Manager INT NULL,
Quota MONEY NULL,
Sales MONEY DEFAULT 0
)
BULK INSERT SalesReps
FROM 'C:\Users\Steve\Desktop\salesreps.txt'
WITH ( FIELDTERMINATOR = '|',
ROWTERMINATOR = '\n')
Data:
105|Bill Adams|37|13|Sales Rep|02/12/88|104|350000.00|367911.00
109|Mary Jones|31|11|Sales Rep|10/12/89|106|300000.00|392725.00
102|Sue Smith|48|21|Sales Rep|12/10/86|108|350000.00|474050.00
106|Sam Clark|52|11|VP Sales|06/14/88|NULL|275000.00|299912.00
104|Bob Smith|33|12|Sales Mgr|05/19/87|106|200000.00|142594.00
101|Dan Roberts|45|12|Sales Rep|10/20/86|104|300000.00|305673.00
110|Tom Snyder|41|NULL|Sales Rep|01/13/90|101|NULL|75985.00
108|Larry Fitch|62|21|Sales Mgr|10/12/89|106|350000.00|361865.00
103|Paul Cruz|29|12|Sales Rep|03/01/87|104|275000.00|286775.00
107|Nancy Angelli|49|22|Sales Rep|11/14/88|108|300000.00|186042.00
Can anyone please help? I've looked at the other mismatch pages but they aren't helping much. I've been stuck on this for days.
The bulk insert on row 4 includes a value NULL, but I think that SQL Server interprets this as string containing 'NULL'. You can try to change row 4 with that :
106|Sam Clark|52|11|VP Sales|06/14/88||275000.00|299912.00
You will also have the same problem on row 7, your column Quota which expects a MONEY type, but a string containing NULL is provided.

JavaDB throws error when boolean is used. why?

This is the table I try to create in JavaDB.
CREATE TABLE USER(
userid INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
displayName VARCHAR(20) not null,
username VARCHAR(15) not null unique,
password VARCHAR(15) not null,
adminrole boolean default false,
lastlogin timestamp default CURRENT TIMESTAMP
);
I get Error code -1, SQL state 42X01: Syntax error: BOOLEAN.
Line 3, column 1
You have to use JavaDB Version 10.7 or later and also upgrade your database to new version too.