I have a tables Cars and CarDescriptions
cars: IDCar(int, PK, autoincrement) carsDesciptions(IDDescription, Header(nvarchar),Content(nvarchar),idCar(int,FK)
In application I am adding cars and editing existing ones.
My problems:
1.How to save changed Car with descriptions in database ??
I have ID of Car, and I have ID's of Descriptions
Class CarDescirption doesn't have any pool like IsChanged, so
I don't wanna do something like :
the record must be updated if is in table, and inserted if doesn't exist in table
The UPDATE statement is used to modify the existing records in a table.
The UPDATE command in SQL is used to modify or change the existing records in a table. If we want to update a particular value, we use the WHERE clause along with the UPDATE clause. If you do not use the WHERE clause, all the rows will be affected.
Is update or INSERT faster? Inserts will just about always be quicker, especially if they are either in order or if the underlying table doesn't have a clustered index.
It has the best perfomacne:
UPDATE Table1 SET (...) WHERE Column1='SomeValue'
IF @@ROWCOUNT=0
INSERT INTO Table1 VALUES (...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With