把SQL SERVER里表里的数据导出成为insert into 脚本
<pre class="sql" name="code">把SQL SERVER里表里的数据导出成为insert into 脚本
终于找到这个过程了:
Create PROCEDURE dbo.UspOutputData
@tablename sysname
AS
declare @column varchar(1000)
declare @columndata varchar(1000)
declare @sql varchar(4000)
declare @xtype tinyint
declare @name sysname
declare @objectId int
declare @objectname sysname
declare @ident int
set nocount on
set @objectId=object_id(@tablename)
if @objectId is null -- 判斷對象是否存在
begin
print 'The object not exists'
return
end
set @objectname=object_name(@objectId)
if @objectname is null or charindex(@objectname,@tablename)=0 --此判断不严密
begin
print 'object not in current database'
return
end
if OBJECTPROPERTY(@objectId,'IsTable') <> 1 -- 判斷對象是否是table
begin
print 'The object is not table'
return
end
select @ident=status&0x80 from syscolumns where id=@objectid and status&0x80=0x80
if @ident is not null
print 'SET IDENTITY_Insert '+@TableName+' ON'
declare syscolumns_cursor cursor
for select c.name,c.xtype from syscolumns c
where c.id=@objectid
order by c.colid
open syscolumns_cursor&n
相关新闻>>
- 发表评论
-
- 最新评论 更多>>