SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Number of rows affected after update of MSSQL table using ROWCOUNT

We can use any UPDATE , insert or delete command to change the records of a MSSQL table. After successful execution of the query we can find out how many rows or records got change or affected by the command. This is a confirmation of change in records. For example if a member is updating his or her password then we can expect the number of records got updated is equal to 1 . So after checking this we can display a confirmation message to the member.

Let us try with one simple example where we have changed all the passwords to the default value test. This will affect all the records of the table as we have not used any WHERE clause or any other condition. After the update command we will use one more query to get the number of rows changed. Here is the sample code.

We have assumed all the connection and record objects are already created. Here is the example.

rs.open "update member set password ='test1' where password ='test'", conn
rs.open "select @@rowcount ", conn
dt=rs(0).value
Response.Write " Nos of records affected : " & dt

The above command will display total number of records changed because of the update command.


Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

Join Our Email List
Email:  
For Email Newsletters you can trust
MSSQL