Find the exact line number of error in sql script - sql

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.

Related

Trying insert data to database by SQL

I want to insert data on table dbo.batch but but I have an error message when i tried to insert the data
error message
Msg 110, Level 15, State 1, Line 3
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.
You have 10 columns in your statement but 11 values to enter. Therefore the error message
You have 10 columns and you are inserting 11 values check for the valid columns values you need and remove other.
I guess the last 2nd column value is the one you should remove

SQL Server invalid object name insert

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

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.

I want to insert multiple rows in a table using sql server 2005

I am wanting to insert rows into a four column table. I have inserted rows in the first two columns. However, when I try adding to the third and fourth column I receive the following error,
"Msg 8152, Level 16, State 4, Line 1 String or binary data would be
truncated. The statement has been terminated"
I am using the following query:
USE DB
GO
INSERT INTO dbo.Table (Column1, Column2, Column3,Column4)
VALUES ('data','data','data','data')
Check if one of your strings exceeds the length of the datafield.
For example, if you are inserting a string of length 50 into a varchar(20), you would recieve this error.
You are receiving that error because your columns are not capable of storing a value that large. You need to either shorten the length of your strings being inserted or increased the length on the column structure.

I am Trying to insert this data into SQL

I am trying to create the correct values for the tables I created. This is the code:
INSERT DEPARTMENTS
(Department_Id,Department_Name,Manager_Id,Location_Id)
VALUES
('D0001,D0002,D0003','Think Tank,Creators,Marketers',NULL,'L0001,L0002,L0003')
GO
INSERT EMPLOYEES
(Employee_Id,First_Name,Last_Name,Email,PhoneNumber,Hire_Date,Manager_ID,Department_Id)
VALUES
('E0001,E0002,E0003,E0004,E0005,E0006,E0007','Joe,John,Sue,Tina,Ike,Big,Speedy','Blow,Doe,Happy,Turner,Turner,Bird,Gonzales',NULL,NULL,2010/06/25,2010/06/25,2010/06/25,2010/06/25,2010/06/25,2010/06/25,2010/06/25,NULL,NULL)
GO
INSERT LOCATIONS
(Location_ID,Postal_Code,City,State_Province,Country)
VALUES
('L0001,L0002','19121,08618','Philadelphia,Trenton','PA,NJ','USA,USA')
This is the error message:
Msg 8152, Level 16, State 14, Line 2
String or binary data would be truncated.
The statement has been terminated.
Msg 110, Level 15, State 1, Line 1
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.
Msg 8152, Level 16, State 14, Line 1
String or binary data would be truncated.
The statement has been terminated.
I would like to know what I am doing wrong and the correct code. Can anyone help me out? Thanks
INSERT EMPLOYEES has 8 columns and WAY more than 8 values in the VALUES part of the statement.
I don't think you understand how SQL works.
As an hint, this:
INSERT LOCATIONS
(Location_ID,Postal_Code,City,State_Province,Country)
VALUES
('L0001,L0002','19121,08618','Philadelphia,Trenton','PA,NJ','USA,USA')
should look like this:
INSERT LOCATIONS
(Location_ID,Postal_Code,City,State_Province,Country)
VALUES
('L0001','19121','Philadelphia','PA','USA');
INSERT LOCATIONS
(Location_ID,Postal_Code,City,State_Province,Country)
VALUES
('L0002','08618','Trenton','NJ','USA');
You need one insert statement for every row you are inserting.
The DEPARTMENTS and EMPLOYEES is wrong in this same way as well.
You can do multiple inserts like this though,
INSERT INTO LOCATIONS
(Location_ID,Postal_Code,City,State_Province,Country)
VALUES
('L0001','19121','Philadelphia','PA','USA'),
('L0002','08618','Trenton','NJ','USA');