Using the Microsoft.SqlServer.Management.Smo.Scripter object, I'm generating scripts for each of the tables in my database, including indexes/constraints. When it generates the script, however, it includes all the index options, even though they are the default values, e.g.,
CREATE TABLE [dbo].[AgeGroup](
[AgeGroupID] [int] NOT NULL),
CONSTRAINT [PK_AgeGroup] PRIMARY KEY CLUSTERED
(
[AgeGroupID] ASC
) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
All the options in the WITH clause of the primary key constraint are set to the default values (at least according to SQL Server Books Online). How can I get the Scripter object to not output those options?
Here is my code:
Server server = new Server("MYSERVER");
Scripter scripter = new Scripter(server);
scripter.Options.Indexes = true;
scripter.Options.AnsiPadding = true;
scripter.Options.AnsiFile = true;
scripter.Options.Permissions = true;
scripter.Options.ClusteredIndexes = true;
scripter.Options.DriAll = true;
Urn[] urns = new Urn[1];
Table t = server.Databases["MYDATABASE"].Tables["AgeGroup"];
urns[0] = t.Urn;
StringCollection sc = scripter.Script(urns);
using (StreamWriter sw = File.CreateText("AgeGroup.Table.sql"))
foreach (string str in sc)
sw.WriteLine(str);