I have a Table where 'ID' is an auto number. There are a few records present with the same OrderID. I want to add another record to this table with the same OrderID. I tried the following but it does not do anything.
IF NOT EXISTS (SELECT 1 FROM Orders WHERE OrderID='2344567')
Insert into orders (Product_Id, Quantity, Description, Price)
Values ('" & Product_Id & "', '" & Quantity & "', '" & Description & "', '" & Price & "')
Can you help please?
CodePudding user response:
In SQL Server you can use
SET IDENTITY INSERT - Allows explicit values to be inserted into the identity column of a table.
In this case you turn on and off the possibility to insert into an identity column which is defined as a sequence
The following link will help to resolve the task: SQL Server set identity
CodePudding user response:
Use SQL Server Profiler
to see what query will be run on your Db. I think you may have some problems on setting parameters on your application, then you can see what really happening in your Db.
-- If (OrderID='2344567') record is EXISTS, your INSERT statement doesn't work