how does the scripter script a table in SMO?

fguihen

Well-known member
Joined
Nov 10, 2003
Messages
248
Location
Eire
In smo im trying to script each table out to a file. I can script each table to an array as shown:


Code:
Table[] tables = new Table[db.Tables.Count];

            db.Tables.CopyTo(tables, 0);

            SqlSmoObject[] smoObj = new SqlSmoObject[tables.Length];

            Array.Copy(tables, smoObj, tables.Length);

            Scripter scripter = new Scripter(s);
         
            StringCollection scriptsList = scripter.Script(smoObj);

            string[] scripts = new string[scriptsList.Count];
            scriptsList.CopyTo(scripts, 0);

i expected each array of the scripts array to have a table creation script, but no.

element 0 of the array contains the text:

SET ANSI_NULLS OFF

element 1 of the array contains the text:

SET QUOTED_IDENTIFIER ON

element 3 of the array contains the text:

CREATE TABLE [dbo].[_EXRATE02EuroZoneCurrencyRate](
[CurrencyCode] [char](3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[FixedExchangeRateAmt] [float] NOT NULL
) ON [PRIMARY]



this continues throughout the array. how am i supposed to find the end of one script and the beginning of another? will SET ANSI_NULLS OFF be at the beginning of each table script, if so i can create a new script each time i find that line.
 
Back
Top