Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

sp_helptext for Tables

 
   Database Help (Home) -> Programming RSS
Next:  Cannot insert explicit value for identity column ..  
Author Message
Hemant

External


Since: Oct 20, 2009
Posts: 4



(Msg. 1) Posted: Thu Mar 18, 2010 9:25 am
Post subject: sp_helptext for Tables
Archived from groups: microsoft>public>sqlserver>programming (more info?)

Hi,

I am working on sql server 2000. I want to generate script of a table in a
query.
Is there any way like sp_helptext for views to create Script for tables?

Thanks,
Hemant

 >> Stay informed about: sp_helptext for Tables 
Back to top
Login to vote
Jay Konigsberg

External


Since: Mar 09, 2010
Posts: 5



(Msg. 2) Posted: Thu Mar 18, 2010 9:25 am
Post subject: Re: sp_helptext for Tables [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Are you saying you want to create the DDL for a table, from a T-SQL
statement? If so, you can't do it from anything less than a procedure. I
wrote such a procedure for 2000 and got it about 98% working, it wasn't that
hard, but it took a while.

Shall I dig it out for you?

--
Jay Konigsberg
SQL Server DBA in Sacramento, CA
http://www.linkedin.com/in/jaykonigsberg

Live in Sacramento, CA?
Join the Sacramento SQL Server User Group on LinkedIn
http://www.linkedin.com/groups?home=&gid=2825448&trk=anet_ug_hm&goback=%2Emyg



"Hemant" wrote in message

> Hi,
>
> I am working on sql server 2000. I want to generate script of a table in a
> query.
> Is there any way like sp_helptext for views to create Script for tables?
>
> Thanks,
> Hemant
>

 >> Stay informed about: sp_helptext for Tables 
Back to top
Login to vote
Hemant

External


Since: Oct 20, 2009
Posts: 4



(Msg. 3) Posted: Thu Mar 18, 2010 9:25 am
Post subject: Re: sp_helptext for Tables [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi Jay,

Thank you.
Its very helpful for me if you can do it.
Thanks once again.

Hemant

"Jay Konigsberg" wrote in message

> Are you saying you want to create the DDL for a table, from a T-SQL
> statement? If so, you can't do it from anything less than a procedure. I
> wrote such a procedure for 2000 and got it about 98% working, it wasn't
> that hard, but it took a while.
>
> Shall I dig it out for you?
>
> --
> Jay Konigsberg
> SQL Server DBA in Sacramento, CA
> http://www.linkedin.com/in/jaykonigsberg
>
> Live in Sacramento, CA?
> Join the Sacramento SQL Server User Group on LinkedIn
> http://www.linkedin.com/groups?home=&gid=2825448&trk=anet_ug_hm&goback=%2Emyg
>
>
>
> "Hemant" wrote in message
>
>> Hi,
>>
>> I am working on sql server 2000. I want to generate script of a table in
>> a query.
>> Is there any way like sp_helptext for views to create Script for tables?
>>
>> Thanks,
>> Hemant
>>
>
>
 >> Stay informed about: sp_helptext for Tables 
Back to top
Login to vote
Uri Dimant

External


Since: Aug 24, 2003
Posts: 1744



(Msg. 4) Posted: Thu Mar 18, 2010 9:25 am
Post subject: Re: sp_helptext for Tables [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hemant
VB project, you need to use SQL DMO object library


Sub ScriptDB(strLogin As String, strPwd As String, _
strDataBase As String, StrFilePath As String)

'==========================================================================
' Parameters
' -------------------------------------------------------------------------
' strLogin: The Login Name of the account you use to connect to the server
' strPwd: The Password for the account you use to connect to the server
' strDataBase: The name of the database you want to create script for
' StrFilePath: The path and filename to store the SQL file
'==========================================================================

Dim sql As Object
Dim db As Object
Dim objTrigger As Object
Dim intOptions As Long
Dim genObj

Set sql = CreateObject("SQLDMO.SQLServer")
Set db = CreateObject("SQLDMO.Database")
Set objTrigger = CreateObject("SQLDMO.Trigger")

Const sDrops As Integer = 1
Const sIncludeHeaders As Long = 131072
Const sDefault As Integer = 4
Const sAppendToFile As Integer = 256
Const sBindings As Integer = 128
Const SQLDMOScript2_NoCollation As Long = 8388608

' Set scripting options. Because you need to specify multiple behaviors
' for the ScriptType argument, you use "Or" to combine these.
intOptions = sDrops Or sIncludeHeaders Or _
sDefault Or sAppendToFile Or sBindings Or SQLDMOScript2_NoCollation

' Connect to local server
sql.Connect "(local)", strLogin, strPwd
Set db = sql.Databases(strDataBase, "dbo")


' Script Tables and Triggers, ignoring system
' tables and system generated triggers
For Each genObj In db.Tables
If genObj.SystemObject = False Then
genObj.Script intOptions, StrFilePath,,SQLDMOScript2_NoCollation
For Each objTrigger In genObj.Triggers
If objTrigger.SystemObject = False Then
objTrigger.Script intOptions, StrFilePath
End If
Next
End If
Next


MsgBox "Finished generating SQL scripts."

End Sub

Save the module as MyModule.

To call the procedure, open the Immediate window, type the following line,
and then press ENTER:Call
ScriptDB("UserName","Password","DatabaseName","C:\MyResults.SQL")
Call ScriptDB("UserName","Password","DatabaseName","C:\MyResults.SQL")





"Hemant" wrote in message

> Hi Jay,
>
> Thank you.
> Its very helpful for me if you can do it.
> Thanks once again.
>
> Hemant
>
> "Jay Konigsberg" wrote in message
>
>> Are you saying you want to create the DDL for a table, from a T-SQL
>> statement? If so, you can't do it from anything less than a procedure. I
>> wrote such a procedure for 2000 and got it about 98% working, it wasn't
>> that hard, but it took a while.
>>
>> Shall I dig it out for you?
>>
>> --
>> Jay Konigsberg
>> SQL Server DBA in Sacramento, CA
>> http://www.linkedin.com/in/jaykonigsberg
>>
>> Live in Sacramento, CA?
>> Join the Sacramento SQL Server User Group on LinkedIn
>> http://www.linkedin.com/groups?home=&gid=2825448&trk=anet_ug_hm&goback=%2Emyg
>>
>>
>>
>> "Hemant" wrote in message
>>
>>> Hi,
>>>
>>> I am working on sql server 2000. I want to generate script of a table in
>>> a query.
>>> Is there any way like sp_helptext for views to create Script for tables?
>>>
>>> Thanks,
>>> Hemant
>>>
>>
>>
>
>
 >> Stay informed about: sp_helptext for Tables 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
SQL Server 2005 sp_helptext "There is no text for object" - When I execute: sp_helptext spSomeProc on a particular database on SQL server 2005, I get the error: There is no text for object 'spSomeProc'. Other approaches like: SELECT ROUTINE_DEFINITION, * FROM INFORMATION_SCHEMA.ROUTINES WHERE SPECIFIC_NAME =..

reconcile two tables - i trying to reconcile a log against files we recieve in from our clients. HeaderRecords contains the file Headers and DayRecLogs is the daytime log I need to show all files recieved that day and check tere is an enrty in the DayRecLogs for that file ...

Temp tables and SP - Hi, I have a StoredProcedure 'ProfitSP' in different databases and the ProfitSP is same in each database. If I execute ProfitSP as: <font color=purple> ; Exec DB1.dbo.ProfitSP @OrderStartDate, @OrderEndDate</font> it works fine! ...

Joining tables - I have two tables one table T1 only have one result per date table 2 T2 can range from 0 to 8 results per date, I want to pull back all of the results in T2 and sum the totals, in my example it will be summing "Stafftime" and "items&quo...

3 tables query - I hable that has a ProOnwerID and ProFinOwner, when I create the following view I get NULL in my ProOwner and FinOwner.. If I delte de Fin Owner the ProOwer shows up.. Any Idea why ?.... is it because I have two ID for Clients en same table ? ..
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]