Tworzenie, zmienianie i usuwanie ich ustawienia domyślne
W SQL Server Obiekty zarządzania obiekty (SMO), to domyślne ograniczenie jest reprezentowany przez Default obiekt.
The TextBody() właściwość of the Default object is used to zestaw the value to be inserted. Może to być stała lub Transact-SQL Instrukcja, która zwraca wartość stałą, takie jak GETDATE(). The TextBody() właściwość cannot be modified by using the Alter() metoda. Zamiast tego Default Obiekt musi być usunięty i utworzony ponownie.
Przykład
Aby używać dostarczonych przykładów kodu źródłowego, należy wybrać środowisko, szablon oraz język programowania, które będą używane do tworzenia aplikacji.Aby uzyskać więcej informacji zobacz Jak Tworzenie obiektów SMO projektu Visual Basic w programie Visual Studio .NET lub Jak Tworzenie projektu programu Visual C# obiekty SMO w programie Visual Studio .NET.
Tworzenie, zmienianie i usuwanie domyślnie w języku Visual Basic
W tym przykładzie kodu pokazano, jak utworzyć jedną domyślną jest prosty tekst, a inny domyślny jest Transact-SQL Instrukcja. Wartość domyślna musi być dołączony do kolumna używając BindToColumn(String, String) metody i odłączone przy użyciu UnbindFromColumn(String, String) Metoda.
Tworzenie, zmienianie i usuwanie domyślnego w środowisku Visual C#
W tym przykładzie kodu pokazano, jak utworzyć jedną domyślną jest prosty tekst, a inny domyślny jest Transact-SQL Instrukcja. Wartość domyślna musi być dołączony do kolumna używając BindToColumn(String, String) metody i odłączone przy użyciu UnbindFromColumn(String, String) Metoda.
{
//Connect to the local, default instance of SQL Server.
{
Server srv = default(Server);
srv = new Server();
//Reference the AdventureWorks database.
Database db = default(Database);
db = srv.Databases("AdventureWorks");
//Define a Default object variable by supplying the parent database and the default name
//in the constructor.
Default def = default(Default);
def = new Default(db, "Test_Default2");
//Set the TextHeader and TextBody properties that define the default.
def.TextHeader = "CREATE DEFAULT [Test_Default2] AS";
def.TextBody = "GetDate()";
//Create the default on the instance of SQL Server.
def.Create();
//Declare a Column object variable and reference a column in the AdventureWorks database.
Column col = default(Column);
col = db.Tables("SpecialOffer", "Sales").Columns("StartDate");
//Bind the default to the column.
def.BindToColumn("SpecialOffer", "StartDate", "Sales");
//Unbind the default from the column and remove it from the database.
def.UnbindFromColumn("SpecialOffer", "StartDate", "Sales");
def.Drop();
}
See Also
Reference
Default