# Sql-server – SQL Server: Use Implicit or Explicit Cursor?

cursorsexecsql server

SELECT Table_Name
FROM INFORMATION_SCHEMA.TABLES
WHILE (1=1)
BEGIN
EXEC 'drop view ' + Table_Name
END


or

DECLARE my_cursor CURSOR FOR
SELECT Table_Name
FROM INFORMATION_SCHEMA.TABLES

OPEN my_cursor
WHILE 1 = 1
BEGIN
FETCH my_cursor INTO @vname
IF @@fetch_status != 0 BREAK
EXEC('drop view ' + @vname)
END
CLOSE my_cursor;


The examples more or less describe what I'm doing, but that's not the question. The question is: When should I be trying to use an explicitly defined cursor, as in the second example, and what are the conditions where the first example would work?