Sample Header Ad - 728x90

SQL Server: Use Implicit or Explicit Cursor?

-2 votes
1 answer
205 views
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?
Asked by david (115 rep)
Dec 6, 2019, 03:39 AM
Last activity: Dec 6, 2019, 01:13 PM