Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How to write stored procedure to update the data in 10
tables

Answers were Sorted based on User's Feedback



How to write stored procedure to update the data in 10 tables..

Answer / mohit johri

Hey Vaishaili,
The query you wrote first of all does not require a dynamic
string to be constructed and then executed. The problem
with this is you are defeating the purpose of a stored
procedure.

A stored procedure is basically used to make the execution
faster as the code is kept in pre-complied mode.

Here what you are doing is you are giving an 'EXEC'
statement to execute the query which means that
the 'update'statements are not kept in pre-compiled mode.
They will first compile and then execute just like a normal
SQL statement.

Hence you should directly write the 'UPDATE' statements so
that it should only be executed and not compiled as they
are already kept in a pre-compiled mode.

The procedure can be best written as follows:

CREATE PROCEDURE <<procName>>
(
@param1 varchar(20),
@param2 varchar(20)
)
AS
UPDATE <<tableName1>> SET <<colName1>> = @param1 WHERE
<<colName2>> = @param2

UPDATE <<tableName1>> SET <<colName1>> = @param1 WHERE
<<colName2>> = @param2

..
..
..
..

UPDATE <<tableNameN>> SET <<colName1>> = @param1 WHERE
<<colName2>> = @param2



Exec(@sql)

Is This Answer Correct ?    15 Yes 3 No

How to write stored procedure to update the data in 10 tables..

Answer / mohit johri

Kindly ignore the last statement in my posted answer which
says 'Exec(@sql)' it was wrongly copied

Is This Answer Correct ?    9 Yes 2 No

How to write stored procedure to update the data in 10 tables..

Answer / vaishali

create procedure proc_name
{
@para1 varchar(20),
@para2 varchar(20),
}
AS
Declare @sql varchar(8000)
Set @sql="update table1 set col1='value' where
col2='"+@para1+"'\n"
Set @sql=@sql+ "update table2 set col1='value' where
col2='"+@para2+"'\n"

Exec(@sql)

Is This Answer Correct ?    10 Yes 11 No

How to write stored procedure to update the data in 10 tables..

Answer / jaipal

CREATE PROCEDURE <<procName>>
(
@param1 varchar(20),
@param2 varchar(20)
)
AS
UPDATE <<tableName1>> SET <<colName1>> = @param1 WHERE
<<colName2>> = @param2

UPDATE <<tableName1>> SET <<colName1>> = @param1 WHERE
<<colName2>> = @param2

..
..
..
..

UPDATE <<tableNameN>> SET <<colName1>> = @param1 WHERE
<<colName2>> = @param2

Is This Answer Correct ?    6 Yes 7 No

Post New Answer

More SQL Server Interview Questions

List all types of constraints in sql server?

0 Answers  


What does it mean to manipulate data?

0 Answers  


What are the 2 types of classifications of constraints in the sql server?

0 Answers  


How many triggers you can have on a table?

0 Answers  


How To Change Column Ordinal Position in SQL Server 2005 using Query i.e I Want To Add Column at Particular Ordinal Position in SQL Server 2005

2 Answers  


How much memory that we are using in Logshipping Concept?

0 Answers  


What are different types of table joins?

0 Answers  


What are different types of raid levels?

0 Answers  


You have several tables, and they are joined together for querying. The tables contain both clustered indexes and non clustered indexes to optimize performance, how should you distribute the tables and their indexes onto different file groups?

0 Answers  


What happens to a trigger with multiple affected rows?

0 Answers  


What is an Index?

3 Answers   Yardi Software,


Do you know what guidelines should be followed to help minimize deadlocks?

0 Answers  


Categories