MS SQL Server da basit bir cursor örneği

Aşağıdaki örnek kod ile STE_EMAILS tablosundaki emails kolonunu PRINT ediyoruz.

DECLARE @email NVARCHAR(255)
DECLARE MyCursor CURSOR
    FOR SELECT  email
        FROM    STE_EMAILS
OPEN MyCursor
FETCH NEXT FROM MyCursor INTO @email
WHILE @@FETCH_STATUS = 0
    BEGIN
        
        PRINT '%' + @email + '%'
        FETCH NEXT FROM MyCursor INTO @email
    END
CLOSE MyCursor
DEALLOCATE MyCursor

Comments

comments

2 Comments

  1. Hi Alejandro,

    “Truncate Table” is faster but you can not use this command when your table includes Foreign Keys.

    Another fact is, if you want to delete spesific records on a table, you can only use delete command.

Leave a Comment.