sql server ²é¿´»òɾ³ýËùÓÐÊÓͼ¡¢´æ´¢¹ý³Ì
1¡¢ÁгöËùÓÐÊÓͼ
SELECT Name,ÊÓͼÃû×Ö Definition ÊÓͼÄÚÈÝ FROM sys.sql_modules AS m INNER JOIN sys.all_objects AS o ON m.object_id = o.object_id WHERE o.[type] = ¡¯v¡¯
2¡¢É¾³ýÊÓͼ
USE Êý¾Ý¿âÃû declare mycur cursor local for select [name] from dbo.sysobjects where xtype=¡¯V¡¯  ÉùÃ÷Óαê declare @name varchar(100)   OPEN mycur    ´ò¿ªÓÎ±ê   FETCH NEXT from mycur into @name   WHILE @@FETCH_STATUS = 0    BEGIN exec(¡¯drop VIEW ¡¯ + @name) FETCH NEXT from mycur into @name   ÖðÌõ¶ÁÈ¡ END   CLOSE mycur   ¹Ø±ÕÓαê
3¡¢ÀûÓÃSqlÓï¾ä²éѯÊý¾ÝÖеÄËùÓд洢¹ý³Ì
a¡¢ÀûÓÃsysobjectsϵͳ±í£¬
ÔÚÕâ¸ö±íÖУ¬ÔÚÊý¾Ý¿âÖд´½¨µÄÿ¸ö¶ÔÏó£¨ÀýÈçÔ¼Êø¡¢Ä¬ÈÏÖµ¡¢ÈÕÖ¾¡¢¹æÔòÒÔ¼°´æ´¢¹ý³Ì£©¶¼ÓжÔÓ¦Ò»ÐУ¬ÎÒÃÇÔڸñíÖÐɸѡ³öxtypeµÈÓÚPµÄËùÓмǼ£¬¾ÍΪÊý¾Ý¿âÖеĴ洢¹ý³ÌÁË¡£ ʾÀýÓï¾äÈçÏ£º
select * from sysobjects where xtype=''''''''P''''''''
×¢Ò⣺ÔÚSQL SERVER2005ÖУ¬³öÏÖÁËsys.objectsĿ¼ÊÓͼÀ´´úÌæsysobjectsϵͳ±í£¬ÎÒÃÇÔÚSQL SERVER2005¼°ÒÔºóµÄ°æ±¾ÖУ¬¿ÉÒÔʹÓÃsysobjectsϵͳ±íÓësys.objectsĿ¼ÊÓͼµÄÈÎÒâ¶ÔÏóÀ´²éѯËùÓд洢¹ý³Ì¡£
µ«ÔÚsys.objectsÖÐ,xtypeÁÐÒѾ±»typeÁдúÌ棬¼´ÔÚSQL SERVER2005¼°ÒÔºóµÄ°æÖпÉÓÃÒÔÏ´úÂëÀ´²éѯÊý¾Ý¿âÖÐËùÓд洢¹ý³Ì£º select * from sys.objects where type=''''''''P''''''''
Á½¸öµÄ²î±ðÊÇX£¬xtype»»³Étype¡£
b£¬ÀûÓÃsys.proceduresĿ¼ÊÓͼ
sys.proceduresĿ¼ÊÓͼ£¬Ã¿¸ö´æ´¢¹ý³Ì¶¼»áÔÚ·µ»Ø½á¹û¼¯ÖÐÕ¼Ò»ÐÐ. ʾÀýÓï¾äÈçÏ£º select * from sys.procedures
4¡¢É¾³ý´æ´¢¹ý³Ì
USE Êý¾Ý¿âÃû declare mycur cursor local for select [name] from dbo.sysobjects where xtype=¡¯P¡¯ declare @name varchar(100)   OPEN mycur   FETCH NEXT from mycur into @name   WHILE @@FETCH_STATUS = 0    BEGIN exec(¡¯drop PROCEDURE ¡¯ + @name) FETCH NEXT from mycur into @name END   CLOSE mycur
 
5£¬
£¨ Ò»£©ÀûÓÃSqlÓï¾ä²éѯÊý¾Ý¿âÖеÄËùÓбí
1£¬ÀûÓÃsysobjectsϵͳ±í ÔÚÕâ¸ö±íÖУ¬ÔÚÊý¾Ý¿âÖд´½¨µÄÿ¸ö¶ÔÏó£¨ÀýÈçÔ¼Êø¡¢Ä¬ÈÏÖµ¡¢ÈÕÖ¾¡¢¹æÔòÒÔ¼°´æ´¢¹ý³Ì£©¶¼ÓжÔÓ¦Ò»ÐУ¬ÎÒÃÇÔڸñíÖÐɸѡ³öxtypeµÈÓÚUµÄËùÓмǼ£¬¾ÍΪÊý¾Ý¿âÖеıíÁË¡£ ʾÀýÓï¾äÈçÏ£º£º
select * from sysobjects where xtype=''''''''U''''''''
×¢Ò⣺ÔÚSQL SERVER2005ÖУ¬³öÏÖÁËsys.objectsĿ¼ÊÓͼÀ´´úÌæsysobjectsϵͳ±í£¬ÎÒÃÇÔÚSQL SERVER2005¼°ÒÔºóµÄ°æ±¾ÖУ¬¿ÉÒÔʹÓÃsysobjectsϵͳ±íÓësys.objectsĿ¼ÊÓͼµÄÈÎÒâ¶ÔÏóÀ´²éѯËùÓÐ±í¡£
2,ÀûÓÃsys.tablesĿ¼ÊÓͼ sys.tablesĿ¼ÊÓͼ£¬ÎªÃ¿¸ö±í¶ÔÏó·µ»ØÒ»ÐÐ. ʾÀýÓï¾äÈçÏ£º select * from sys.tables
×¢Ò⣺sys.tablesĿ¼ÊÓͼҲֻÓÐÔÚSQL SERVER2005¼°ÒÔÉϵİ汾ÖвÅÄÜʹÓá£
3,ÀûÓô洢¹ý³Ìsp_tables sp_tables´æ´¢¹ý³Ì,¿É·µ»Ø¿ÉÔÚµ±Ç°»·¾³ÖвéѯµÄ¶ÔÏóÁÐ±í¡£Õâ´ú±í¿ÉÔÚFROM×Ó¾äÖгöÏÖµÄÈκζÔÏó¡£ ÎÒÃÇ¿ÉÒÔÖ´ÐÐÈçÏÂÓï¾ä£º exec sp_tables
ÔÚ½á¹û¼¯ÖÐɸѡ³öËùÓÐTABLE_TYPEµÈÓÚTABLEµÄ¼Ç¼¾ÍÊDZíÐÅÏ¢ÁË¡£
£¨¶þ£©ÀûÓÃSqlÓï¾ä²éѯÊý¾ÝÖеÄËùÓд洢¹ý³Ì(Öظ´3)
1£¬ÀûÓÃsysobjectsϵͳ±í ÔÚÕâ¸ö±íÖУ¬ÔÚÊý¾Ý¿âÖд´½¨µÄÿ¸ö¶ÔÏó£¨ÀýÈçÔ¼Êø¡¢Ä¬ÈÏÖµ¡¢ÈÕÖ¾¡¢¹æÔòÒÔ¼°´æ´¢¹ý³Ì£©¶¼ÓжÔÓ¦Ò»ÐУ¬ÎÒÃÇÔڸñíÖÐɸѡ³öxtypeµÈÓÚPµÄËùÓмǼ£¬¾ÍΪÊý¾Ý¿âÖеĴ洢¹ý³ÌÁË¡£ ʾÀýÓï¾äÈçÏ£º
select * from sysobjects where xtype=''''''''P''''''''
×¢Ò⣺ÔÚSQL SERVER2005ÖУ¬³öÏÖÁËsys.objectsĿ¼ÊÓͼÀ´´úÌæsysobjectsϵͳ±í£¬ÎÒÃÇÔÚSQL SERVER2005¼°ÒÔºóµÄ°æ±¾ÖУ¬¿ÉÒÔʹÓÃsysobjectsϵͳ±íÓësys.objectsĿ¼ÊÓͼµÄÈÎÒâ¶ÔÏóÀ´²éѯËùÓд洢¹ý³Ì¡£
µ«ÔÚsys.objectsÖÐ,xtypeÁÐÒѾ±»typeÁдúÌ棬Ҳ¾ÍÊÇ˵£¬ÔÚSQL SERVER2005¼°ÒÔºóµÄ°æÖпÉÒÔʹÓÃÒÔÏ´úÂëÀ´²éѯÊý¾Ý¿âÖÐËùÓд洢¹ý³Ì¡£ select * from sys.objects where type=''''''''P''''''''
2,ÀûÓÃsys.proceduresĿ¼ÊÓͼ sys.proceduresĿ¼ÊÓͼ£¬Ã¿¸ö´æ´¢¹ý³Ì¶¼»áÔÚ·µ»Ø½á¹û¼¯ÖÐÕ¼Ò»ÐÐ. ʾÀýÓï¾äÈçÏ£º select * from sys.procedures
×¢Ò⣺sys.proceduresĿ¼ÊÓͼҲֻÓÐÔÚSQL SERVER2005¼°ÒÔÉϵİ汾ÖвÅÄÜʹÓᣠ|