Project Description
SMO Lite is a .NET 4.0 API to create, update and view database objects. The classes and methods are identical to SMO, however, only the most commonly used classes and methods are implemented. The reduced functionality and design in favor of batch operations results in far better performance than SMO.

Sample Usage 1 (version 1.1.4)

Server server = new Server();

server.ConnectionContext.ServerInstance = "localhost";
server.ConnectionContext.Connect();

if (server.Databases["SampleDatabase"] != null)
{
    server.KillAllProcesses("SampleDatabase");
    server.KillDatabase("SampleDatabase");
}

Database database = new Database(server, "SampleDatabase");

database.Create();

FullTextCatalog fullTextCatalog = new FullTextCatalog(database, "SampleCatalog");

fullTextCatalog.Create();

Schema schema = new Schema(database, "SampleSchema");

schema.Create();

Table table = new Table(database, "SampleTable", schema.Name);

Column idColumn = new Column(table, "Id");

idColumn.DataType.SqlDataType = SqlDataType.UniqueIdentifier;

Column nameColumn = new Column(table, "Name");

nameColumn.DataType.SqlDataType = SqlDataType.NVarChar;
nameColumn.DataType.MaximumLength = 100;

table.Columns.Add(idColumn);
table.Columns.Add(nameColumn);

Index tablePrimaryKey = new Index("SampleTable_SamplePrimaryKey");

tablePrimaryKey.IsPrimaryKey = true;
tablePrimaryKey.FillFactor = 50;

IndexedColumn tablePrimaryKeyIndexedColumn = new IndexedColumn("Id");

tablePrimaryKey.IndexedColumns.Add(tablePrimaryKeyIndexedColumn);

table.Indexes.Add(tablePrimaryKey);

Index tableIndex = new Index("SampleTable_SampleIndex");

tableIndex.IsUnique = true;
tableIndex.FillFactor = 50;

IndexedColumn tableIndexIndexedColumn = new IndexedColumn("Name");

tableIndex.IndexedColumns.Add(tableIndexIndexedColumn);

table.Indexes.Add(tableIndex);

table.Create();

View view = new View(
    database,
    "SampleView",
    schema.Name,
    "CREATE VIEW SampleSchema.SampleView WITH SCHEMABINDING AS SELECT Id, Name FROM SampleSchema.SampleTable");

Index viewIndex = new Index("SampleView_SampleIndex");

viewIndex.IsUnique = true;
viewIndex.IsClustered = true;
viewIndex.FillFactor = 50;

IndexedColumn viewIndexedColumn = new IndexedColumn("Name");

viewIndex.IndexedColumns.Add(viewIndexedColumn);

view.Indexes.Add(viewIndex);

FullTextIndex fullTextIndex = new FullTextIndex();

fullTextIndex.CatalogName = "SampleCatalog";
fullTextIndex.UniqueIndexName = viewIndex.Name;

fullTextIndex.IndexedColumns.Add(new FullTextIndexColumn("Name"));

view.FullTextIndexes.Add(fullTextIndex);

view.Create();

StoredProcedure storedProcedure = new StoredProcedure(
    database,
    "SampleStoredProcedure",
    schema.Name,
    "CREATE PROCEDURE SampleSchema.SampleStoredProcedure AS SELECT Id, Name FROM SampleSchema.SampleTable");

storedProcedure.Create();

database.ExecuteNonQuery("INSERT SampleSchema.SampleTable (Id, Name) VALUES(NEWID(), 'Test 1')\nGO\nINSERT SampleSchema.SampleTable (Id, Name) VALUES(NEWID(), 'Test 2')\nGO\nINSERT SampleSchema.SampleTable (Id, Name) VALUES(NEWID(), 'Test 3')");

Sample Usage using SqlConnection (version 1.1.4)

SqlConnection sqlConnection = new SqlConnection();

SqlConnectionStringBuilder sqlConnectionStringBuilder = new SqlConnectionStringBuilder();

sqlConnectionStringBuilder.IntegratedSecurity = true;
sqlConnectionStringBuilder.Pooling = false;
sqlConnectionStringBuilder.DataSource = ".";

sqlConnection.ConnectionString = sqlConnectionStringBuilder.ToString();

sqlConnection.Open();

Server server = new Server(sqlConnection);

server.ConnectionContext.ServerInstance = "localhost";
server.ConnectionContext.Connect();

if (server.Databases["SampleDatabase"] != null)
{
    server.KillAllProcesses("SampleDatabase");
    server.KillDatabase("SampleDatabase");
}

Database database = new Database(server, "SampleDatabase");

database.Create();

FullTextCatalog fullTextCatalog = new FullTextCatalog(database, "SampleCatalog");

fullTextCatalog.Create();

Schema schema = new Schema(database, "SampleSchema");

schema.Create();

Table table = new Table(database, "SampleTable", schema.Name);

Column idColumn = new Column(table, "Id");

idColumn.DataType.SqlDataType = SqlDataType.UniqueIdentifier;

Column nameColumn = new Column(table, "Name");

nameColumn.DataType.SqlDataType = SqlDataType.NVarChar;
nameColumn.DataType.MaximumLength = 100;

table.Columns.Add(idColumn);
table.Columns.Add(nameColumn);

Index tablePrimaryKey = new Index("SampleTable_SamplePrimaryKey");

tablePrimaryKey.IsPrimaryKey = true;
tablePrimaryKey.FillFactor = 50;

IndexedColumn tablePrimaryKeyIndexedColumn = new IndexedColumn("Id");

tablePrimaryKey.IndexedColumns.Add(tablePrimaryKeyIndexedColumn);

table.Indexes.Add(tablePrimaryKey);

Index tableIndex = new Index("SampleTable_SampleIndex");

tableIndex.IsUnique = true;
tableIndex.FillFactor = 50;

IndexedColumn tableIndexIndexedColumn = new IndexedColumn("Name");

tableIndex.IndexedColumns.Add(tableIndexIndexedColumn);

table.Indexes.Add(tableIndex);

table.Create();

View view = new View(
    database,
    "SampleView",
    schema.Name,
    "CREATE VIEW SampleSchema.SampleView WITH SCHEMABINDING AS SELECT Id, Name FROM SampleSchema.SampleTable");

Index viewIndex = new Index("SampleView_SampleIndex");

viewIndex.IsUnique = true;
viewIndex.IsClustered = true;
viewIndex.FillFactor = 50;

IndexedColumn viewIndexedColumn = new IndexedColumn("Name");

viewIndex.IndexedColumns.Add(viewIndexedColumn);

view.Indexes.Add(viewIndex);

FullTextIndex fullTextIndex = new FullTextIndex();

fullTextIndex.CatalogName = "SampleCatalog";
fullTextIndex.UniqueIndexName = viewIndex.Name;

fullTextIndex.IndexedColumns.Add(new FullTextIndexColumn("Name"));

view.FullTextIndexes.Add(fullTextIndex);

view.Create();

StoredProcedure storedProcedure = new StoredProcedure(
    database,
    "SampleStoredProcedure",
    schema.Name,
    "CREATE PROCEDURE SampleSchema.SampleStoredProcedure AS SELECT Id, Name FROM SampleSchema.SampleTable");

storedProcedure.Create();

database.ExecuteNonQuery("INSERT SampleSchema.SampleTable (Id, Name) VALUES(NEWID(), 'Test 1')\nGO\nINSERT SampleSchema.SampleTable (Id, Name) VALUES(NEWID(), 'Test 2')\nGO\nINSERT SampleSchema.SampleTable (Id, Name) VALUES(NEWID(), 'Test 3')");

Last edited Feb 12, 2012 at 5:56 PM by bkejser, version 15