SAP DBTech JDBC: [257] (at 14): sql syntax error: missing column definition - hana

I want to create table in SAP HANA and my query is as follow:
create column table test12 (ID INTEGER, NAME VARCHAR(10), PRIMARY KEY (ID));
and I encounter the problem
sql syntax error: missing column definition: line 1 col 21 (at pos 21)
I am new to HANA and I dont know how to get column definition, so please guide me.
Thank you in advance!

Related

Cockroachdb varchar column length isn't flexible

I have a spring boot application that connects to Cockroachdb. I have the following script in my flyway using which the table gets created:
CREATE TABLE IF NOT EXISTS sample_table (
name varchar,
groups varchar,
PRIMARY KEY (name));
The application starts fine, but whenever there is a value for the 'groups' column that is greater than 255 length, I get an error :
Caused by: org.postgresql.util.PSQLException: ERROR: value too long for type VARCHAR(255)
In the sql script, I have mentioned the column 'groups' as 'varchar' which should not restrict the length so I am not sure why am I getting this error.
There isn't an implicit default limit on varchar in CockroachDB. This error indicates that the groups column was initialized with the type varchar(255) when the table was created. Running SHOW CREATE TABLE sample_table; should confirm this.
It's possible that something unexpected is going on in the flyway and the table is not being created how you want it to be created.

New to SQL and already having an issue

I'm doing a group project to learn SQL, I'm using jdoodle as an online IDE for now and w3schools. I feel so weird for asking this because this is literally my first attempt but I get an error.
CREATE DATABASE turing;
CREATE TABLE Suppliers (
SupplierNumber int,
SupplierName varchar(255),
SupplierAddress varchar(255),
);
Error: near line 1: in prepare, near "DATABASE": syntax error (1)
Error: near line 2: in prepare, near ")": syntax error (1)
I'm just like copying exactly what w3schools taught me?
I don't see any errors in here, But these are some best practises,
RUN the SQL queries one by one in case if that's causing the error. First create the Database and then Create the Table. Do both seperately.
CREATE TABLE Suppliers (
supplierNumber int PRIMARY KEY NOT NULL,
supplierName varchar(255),
supplierAddress varchar(255)
);
Best practise is to have the column names in lowerCamelCase.
Normally we don't use comma for the last line. It is Unnecessary
Having a Primary key for every table is good. Make it PRIMARY KEY and NOT NULL at the same time to prevent some error in the future.

Hana DB is not allowing nulls in a nullable field

My shema looks like this:
CREATE TABLE newsletter_status(
identificationnumber BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 0) NOT NULL PRIMARY KEY,
bpid varchar(10),
consumer varchar(4) NOT NULL,
source varchar(10),
vkorg varchar(4) NOT NULL,
cryptid varchar(255) NOT NULL,
status varchar(25),
regDat timestamp,
confirmDat timestamp,
updateDat timestamp
);
CREATE TABLE scpnewsletter (version varchar(255));
CREATE INDEX bpid_index ON newsletter_status (bpid);
CREATE INDEX cryptid_index ON newsletter_status (cryptid);
Running locally in a H2-Database this works fine with insertions. Inserting a object which fields consumer,source,vkorg,cryptid and status ARE set, others dont. The Database should generate an identificationnumber. And the H2 does
When run on the customer DEV environment with a HANA DB the insertion fails, saying that:
PreparedStatementCallback; uncategorized SQLException for SQL [INSERT INTO newsletter_status (identificationnumber,bpid,consumer,source,vkorg,cryptid,status,regDat,confirmDat,updateDat) VALUES (?,?,?,?,?,?,?,?,?,?)]; SQL state [HY000]; error code [287]; SAP DBTech JDBC: [287]: cannot insert NULL or update to NULL: Not nullable "IDENTIFICATIONNUMBER" column; nested exception is com.sap.db.jdbc.exceptions.JDBCDriverException: SAP DBTech JDBC: [287]: cannot insert NULL or update to NULL: Not nullable "IDENTIFICATIONNUMBER" column
It does not likes that the Identificationnumber is null.
Going further. If I add an Identificationnumber it says the same thing about bpid:
PreparedStatementCallback; uncategorized SQLException for SQL [INSERT INTO newsletter_status (identificationnumber,bpid,consumer,source,vkorg,cryptid,status,regDat,confirmDat,updateDat) VALUES (?,?,?,?,?,?,?,?,?,?)]; SQL state [HY000]; error code [287]; SAP DBTech JDBC: [287]: cannot insert NULL or update to NULL: Not nullable "BPID" column; nested exception is com.sap.db.jdbc.exceptions.JDBCDriverException: SAP DBTech JDBC: [287]: cannot insert NULL or update to NULL: Not nullable "BPID" column
bpid can clearly be null in the shema. This ambiguity in consuming field confuses.
If both bpid and Identificationnumber are set, then the is not Problem with the database.
I want to store an object that both of this ids can be null, but also want an unique id for Identificationnumber.
I cant debug on the DEV env from the customer. Any Idea what possibly could go wrong here?
Ok, so your IDENTIFICATIONNUMBER can never ever be NULL.
Based on the DDL provided, it has a NOT NULL constraint and is the single-column primary key, which implicitly makes it NOT NULL.
If H2 allows NULL inserts, that's an H2 bug/incompliant behavior.
Concerning the BPID column it looks like you're still trying to insert the value for IDENTIFICATIONNUMBER even though this value is defined as IDENTITY column. I assume, that by specifying NULL as a value for it, you want to make HANA use the DEFAULT value (the sequence).
If that's correct, then the answer is: it does not work this way.
Also: the error message wrongly named BPID as the problematic field.
The correct way to use DEFAULT values in INSERT statements in HANA is to leave the columns for which the DEFAULT values should be used, out from the column list.
SQL standard also has the option to use the DEFAULT keyword, but that's (currently, HANA 2 SPS 04) not supported.

SQL Error about syntax error(POSTGRES)

I always get the error on postgres sql can anyone help me
ERROR: Syntaxerror in „(“ LINE 4: Liga_Nr int(1),
^
********** ERROR **********
ERROR: Syntaxerror in „(“ SQL Status:42601 Symbol:79
Here is my code
DROP TABLE IF EXISTS Liga;
Create Table Liga(
Verband varchar(90),
Liga_Nr int(1),
PRIMARY KEY(Liga_Nr)
);
DROP TABLE IF EXISTS Spiel;
CREATE Table Spiel(
);
DROP TABLE IF EXISTS Verein;
CREATE Table Verein(
);
DROP TABLE IF EXISTS Spieler;
CREATE Table Spieler(
PRIMARY KEY(Spieler_ID)
);
Integer types don't accept a parameter. The correct code is:
Create Table Liga(
Verband varchar(90),
Liga_Nr int,
PRIMARY KEY(Liga_Nr)
);
If you want to store a small number, use smallint. You can read about numeric types here.

sql server modify error

i m not able to modify table in SQL server. i m new to databases.
use work
go
alter table employee
modify id varchar(20)
error message is-
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'modify'
here is an screenshot
thanks
You have the syntax for altering a table wrong. You need:
ALTER TABLE YourTable
ALTER COLUMN ExistingColumn VARCHAR(20)
The syntax should be
ALTER TABLE Employee ALTER COLUMN ID VarChar (20)
Here is the ALTER COLUMN syntax.
http://msdn.microsoft.com/en-us/library/ms190273.aspx
Now, having said all that, I have a question for you.. Why is your ID column a VarChar as opposed to an Identity Column?