SQL Server invalid object name insert - sql

Recently I realized I should have a primary key in this table, so I tried to add one by doing the following steps:
Added a new column with nullable values
Filled all the values with integers indexed from 1 - 178
Made the column not allow nulls - this saved fine with no warnings that there
were still null values
I set the identity column to Id (new column I created)
Tried to insert a new row and got the following message
Msg 208, Level 16, State 74, Procedure tr_dbo_SaveState_7d7e8c09-470a-4510-ac78-12bf952f3a14_Sender, Line 63 [Batch Start Line 0]
Invalid object name 'dbo_SaveState_7d7e8c09-470a-4510-ac78-12bf952f3a14/StartMessage/Insert'.
I thought maybe I had to set the identity seed to the lastvalue+1 but still got the same message. I can insert into other tables just fine, and when I put the wrong number of arguments into the VALUES() function I get a different (expected) error, but when doing what I do for other tables, and used to do for this table I now get the above error. Does it seem the insert function is missing for this table? BTW this user has all permissions so that shouldn't be an issue
I also tried undoing this but it seems like the INSERT method for this table has just been deleted, or is somehow unavailable.
I can still select from the table just fine
When I try to update values I don't get the error message if the WHERE clause always results to false, but if there is a row that it tries to update I get an error message - this is not the case when I right-click on the table and Edit top 200 rows, only when I try and do it through query

Related

I have a script to append values into a 2 tables.While executing the script it is showing error

Msg 2601, Level 14, State 1, Procedure Trig_InsertToInvoiceDetails,
Line 45 Cannot insert duplicate key row in object
'dbo.TT_InvoiceDetails' with unique index 'idx_Invdtl'. The duplicate
key value is (152245, 2018/03/IC17-334, 135). The statement has been
terminated.
But what ever i am passing those are unique values only
There are 2 cases
Against unique index 'idx_Invdtl'there is chances already row saved with values 152245, 2018/03/IC17-334, 135)
Secondly, your saving process works not well it is passing same values for saving.

Invalid Column Name when Inserting Data

I have a local installation of SQLExpress, and accessing it using SQL Server Management Studio.
I created a new database BirdSite in SSMS, with a single table TMasterCountry, with these columns:
Id (int)
CountryName (varchar(50))
where Id is the primary, auto-incrementing key.
When I use the Script table as... option in the object explorer, I am able to view the empty table with this bit of SQL:
USE [BirdSite]
GO
SELECT [Id]
,[CountryName]
FROM [dbo].[TMasterCountry]
GO
without any issues.
However, using the same option to try inserting some data, brings up this SQL:
USE [BirdSite]
GO
INSERT INTO [dbo].[TMasterCountry]
([CountryName])
VALUES
(<CountryName, varchar(50),>)
GO
So I changed the line under VALUES to
(CountryName, 'test')
But when I try running the code, I get these errors:
Msg 207, Level 16, State 1, Line 4
Invalid column name 'CountryName'.
Msg 110, Level 15, State 1, Line 4
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.
Does anyone know what might be going on here? The column clearly does exist, as I can SELECT the data just fine.
Following some similar questions on SO, I have tried restarting SSMS and also tried refreshing the local Intellisense cache, but with no luck. I also tried surrounding CountryName in square brackets but with the same result.
Change it to:
USE [BirdSite]
GO
INSERT INTO [dbo].[TMasterCountry]
([CountryName])
VALUES
('test')
GO
<CountryName, varchar(50),> refers to name of column and it's datatype.
Syntax error; Should be
INSERT INTO [dbo].[TMasterCountry]
([CountryName])
VALUES
('test')
You need to replace the entire content between < and > with the value:
INSERT INTO [dbo].[TMasterCountry]
([CountryName])
VALUES
('test')

Datastage Job terminating due to the following error

I'm running a data stage job, Input through DB2 and output to DB2. Input side has a query containing joins and functions.
I'm getting the following warning message;
TRN_HEALTH_INSURANCE_DETAIL,
2: STATEMENT
INSERT
INTO
HEALTH_INSURANCE_DETAIL
(
RISK_DETAIL_ID,
RISK_COVER_ID,
RD_POLICY_SYSTEM_NO,
RD_POLICY_END_NO_IDX,
RD_POLICY_ID,
RD_LEVEL1_ID,
RD_SUM_INSURED_AMT_LC,
RD_PREMIUM_AMT_LC,
PREMIUM_AMOUNT_FC,
SUM_INSURED_AMT_FC,
RD_REC_TYPE,
RD_EFFECT_FROM_DT,
RD_EFFECT_TO_DT,
RD_END_EFFECT_FROM_DT,
SEX_MAS_CD,
MARITAL_STATUS_CD,
EMP_CATG,
NO_OF_DEPENDENTS,
EMP_AL_NO,
DOB,
EFF_DATE,
EFF_DATE2,
NAME,
RELATIONSHIP_CD_S,
RELATIONSHIP_CD,
DESIGNATION,
BRANCH,
BANK_ACCOUNT,
BANK_BRANCH_NAME,
PRE_EXISTING_AILMENT,
AUTHORITY_LETTER_NO,
AGE,
REGION,
CNIC,
CO_CODE,
EMP_LOCATION,
SUB_LOCATION,
CLH_SYSTEM_NO,
CTH_SYS_ID,
CTH_POL_SYS_ID,
CTH_END_NO_IDX,
CTH_END_SR_NO,
CTH_CATEGORY,
CLD_SYS_ID,
CLDH_SYS_ID,
CLD_COVER_CD,
CLD_END_IDX,
CLD_COVER_DESC,
CLD_CLM_TYPE_LIMIT,
CLD_CLM_REL,
CLD_CLM_AGE_FROM,
CLD_CLM_AGE_TO,
CLD_CLM_RB_LIMIT,
CLD_CATEGORY_LIMIT_FC,
CLD_CATEGORY_PREM_FC
)
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) failed to run.
I cant see such records in my data. The data quality is good. Then what are these ????, I search a bit and found a suggestion to keep the array size and row count to 1, instead of default 2000. But still I'm getting the same warning.
There are a lot of errors followed by this warning; The next error is also interesting.
TRN_HEALTH_INSURANCE_DETAIL,2: SQLExecute reported: SQLSTATE = 23505: Native Error Code = -803: Msg = [IBM][CLI Driver][DB2/NT64] SQL0803N One or more values in the INSERT statement, UPDATE statement, or foreign key update caused by a DELETE statement are not valid because the primary key, unique constraint or unique index identified by "1" constrains table "DB2ADMIN.HEALTH_INSURANCE_DETAIL" from having duplicate values for the index key. SQLSTATE=23505 (CC_DB2DBStatement::executeInsert, file CC_DB2DBStatement.cpp, line 1,095)
I believe the errors are due to the first warning. Kindly help me out.
Regards, Nuh
Make a copy stage before the DB2 connector and put one link to the DB2 and the other to a dataset file to see the data in a data set. But the problem seems to be in the primary key you have a duplicate primary index or a duplicate unique index. It can be either in your data that you want to insert or maybe the table already have a record that you want to insert again

Find the exact line number of error in sql script

I am trying to insert nearly 1000 records for each insert statement in to a table called ZonePlaces. This table is having an Index.
When i try to run the script for insert on this table it throws error
Msg 2601, Level 14, State 1, Line 56
Cannot insert duplicate key row in object 'dbo.ZonePlaces' with unique index 'IX_ZonePlaces'.
Line 56 is start of Insert statement.
I know i am inserting something duplicate value but is there a way to find which exact line number has the error?
Hope i am clear.

Database protected from edit?

If I see this at the bottom of SQL Server Management Studio, does this mean that I do not have permissions to edit a row?
Or the column is a computed column, or populated by the IDENTITY property, or ROWVERSION, or ...
Try and edit the data in this table, you will see that all three columns are read only:
USE tempdb;
GO
CREATE TABLE dbo.flub
(
i INT IDENTITY(1,1),
x AS (i + 1),
r ROWVERSION
);
INSERT dbo.flub DEFAULT VALUES;
If you share the definition of the table, we can at least tell you why if it's because of one of these reasons (we'd need more info to confirm if it's a column-level permissions issue).
Better suggestion: stop using "Open Table", "Edit Top 200 rows" or any other Excel-looking grid to modify data. Write proper DML using UPDATE statements - I promise you the error messages you get when you try to modify a value that you can't will be much more descriptive in almost every case. Examples from above:
UPDATE dbo.flub SET i = 5;
Msg 8102, Level 16, State 1, Line 1
Cannot update identity column 'i'.
UPDATE dbo.flub SET x = 5;
Msg 271, Level 16, State 1, Line 1
The column "x" cannot be modified because it is either a computed column or is the result of a UNION operator.
UPDATE dbo.flub SET r = 0x00;
Msg 272, Level 16, State 1, Line 1
Cannot update a timestamp column.
I talk about several bugs in these UIs here, and others have been reported since. This one, for example, was just fixed in the 2012 version...
If that column you are currently trying to edit is an IDENTITY column, it will display this message.
If you're only getting that message on one or more columns in the table, it sounds like that cell may be a computed column, which by definition does not support updates. Or, it may be an identity column which also does not support updates.
To see if it's a computed column: If you go to the table designer, you will notice no data type specified and instead (in the properties below) a Computed Column Specification. Or, in the DDL you will see an AS clause for the column.