SybSQLException: Attempt to update or insert row failed because resultant row of size larger than 1962 bytes - sybase

I'm getting this error with sybase while updating records to my table. Below is my table definition
CREATE TABLE BATCH_STEP_EXECUTION (
STEP_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY ,
VERSION BIGINT NOT NULL,
STEP_NAME VARCHAR(100) NOT NULL,
JOB_EXECUTION_ID BIGINT NOT NULL,
START_TIME DATETIME NOT NULL ,
END_TIME DATETIME DEFAULT NULL NULL,
STATUS VARCHAR(10) NULL,
COMMIT_COUNT BIGINT NULL,
READ_COUNT BIGINT NULL,
FILTER_COUNT BIGINT NULL,
WRITE_COUNT BIGINT NULL,
READ_SKIP_COUNT BIGINT NULL,
WRITE_SKIP_COUNT BIGINT NULL,
PROCESS_SKIP_COUNT BIGINT NULL,
ROLLBACK_COUNT BIGINT NULL,
EXIT_CODE VARCHAR(2500) NULL,
EXIT_MESSAGE VARCHAR(2500) NULL,
LAST_UPDATED DATETIME,
constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID)
references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID)
) ;
Below is the error message
org.springframework.dao.DataIntegrityViolationException:
PreparedStatementCallback;
SQL [UPDATE BATCH_STEP_EXECUTION set START_TIME = ?, END_TIME = ?, STATUS =
?,
COMMIT_COUNT = ?, READ_COUNT = ?, FILTER_COUNT = ?, WRITE_COUNT = ?,
EXIT_CODE = ?,
EXIT_MESSAGE = ?, VERSION = ?, READ_SKIP_COUNT = ?, PROCESS_SKIP_COUNT = ?,
WRITE_SKIP_COUNT = ?, ROLLBACK_COUNT = ?, LAST_UPDATED = ? where
STEP_EXECUTION_ID = ?
and VERSION = ?]; Attempt to update or insert row failed because resultant
row of size
2633 bytes is larger than the maximum size (1962 bytes) allowed for this
table.
; nested exception is com.sybase.jdbc4.jdbc.SybSQLException: Attempt to
update or
insert row failed because resultant row of size 2633 bytes is larger than the
maximum
size (1962 bytes) allowed for this table.
These 2 columns are creating problem.

Related

Compute column insert

I have added a compute column, but I get an error when I insert the values, I left out the column name where the compute column is. I read somewhere that you don't include it in your insert.
Msg 110, Level 15, State 1, Line 641 There are fewer columns in the
INSERT statement than values specified in the VALUES clause. The
number of values in the VALUES clause must match the number of columns
specified in the INSERT statement.
CREATE TABLE Voorwerp (
voorwerpnummer BIGINT IDENTITY(30068720558,1)
NOT NULL,
titel VARCHAR(100)
NOT NULL,
beschrijving VARCHAR(max)
NOT NULL,
Startprijs NUMERIC(10,2)
NOT NULL,
Betalingswijze VARCHAR(20)
NOT NULL,
betalinginstructie VARCHAR(80)
NULL,
plaatsnaam VARCHAR(28)
NOT NULL,
Land VARCHAR(35)
NOT NULL,
Looptijd TINYINT DEFAULT ((7))
NOT NULL,
LooptijdbeginDag DATE
NOT NULL,
LooptijdbeginTijdstip TIME
NOT NULL,
Verzendkosten NUMERIC (8,2)
NULL,
verzendinstructies VARCHAR (125)
NULL,
Verkoper VARCHAR (255)
NOT NULL,
Koper VARCHAR (255)
NULL,
LooptijdeindeDag AS DATEADD(DAY,Looptijd,looptijdbeginDag),
looptijdeindeTijdstip TIME
NOT NULL,
VeilingGesloten BIT
NOT NULL,
Verkoopprijs NUMERIC(10,2)
NULL,
INSERT INTO Voorwerp(
[titel],
[beschrijving],
[Startprijs],
[Betalingswijze],
[betalinginstructie],
[plaatsnaam],
[Land],
[Looptijd],
[LooptijdbeginDag],
[LooptijdbeginTijdstip],
[Verzendkosten],
[verzendinstructies],
[Verkoper],
[Koper],
[LooptijdeindeDag],
[looptijdeindeTijdstip],
[VeilingGesloten])
VALUES('Stabiele drum/pi..',
'Stabiele drum/pi..',
50.00,
'Bank',
'Overschrijving moet...',
'New Vennep',
'Nederland',
7,
'2005-05-19',
'09:10:00',
3.50,
'Paket post binnen Nederland',
'Bianca77',
1,
'2005-05-26',
'09:30:00',
1,
500
);
Column LooptijdeindeDag is listed in the column list in the INSERT statement.
You need to remove it and it's corresponding value from the insert statement.
Your insert statement should looks like:
INSERT INTO Voorwerp(
[titel],
[beschrijving],
[Startprijs],
[Betalingswijze],
[betalinginstructie],
[plaatsnaam],
[Land],
[Looptijd],
[LooptijdbeginDag],
[LooptijdbeginTijdstip],
[Verzendkosten],
[verzendinstructies],
[Verkoper],
[Koper],
[looptijdeindeTijdstip],
[VeilingGesloten])

error ''there is already an object name in databases''

Can you help me fix the error
There is already an object name in database
My code:
CREATE DATABASE DIEMTHAMQUAN
USE DIEMTHAMQUAN
CREATE TABLE QUOCGIA
(
MAQG NCHAR(5) NOT NULL,
TENQG NCHAR(20) NULL,
TD NCHAR(5) NOT NULL,
DS INT NULL,
DT REAL NULL
CONSTRAINT PK_QUOCGIA PRIMARY KEY(MAQG,TD)
)
CREATE TABLE TINHTHANH
(
MATT NCHAR(5) NOT NULL,
QG NCHAR(5) NULL,
DS INT NULL,
DT REAL NULL,
TENTT NCHAR(30) NULL
CONSTRAINT PK_TINHTHANH PRIMARY KEY(MATT)
)
CREATE TABLE DIEMTHAMQUAN
(
MADTQ NCHAR(10) NOT NULL,
TENDTQ NCHAR(30) NULL,
TT NCHAR(5) NULL,
QG NCHAR(5) NULL,
DD NCHAR(50) NULL
CONSTRAINT PK_DIEMTHAMQUAN PRIMARY KEY(MADTQ)
)
ALTER TABLE TINHTHANH
ADD CONSTRAINT FK_TT_QG FOREIGN KEY(QG) REFERENCES QUOCGIA(MAQG)
ALTER TABLE DIEMTHAMQUAN
ADD CONSTRAINT FK_DTQ_TT FOREIGN KEY(TT) REFERENCES TINHTHANH(MATT)
--insert QUOCGIA(MAQG,TENQG,TD,DS,DT)
INSERT INTO QUOCGIA(MAQG, TENQG, TD, DS, DT)
VALUES (N'QG001', N'VIỆT NAM', N'TT001', CAST(N'115000000' AS INT), CAST(N'331688.00' AS REAL)),
(N'QG002', N'NHẬT BẢN', N'TT003', CAST(N'129500000' AS INT), CAST(N'337834.00' AS REAL))
--insert TINHTHANH(QG,MATT,TENTT,DS,DT)
INSERT INTO TINHTHANH(QG, MATT, TENTT, DS, DT)
VALUES (N'QG001', N'TT001', N'HÀ NỘI', CAST(N'2500000' AS INT), CAST(N'927.39' AS REAL)),
(N'QG001', N'TT002', N'HUẾ', CAST(N'5344000' AS INT), CAST(N'5009.00' AS REAL)),
(N'QG002', N'TT003', N'TOKYO', CAST(N'12084000' AS INT), CAST(N'2187.00' AS REAL))
The problem lies here:
CREATE TABLE DIEMTHAMQUAN
You are using the same name for the ‘Database’ and guving the same name to a ‘table’. If in future you call this ‘DIEMTHAMQUAN’ how would Sql-Server(if you are using this) know that you are referring to database or table.
Possible solution is to name your table ‘tblDIEMTHAMQUAN’.

Bulk load data conversion error, date type field in SQL Server

I have this uni assignment where I am given the script for the database as well as the one for the bulk insert and a dataset of about 1.300.000 records. With the database set up, i ran the bulk insert script and I am getting a bulk load data conversion error.
I asked all my friends if they had a similar experience but none of them had the same issue. I tried to look into that, it would seem that what causes this error to happen is the Date field in the MainTable, so i tried to find how to set the default date to DD/MM/YYYY and to use the / instead of -, all I found was some SELECT that formatted the getdate() function and the SET DATEFORMAT dmy command but that didn't fix my errors. I deleted the database and repeated the process at least 3 times now and I'm getting the same error every time.
CREATE TABLE MainTable
(
bookCode int NULL,
bookDt date NULL,
payCode int NULL,
payMethod char(2) NULL,
custCode int NULL,
custName varchar(30) NULL,
custSurname varchar (30) NULL,
custPhone varchar (20) NULL,
staffNo int NULL,
staffName varchar (30) NULL,
staffSurname varchar (30) NULL,
totalCost numeric(19, 2) NULL,
campCode char(3) NULL,
campName varchar (50) NULL,
numOfEmp int NULL,
empNo int NULL,
catCode char (1) NULL,
areaM2 int NULL,
unitCost numeric(4,2) NULL,
startDt date NULL,
endDt date NULL,
noPers int NULL,
costPerRental numeric(19, 2) NULL
);
SET DATEFORMAT dmy
BULK INSERT mainTable
FROM 'C:\DATA\GeneratedData.txt'
WITH (FIRSTROW = 2,FIELDTERMINATOR= ',', ROWTERMINATOR = '\n');
And a couple of records from the dataset:
2615981,14/08/2018,1,CC,990,Christie,BUCKNER,(+30)000-556-7301,5020,Zaria,RACE,45,ROS,Rosibos,200,151,C,30,15,15/08/2018,17/08/2018,1,45
2616347,17/08/2018,3,CA,403,Ashli,MAXWELL,(+30)000-114-8689,5010,Yovonnda,CAZARES,45,ROS,Rosibos,200,151,C,30,15,18/08/2018,20/08/2018,1,45
The error I am getting is this:
Msg 4864, Level 16, State 1, Line 3
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 2, column 2 (bookDt).
I am getting the same error what appears to be every single row in the text file.
Instead of "Set DateFormat dmy", try the following:
Set Language N'british'
Like I said in my comment, it's often easier to insert the data into a string type column in a staging table, and then convert the values afterwards. I've only done this with the Date columns here, but you can do it to the whole lot if you wish:
USE Sandbox;
GO
CREATE SCHEMA stg;
GO
CREATE TABLE stg.MainTable (bookCode int NULL,
bookDt varchar(10) NULL,
payCode int NULL,
payMethod char(2) NULL,
custCode int NULL,
custName varchar(30) NULL,
custSurname varchar(30) NULL,
custPhone varchar(20) NULL,
staffNo int NULL,
staffName varchar(30) NULL,
staffSurname varchar(30) NULL,
totalCost numeric(19, 2) NULL,
campCode char(3) NULL,
campName varchar(50) NULL,
numOfEmp int NULL,
empNo int NULL,
catCode char(1) NULL,
areaM2 int NULL,
unitCost numeric(4, 2) NULL,
startDt varchar(10) NULL,
endDt varchar(10) NULL,
noPers int NULL,
costPerRental numeric(19, 2) NULL);
GO
BULK INSERT stg.MainTable
FROM 'C:\DATA\GeneratedData.txt'
WITH (FIRSTROW = 2,
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n');
GO
CREATE TABLE dbo.MainTable (bookCode int NULL,
bookDt date NULL,
payCode int NULL,
payMethod char(2) NULL,
custCode int NULL,
custName varchar(30) NULL,
custSurname varchar(30) NULL,
custPhone varchar(20) NULL,
staffNo int NULL,
staffName varchar(30) NULL,
staffSurname varchar(30) NULL,
totalCost numeric(19, 2) NULL,
campCode char(3) NULL,
campName varchar(50) NULL,
numOfEmp int NULL,
empNo int NULL,
catCode char(1) NULL,
areaM2 int NULL,
unitCost numeric(4, 2) NULL,
startDt date NULL,
endDt date NULL,
noPers int NULL,
costPerRental numeric(19, 2) NULL);
GO
INSERT INTO dbo.MainTable
SELECT bookCode,
CONVERT(date, bookDt, 103),
payCode,
payMethod,
custCode,
custName,
custSurname,
custPhone,
staffNo,
staffName,
staffSurname,
totalCost,
campCode,
campName,
numOfEmp,
empNo,
catCode,
areaM2,
unitCost,
CONVERT(date, startDt, 103),
CONVERT(date, endDt, 103),
noPers,
costPerRental
FROM stg.MainTable;
TRUNCATE stg.MainTable;

Postgresql For loop with update inside function

I'm trying to use a postgresql function to initiate a query against a couple of tables and then do an insert into another table if the criteria are met. I'm getting errors around the declaration or the return statement every time. Any help is appreciated.
Basically this should:
Loop against the health_alerts_triggered table and use field data in each row to then query the "healthEvents" table
If the count in the subquery for "healthEvents" returns greater than zero rows and insert should be done into the health_alerts_triggered table.
CREATE OR REPLACE FUNCTION sp_alertcheck()
RETURNS SETOF record;
DECLARE r record;
FOR r IN SELECT *
FROM health_alerts_config
LOOP
INSERT INTO health_alerts_triggered (health_affiliate_id, alert_format,alert_minutes, health_client_internal_id, alert_triggered_date, alert_processed_date, alert_id, affiliate_name, client_name)
VALUES (r.health_affiliate_id, r.alert_format, r.alert_minutes, r.health_client_internal_id, now() as alert_triggered_date, '' as alert_processed_date, id, ha.health_affiliate_description, hc.health_client_description)
WHERE (SELECT COUNT(*) from "heatlhEvents" he
WHERE he.format = r.format,
AND he.healthaffiliatclientid = r.health_affiliate_description,
AND he.timestamp > Now() - r.minutes
)
> 0
INNER JOIN health_affiliates ha
ON r.health_affiliate_id = ha.id
INNER JOIN health_clients hc
ON r.health_client_internal_id = hc.id
END LOOP;
RETURN result;
$BODY$
LANGUAGE plpgsql;
Schema for health_alerts_config:
CREATE TABLE public.health_alerts_config
(
id bigint NOT NULL DEFAULT nextval('"healthAlerts_id_seq"'::regclass),
health_affiliate_id bigint NOT NULL,
alert_format character varying(10) COLLATE pg_catalog."default" NOT NULL,
alert_minutes integer NOT NULL,
health_client_internal_id bigint NOT NULL,
CONSTRAINT health_alerts_pkey PRIMARY KEY (id)
)
Sample row: 1,1,ADT,60,1
Schema for health_affiliates
CREATE TABLE public.health_affiliates
(
id bigint NOT NULL,
health_affiliate_description character varying(50) COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT health_affiliates_pkey PRIMARY KEY (id)
)
Sample row: 1, 'TestCo'
Schema for health_clients
CREATE TABLE public.health_clients
(
id integer NOT NULL DEFAULT nextval('"healthClients_id_seq"'::regclass),
health_affiliate integer NOT NULL,
health_client_id character varying(20) COLLATE pg_catalog."default" NOT NULL,
health_client_description character varying(100) COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT id_pk PRIMARY KEY (id)
)
Sample row: 1, 1, 200, 'TestCoClient'
Schema for "healthEvents"
CREATE TABLE public."healthEvents"
(
"ID" integer NOT NULL DEFAULT nextval('"healthEvents_ID_seq"'::regclass),
"fileName" character varying(100) COLLATE pg_catalog."default" NOT NULL,
"instanceName" character varying(20) COLLATE pg_catalog."default" NOT NULL,
"channelName" character varying(50) COLLATE pg_catalog."default" NOT NULL,
affiliate character varying(20) COLLATE pg_catalog."default" NOT NULL,
"fileSizeKB" bigint,
"beginProcessing" timestamp without time zone,
"endProcessing" timestamp without time zone,
resubmission boolean NOT NULL,
destination integer NOT NULL,
"insertTime" timestamp without time zone NOT NULL DEFAULT now(),
"messageID" bigint NOT NULL,
direction integer NOT NULL,
"affiliateClient" character varying(40) COLLATE pg_catalog."default" NOT NULL,
"messageType" character varying(15) COLLATE pg_catalog."default",
"messageStatus" integer,
"messageCode" character varying(10) COLLATE pg_catalog."default",
"insertDate" date DEFAULT ('now'::text)::date,
"affiliateClientID" character varying(50) COLLATE pg_catalog."default",
CONSTRAINT "PK" PRIMARY KEY ("ID")
)
I don't think you even need a loop here. I'd do something like (untested):
INSERT INTO health_alerts_triggered (
health_affiliate_id, alert_format, alert_minutes, health_client_internal_id,
alert_triggered_date, alert_processed_date, alert_id,
affiliate_name, client_name
)
SELECT
r.health_affiliate_id, r.alert_format, r.alert_minutes, r.health_client_internal_id,
now() as alert_triggered_date, '' as alert_processed_date, id,
ha.health_affiliate_description, hc.health_client_description
FROM
health_alerts_config r
INNER JOIN health_affiliates ha
ON r.health_affiliate_id = ha.id
INNER JOIN health_clients hc
ON r.health_client_internal_id = hc.id
WHERE
exists(
SELECT 1
FROM "heatlhEvents" he
WHERE he.format = r.format,
AND he.healthaffiliatclientid = r.health_affiliate_description,
AND he.timestamp > now() - r.minutes
)
;

Inserting into a table to by pass constraints

maybe I can get some feedback from some folks on this. I created two tables and inserted data into one table and i put a constraint (Foreign key) on the table std_individual_address.
I get the following error message when I try to execute the insert now:
Msg 515, Level 16, State 2, Line 43 Cannot insert the value NULL into
column 'individual_GUID', table 'ABLE.dbo.std_individual_address';
column does not allow nulls. INSERT fails. The statement has been
terminated.
Here is all my code:
--Create the std_individual table
CREATE TABLE std_individual(
individual_GUID INT NOT NULL IDENTITY,
individual_First_Name VARCHAR(50) NULL,
individual_Last_Name VARCHAR(50) NULL,
individual_email VARCHAR(40) NULL,
PRIMARY KEY (individual_GUID));
--Create the std_individual_address table
CREATE TABLE std_individual_address
(
individual_address_GUID INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
individual_address_line1 VARCHAR(100) NULL,
individual_address_line2 VARCHAR(100) NULL,
individual_address_line3 VARCHAR(100) NULL,
individual_address_city VARCHAR(50) NULL,
individual_address_state VARCHAR(30) NULL,
individual_address_zipcode VARCHAR(30) NULL,
individual_GUID INT NOT NULL,
CONSTRAINT fk_std_individual_address_std_individual FOREIGN KEY (individual_GUID) REFERENCES std_individual (individual_GUID)
)
--Insert Individual Data
INSERT INTO std_individual
(individual_First_Name,individual_Last_Name,individual_email)
VALUES
('Terry','Smith','tsmith#example.net'),
('Ronald','Smegan','ronald#example.net'),
('Arnold','Aggassi','aaggassi#example.edu'),
('Jerry','Brukheimer','bbrukheimer#example.edu');
--Mind the Constraint
INSERT INTO std_individual_address(individual_GUID) SELECT individual_GUID from std_individual
--Attempt to insert rest of the data
INSERT INTO std_individual_address
(individual_address_line1,individual_address_line2,individual_address_city,individual_address_state,
individual_address_zipcode )
VALUES
('8200 Greensboro Drive','Ste 1500','Mclean','Virgina','22102'),
('1121 14th Street, NW','Ste 1000','Washington' ,'District of Columbia','20005'),
('1700 Connecticut Ave,NW','Ste 300','Washington' ,'District of Columbia','20009'),
('205 Pennsylvania Ave,SE','','Washington','District of Columbia','20003');
Then I get the error message above. Any ideas on how to combat that issue?

Resources