开发者

How can I extract sprocs/tables/functions from a specific schema?

I need to extract all the tables, stored procs and functions from an SQL Server 08 db that are under a particular schema. I could filter the displayed items in Management Studio and then do Script As -> Drop/Create for each of them, but I would really like to avoid this as there are quite a few items in the schema.开发者_开发技巧

Is there a way to do this?

Edit:

I've had a look at this question (possible duplicate I just found). I'd rather not use an external tool as suggested, since this is at work and I'd need to get approval to use one. Nor do I want one big Create Database script - I need separate scripts for each table/sproc/function.


select 
   object_name(obj.object_id), 
   sch.name, 
   co.definition 
from 
   sys.objects obj 
   join sys.schemas sch on sch.schema_id = obj.schema_id
   left join sys.sql_modules co on co.object_id = obj.object_id
where 
   sch.name = 'DBO' --here goes your schema name

--The syscoments table was used back in sql 2000 and you should not use it anymore - but when so it is the sys.syscomments table


Visual Studio 2010 Premium includes database project tooling support that allows you to perform database schema comparisons between databases (where you can filter to only a specified database schema) and extract all the objects (and configuration) in a live database to a VS2010 database project, creating a script per object.

See Working with Database Projects.


Something based on

SELECT [text] FROM [syscomments]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜