日期:2014-05-18  浏览次数:20481 次

新手上路:sqlserver2000中如何用脚本导出全部表及存贮过程等,但是不要数据,然后可以在另一个数据库中执行脚本进行导入?
新手上路:sqlserver2000中如何用脚本导出全部表及存贮过程等,但是不要数据,然后可以在另一个数据库中执行脚本进行导入?
---------------------
就是动网论坛的数据库一样,执行一个sql文件就创建好了,通过这个sql文件便可以创建全部表,全部存贮过程,函数等。也就是说建立一个没有数据的空库,我就是不知如何实现的。
比如一个数据库,我如何生成sql脚本呢?
总不能一句一句的写创建表及存贮过程语句吧。如何操作可以快速生成。谢谢各位老师。


------解决方案--------------------
企業管理器---工具---generate SQL script /show ALL ,對需要的table/proc等勾上
------解决方案--------------------
生成存储过程
select id=identity(int),text=cast(
N 'if exists(select * from sysobjects where id=object_id(N '
+quotename(name)+N ')
drop proc '+quotename(name)+N '
GO ' as nvarchar(4000))
into ## from sysobjects
where xtype= 'p '
and status> =0
insert ##(text) select text
from(
select c.id,c.number,s1=0,c.text
from sysobjects o,syscomments c
where o.id=c.id
and o.xtype= 'p '
and o.status> =0
union all
select c.id,c.number,s1=1, 'go '
from sysobjects o,syscomments c
where o.id=c.id
and o.xtype= 'p '
and o.status> =0
)a order by id,number,s1
exec master.dbo.xp_cmdshell 'bcp "select text from ## order by id " queryout "c:\a.sql " /T /c ',no_out_put
drop table ##