DECLARE tables_cursor CURSOR FOR SELECT name FROM sysobjects WHERE type = 'U' OPEN tables_cursor DECLARE @tablename sysname FETCH NEXT FROM tables_cursor INTO @tablename WHILE (@@FETCH_STATUS <> -1) BEGIN /* A @@FETCH_STATUS of -2 means that the row has been deleted. There is no need to test for this because this loop drops all user-defined tables. */. EXEC ('DROP TABLE ' + @tablename) FETCH NEXT FROM tables_cursor INTO @tablename END PRINT 'All user-defined tables have been dropped from the database.' DEALLOCATE tables_cursor给你个例子
declare @a varchar(4000)set @a='select * from ta'exec(@a)
------------------------------------------------------
2009-08-11 08:57:04.903
FOR
SELECT name FROM sysobjects WHERE type = 'U'
OPEN tables_cursor
DECLARE @tablename sysname
FETCH NEXT FROM tables_cursor INTO @tablename
WHILE (@@FETCH_STATUS <> -1)
BEGIN
/* A @@FETCH_STATUS of -2 means that the row has been deleted.
There is no need to test for this because this loop drops all
user-defined tables. */.
EXEC ('DROP TABLE ' + @tablename)
FETCH NEXT FROM tables_cursor INTO @tablename
END
PRINT 'All user-defined tables have been dropped from the database.'
DEALLOCATE tables_cursor给你个例子
比如说:
....
Exec ('Select Getdate()')与
....
Select GetDate()
以上两种得到的结果不都一样吗?没有Exec来执行Select GetDate(),它照样会执行呀?
Exec关键字来执行徐徐串到底有什么意义呢?