We need to execute all the ways and need to check the e performance of the different update statements. Scenario 1 : Traditional way to update individual records and commit after for loop.
If you can check the first example where we are trying to update all records using for loop and then use commit statement. It is taking around 2 mins and 42 seconds to complete the procedure and to update the records. Scenario 2 : Traditional way to update individual records and commit inside for loop. If we can check the process and timing to execute the records or update the records in database it is approximately 3 mins and 58 seconds.
Here loop will run commit statement after every record update so the time to update the record is higher than single commit record. The bulk collect method is faster method than traditional methods. We require to create a type variable where we can fetch all customer data and we need to use bulk collect statement in forall clause so that the records in the forall clause or specified table will be updated correctly.
If we can see the Elapsed time it is around 54 seconds which is more faster than other methods. The direct update will take 58 seconds to update all the records. The final output of the above statement we illustrated by using the below screenshot is as follows. By using this command, we can insert the different records into the specified table that we want.
When we need to insert the records into the table, we must require the table name, column name, and values for a column. In the above syntax, we use to insert into a statement to insert the records into the specified table, here insert into keyword is mandatory, specified table name means actual table name, and inside the bracket, we need to provide the column names and finally, we need to provide the different values with respect the column name as per our requirement as shown in the above syntax.
By using the above statement, we inserted five records as shown in the below screenshot as follows. It is useful to update any value from the specified table as per our requirements. It must require the table name, column name, and new value for that column.
In the above syntax, we use an update query to update the records from the specified table; here, the specified table name means actual name, and after that, we need to use the set keyword as shown. One more thing is that here we update only a single column. Syntax of delete query is very simple as shown in above syntax, here we specified table name means actual table name that we already created, and inside the where clause we need to specify the condition to delete the particular records from the specified table.
In the first syntax, we can fetch all records from the specified table. In the above syntax, we wrote the exception section separately, as shown in the above syntax.
When an expression is not executed, and it shows the error message that we wrote in the exception section as shown. In the above syntax, we use a select statement with specified table names with the specified arithmetic operators. Please check below result screen. We have updated state code column using CASE expression. I hope that you will get an idea about how to use CASE expression. I hope you will enjoy these tips while playing with SQL Server. I would like to have feedback from my blog readers.
Your valuable feedback, questions, or comments about this article are always welcome.
0コメント