Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Generate Script

Author  Topic 

khalik
Constraint Violating Yak Guru

443 Posts

Posted - 2009-02-13 : 10:24:46

Hi

I need to write a SP which can generate script for a given table to a txt file. i am using SQL 2005.

Regards
Khalik

========================================
Project Manager who loves to code.
===============
Ask to your self before u ask someone

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-13 : 11:08:39
make use INFORMATION_SCHEMA.COLUMNS and INFORMATION_SCHEMA.TABLES view for this
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-02-13 : 11:11:47
>>for a given table
Do you mean the structure or the content?

Be One with the Optimizer
TG
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-13 : 11:27:46
http://www.databasejournal.com/features/mssql/article.php/3401081/Automating-Generate-SQL-Script.htm
Go to Top of Page

khalik
Constraint Violating Yak Guru

443 Posts

Posted - 2009-02-13 : 11:43:28
thanks Visakh. me to found the same... i was testing it

========================================
Project Manager who loves to code.
===============
Ask to your self before u ask someone
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-14 : 00:56:06
welcome
Go to Top of Page

khalik
Constraint Violating Yak Guru

443 Posts

Posted - 2009-02-14 : 06:24:53
I am trying to execuete the sp which generates the script and get the output to a .txt file.
here goes the script


set QUOTED_IDENTIFIER OFF
declare @sql varchar(8000)
select @sql = 'bcp "exec sp_ScriptTable ''user@abc.com'',''CustomerTable'' " queryout E:\SyncData\DBScript.txt -w -T -x '
print @sql
exec xp_cmdshell @sql

i get a error
SQLState = 42000, NativeError = 2812
Error = [Microsoft][SQL Native Client][SQL Server]Could not find stored procedure 'sp_ScriptTable'.
NULL

what is the issue i have the sp when i execute the sp alone works fine..
exec sp_ScriptTable 'user@abc.com','CustomerTable'


========================================
Project Manager who loves to code.
===============
Ask to your self before u ask someone
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-14 : 10:50:21
does the account running bcp has access to execute the stored procedure ?
Go to Top of Page
   

- Advertisement -