Hi,
When I run my script I am getting the below error msg. Please help me to fix this error. Thanks in advance.
Msg 11736, Level 15, State 0:
line 1: You cannot specify this command in an 'execute immediate' context.
Here is my script:
declare tbl_loop cursor for
select distinct name from sysobjects where type='U'
go
declare @sql varchar(250)
declare @tbl_name char(25)
open tbl_loop
fetch tbl_loop into @tbl_name
while (@@sqlstatus = 0 )
begin
select @sql = ' dbcc checktable('+@tbl_name+')'
print @sql
execute (@sql)
fetch tbl_loop into @tbl_name
end
close tbl_loop
deallocate cursor tbl_loop
go
END