There is a table table1 in the A server, want to guide the contents of the table to the B server, these two databases are not connected, what should I do? Guide an external file and exported again with the import. . . . This is too stupid, if the other server is on the Internet, can only perform the service? If you are dizzy, use this store process to help you. Alter Proc sp_gettabledata @objname nvarchar (776) as - set @ objName = 's_coderule'
/ * DECLARE @no varchar (35), @yes varchar (35) master.dbo.spt_values where type = 'B' and number = 1 select @none = name from master.dbo.spt_values where type = 'B' and number = 2 * / declare @numtypes nvarchar (80) select @numtypes = N 'tinyint, smallint, decimal, int, real, money, float, numeric, smallmoney, varbinary, bit' declare @chartypes nvarchar (80) select @chartypes = N'char, varchar, text, nchar, ntext, nvarchar 'declare @ datetypes nvarchar (80) select @datetypes = N'datetimesmalldatetime 'declare @Limitlength Int, @ Limitlength1 Int declare @objid bigint --declare @sysobj_type char (2) select @objid = id--, @sysobj_type = xtype from sysobjects where id = Object_ID (@objname) set @limitLength = 0 set @ limited dength1 = 0Declare @name varchar (30), @ type var, @fieldsql varchar (5000), @ SQL varchar (8000), @ Ident Smallint set @ SQL = '' set @f Ieldsql = ''
Declare Cur Cursorfor
select 'Column_name' = name, 'Type' = type_name (xusertype), 'Length' = convert (int, length), 'Ident' = colstat from syscolumns where id = @objid and number = 0 order by colidopen Cur fetch next from Cur Into @ name, @ type, @ @@ fetch_status = 0begin if @ Ident = 0BEGIN if @limitLength> 200 Begin set @SQL = @SQL ',' set @limitLength = 0 END
IF @ limited @fieldsql = @fieldsql char (39) ',' char (39) set @ limited set = 0 end set @fieldsql = @fieldsql ltrim (RTRIM (@name)) ', 'If Charindex (@Type, @numtypes)> 0 - (' convert (char (6), @ length) ') set @ SQL = @ SQL ' Case When ' @ Name ' Is Null Ten '' NULL 'ELSE RTRIM (Convert (CHAR,' @Name ')) end' else if charindex (@Type, @Chartypes)> 0 set @ SQL = @ SQL ' Case When' @ Name 'is null dam '' Null 'Else Char (39) RTRIM (' @name ') Char (39) End' Else if Charindex (@Type, @datetypes)> 0 set @ SQL = @ SQL ' Case When ' @ Name ' Is Null Then '' Null '' Else Char (39) RTRIM (Convert (CHAR (19), ' @ Name ', 120) CHAR (39) End 'Set @ SQL = @ SQL ' ' Char (39) ',' Char (39) Set @LimitLength = @LimitLength @Length Set @ limitedLENGTH1 = @ LimitLength1 Len (@Name) end
Fetch next from cur @ Name, @ type, @ Length, @ IDENTENDCLOSE CURDEALLOCATE CUR
- Print @sqlif right (@fieldsql, 1) = char (39) set @fieldsql = substring (@fieldsql, 1, len (@fieldsql) -5) else set @fieldsql = Substring (@fieldsql, 1, len @Fieldsql) -1)
IF Right (@SQL, 1) = ',' set @SQL = Substring (@SQL, 1, LEN (@SQL) -5) Else Set @ SQL = Substring (@ SQL, 1, LEN (@SQL) -4 - Print (@fieldsql)
Set @fieldsql = 'SELECT' CHAR (39) 'INSERT INTO' @ ObjName '(' @fieldsql ')' - set @fieldsql = 'SELECT' CHAR (39) 'INSERT INTO' @ ObjName '(' @fieldsql ')' print @fieldsql
Set @SQL = 'VALUES (' char (39) @ SQL ' ' CHAR (39) ')' CHAR (39) 'from' @ ObjName
Print @SQL
Set @SQL = @fieldsql @SQLEXEC (@SQL)
--EXEC @fieldsql @ SQL - SELECT RTRIM (Isnull (Convert (CONVERT (CONVERT (CONVERT (CONVERT (CHAR (8), DID), '')) from
Goset quoted_identifier off goset ANSI_NULLS ON Go
Look at the results, there are some bugs, enough to use it, lazy to change.