Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SP with multiple tables and databases (insert & delete)
Message
De
28/02/2003 15:46:02
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Divers
Thread ID:
00758108
Message ID:
00759659
Vues:
25
This message has been marked as a message which has helped to the initial question of the thread.
>Why your suggestion is better? If UserID exists, we would need to modify, so we don't have to search?

Remember that INSERT, UPDATE, and DELETEs are two step commands. In the first step, SQL Server must find the applicable row or in the case of INSERT, it must find the location to put the new row. In performing this step, SQL Server uses a special lock - UPDATE. It is different than a SHARED lock. It affects concurrency more than a SHARED lock but less than EXCLUSIVE.

> UPDATE cart
> SET LastModTs = CURRENT_TIMESTAMP,
> @CartID = CartID
> FROM cart
> WHERE UserID = @tcUserID
>
>Incorrect syntax near UserID

You don't need to use this form of UPDATE. Try this

UPDATE cart
SET @cartID = cartID
,lastModified = CURRENT_TIMESTAMP
WHERE
userid = @tnUserID

Now, if lastModified is defined with the TIMESTAMP datatype, you don't have to explicitly update it. SQL Server will automatically do it.

>Also am I getting right, that you don't have to close IF statements, e.g. is this valid:
>Does END means an early exit point from the procedure?

BEGIN and END are use to group statements into blocks. TSQL is similar to C, C++, and C# in that conditional and looping statements only affect the statement that appear directly after it. Executing the following:

IF (1=0)
PRINT 'Hello'
PRINT 'World'

Will produce "World" since the first PRINT is skipped. But, wrapping BEGIN and END around the two prints will produce the output as you might expect:

IF (1=0)
BEGIN
PRINT 'Hello'
PRINT 'World'
END

Nothing will be displayed when the above snippet of code is executed.

-Mike
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform