Oluşturma ve güncelleştirme istatistikleri
smo, kullanarak veritabanı sorguları işleme hakkında istatistiksel bilgi toplanabilir Statisticnesnesini.
Kullanarak herhangi bir sütun için istatistikler oluşturmak mümkün Statisticve StatisticColumnnesnesini. UpdateYöntemi, istatistiklere güncelleştirmek için çalıştırılabilir Statisticnesnesini. Sorgu en iyi duruma getiricisi sonuçları görülebilir.
Örnek
Sunulan kod örneklerinden herhangi birini kullanmak için, programlama ortamını, programlama şablonunu ve uygulamanızı oluşturacağınız programlama dilini seçmeniz gerekecektir. Daha fazla bilgi için, bkz. Visual Studio'da Visual Basic smo proje oluşturun.NET veya Visual Studio'da Visual C# smo proje oluşturun.NET.
Oluşturma ve Visual Basic istatistikleri güncelleştirme
Varolan bir veritabanına, yeni bir tablo bu kod örneği oluşturur Statisticnesnesi ve StatisticColumnnesnesi oluşturulur.
'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server
'Reference the AdventureWorks2012 database.
Dim db As Database
db = srv.Databases("AdventureWorks2012")
'Reference the CreditCard table.
Dim tb As Table
tb = db.Tables("CreditCard", "Sales")
'Define a Statistic object by supplying the parent table and name arguments in the constructor.
Dim stat As Statistic
stat = New Statistic(tb, "Test_Statistics")
'Define a StatisticColumn object variable for the CardType column and add to the Statistic object variable.
Dim statcol As StatisticColumn
statcol = New StatisticColumn(stat, "CardType")
stat.StatisticColumns.Add(statcol)
'Create the statistic counter on the instance of SQL Server.
stat.Create()
Oluşturma ve güncelleştirme istatistikleri Visual C#
Varolan bir veritabanına, yeni bir tablo bu kod örneği oluşturur Statisticnesnesi ve StatisticColumnnesnesi oluşturulur.
{
//Connect to the local, default instance of SQL Server.
Server srv = new Server();
//Reference the AdventureWorks2012 database.
Database db = default(Database);
db = srv.Databases["AdventureWorks2012"];
//Reference the CreditCard table.
Table tb = db.Tables["CreditCard", "Sales"];
//Define a Statistic object by supplying the parent table and name
//arguments in the constructor.
Statistic stat = default(Statistic);
stat = new Statistic(tb, "Test_Statistics");
//Define a StatisticColumn object variable for the CardType column
//and add to the Statistic object variable.
StatisticColumn statcol = default(StatisticColumn);
statcol = new StatisticColumn(stat, "CardType");
stat.StatisticColumns.Add(statcol);
//Create the statistic counter on the instance of SQL Server.
stat.Create();
}
{
//Connect to the local, default instance of SQL Server.
Server srv = new Server();
//Reference the AdventureWorks2012 database.
Database db = default(Database);
db = srv.Databases["AdventureWorks2012"];
//Reference the CreditCard table.
Table tb = db.Tables["CreditCard", "Sales"];
//Define a Statistic object by supplying the parent table and name
//arguments in the constructor.
Statistic stat = default(Statistic);
stat = new Statistic(tb, "Test_Statistics");
//Define a StatisticColumn object variable for the CardType column
//and add to the Statistic object variable.
StatisticColumn statcol = default(StatisticColumn);
statcol = new StatisticColumn(stat, "CardType");
stat.StatisticColumns.Add(statcol);
//Create the statistic counter on the instance of SQL Server.
stat.Create();
}
Oluşturma ve güncelleştirme istatistikleri PowerShell
Varolan bir veritabanına, yeni bir tablo bu kod örneği oluşturur Statisticnesnesi ve StatisticColumnnesnesi oluşturulur.
# Example of implementing a full text search on the default instance.
# Set the path context to the local, default instance of SQL Server and database tables
CD \sql\localhost\default\databases
$db = get-item AdventureWorks2012
CD AdventureWorks2012\tables
#Get a reference to the table
$tb = get-item Production.ProductCategory
# Define a FullTextCatalog object variable by specifying the parent database and name arguments in the constructor.
$ftc = New-Object -TypeName Microsoft.SqlServer.Management.SMO.FullTextCatalog -argumentlist $db, "Test_Catalog2"
$ftc.IsDefault = $true
# Create the Full Text Search catalog on the instance of SQL Server.
$ftc.Create()
# Define a FullTextIndex object variable by supplying the parent table argument in the constructor.
$fti = New-Object -TypeName Microsoft.SqlServer.Management.SMO.FullTextIndex -argumentlist $tb
# Define a FullTextIndexColumn object variable by supplying the parent index
# and column name arguments in the constructor.
$ftic = New-Object -TypeName Microsoft.SqlServer.Management.SMO.FullTextIndexColumn -argumentlist $fti, "Name"
# Add the indexed column to the index.
$fti.IndexedColumns.Add($ftic)
# Set change tracking
$fti.ChangeTracking = [Microsoft.SqlServer.Management.SMO.ChangeTracking]::Automatic
# Specify the unique index on the table that is required by the Full Text Search index.
$fti.UniqueIndexName = "AK_ProductCategory_Name"
# Specify the catalog associated with the index.
$fti.CatalogName = "Test_Catalog2"
# Create the Full Text Search Index
$fti.Create()
# Example of implementing a full text search on the default instance.
# Set the path context to the local, default instance of SQL Server and database tables
CD \sql\localhost\default\databases
$db = get-item AdventureWorks2012
CD AdventureWorks2012\tables
#Get a reference to the table
$tb = get-item Production.ProductCategory
# Define a FullTextCatalog object variable by specifying the parent database and name arguments in the constructor.
$ftc = New-Object -TypeName Microsoft.SqlServer.Management.SMO.FullTextCatalog -argumentlist $db, "Test_Catalog2"
$ftc.IsDefault = $true
# Create the Full Text Search catalog on the instance of SQL Server.
$ftc.Create()
# Define a FullTextIndex object variable by supplying the parent table argument in the constructor.
$fti = New-Object -TypeName Microsoft.SqlServer.Management.SMO.FullTextIndex -argumentlist $tb
# Define a FullTextIndexColumn object variable by supplying the parent index
# and column name arguments in the constructor.
$ftic = New-Object -TypeName Microsoft.SqlServer.Management.SMO.FullTextIndexColumn -argumentlist $fti, "Name"
# Add the indexed column to the index.
$fti.IndexedColumns.Add($ftic)
# Set change tracking
$fti.ChangeTracking = [Microsoft.SqlServer.Management.SMO.ChangeTracking]::Automatic
# Specify the unique index on the table that is required by the Full Text Search index.
$fti.UniqueIndexName = "AK_ProductCategory_Name"
# Specify the catalog associated with the index.
$fti.CatalogName = "Test_Catalog2"
# Create the Full Text Search Index
$fti.Create()