IsPersisted 属性

获取布尔属性值,该值指定 Column 对象的计算值是否与数据一起保存,从而避免在每次访问该列时都进行计算。

命名空间:  Microsoft.SqlServer.Management.Smo
程序集:  Microsoft.SqlServer.Smo(在 Microsoft.SqlServer.Smo.dll 中)

语法

声明
<SfcPropertyAttribute(SfcPropertyFlags.None Or SfcPropertyFlags.Standalone Or SfcPropertyFlags.SqlAzureDatabase Or SfcPropertyFlags.Design)> _
Public Property IsPersisted As Boolean
    Get
    Set
用法
Dim instance As Column
Dim value As Boolean

value = instance.IsPersisted

instance.IsPersisted = value
[SfcPropertyAttribute(SfcPropertyFlags.None|SfcPropertyFlags.Standalone|SfcPropertyFlags.SqlAzureDatabase|SfcPropertyFlags.Design)]
public bool IsPersisted { get; set; }
[SfcPropertyAttribute(SfcPropertyFlags::None|SfcPropertyFlags::Standalone|SfcPropertyFlags::SqlAzureDatabase|SfcPropertyFlags::Design)]
public:
property bool IsPersisted {
    bool get ();
    void set (bool value);
}
[<SfcPropertyAttribute(SfcPropertyFlags.None|SfcPropertyFlags.Standalone|SfcPropertyFlags.SqlAzureDatabase|SfcPropertyFlags.Design)>]
member IsPersisted : bool with get, set
function get IsPersisted () : boolean
function set IsPersisted (value : boolean)

属性值

类型:System. . :: . .Boolean
一个布尔属性值,该值指定 Column 对象的计算值是否与数据一起保存。
如果为 True,则 Column 对象的计算值与数据一起保存。
如果为 False(默认值),则每次请求列数据时都会计算 Column 对象的计算值。
对于计算列,IsPersisted 属性只能设置为 True。否则将导致错误。

注释

The following example shows how to use feature in C#:

// compile with: /r:Microsoft.SqlServer.Smo.dll /r:Microsoft.SqlServer.ConnectionInfo.dll /r:Microsoft.SqlServer.Management.Sdk.Sfc.dll 
using System;
using Microsoft.SqlServer.Management.Smo;

public class A {
   public static void Main() {
      Server svr = new Server(); 
      Database db = new Database(svr, "TestDB");
      db.Create();

      Table tab1 = new Table(db, "Table1");

      Column col1 = new Column(tab1, "Col1", DataType.Int);

      // Computed column
      Column col2 = new Column(tab1, "Col2", DataType.Int);
      col2.Computed = true;
      col2.ComputedText = "col1 * 2";

      // Persisted Computed Column
      Column col3 = new Column(tab1, "Col3", DataType.Int);
      col3.Computed = true;
      col3.ComputedText = "col1 * 3";

      // allows the computed column to persist with table data
      col3.IsPersisted = true;   

      tab1.Columns.Add(col1);
      tab1.Columns.Add(col2);
      tab1.Columns.Add(col3);

      tab1.Create();

      // default value of IsPersisted for computed column is false
      Console.WriteLine(col2.Name + "  Computed = " + col2.Computed + "  Persisted =  " + col2.IsPersisted);
      Console.WriteLine(col3.Name + "  Computed = " + col3.Computed + "  Persisted =  " + col3.IsPersisted);
   }
}

The following example shows how to use feature in Visual Basic:

' compile with: /r:Microsoft.SqlServer.Smo.dll /r:Microsoft.SqlServer.ConnectionInfo.dll /r:Microsoft.SqlServer.Management.Sdk.Sfc.dll
Imports Microsoft.SqlServer.Management.Smo

Public Class A
   Public Shared Sub Main()
      Dim svr As New Server()
      Dim db As New Database(svr, "TestDB")
      db.Create()

      Dim tab1 As New Table(db, "Table1")

      Dim col1 As New Column(tab1, "Col1", DataType.Int)

      ' Computed column
      Dim col2 As New Column(tab1, "Col2", DataType.Int)
      col2.Computed = True
      col2.ComputedText = "col1 * 2"

      ' Persisted Computed Column
      Dim col3 As New Column(tab1, "Col3", DataType.Int)
      col3.Computed = True
      col3.ComputedText = "col1 * 3"

      ' allows the computed column to persist with table data
      col3.IsPersisted = True

      tab1.Columns.Add(col1)
      tab1.Columns.Add(col2)
      tab1.Columns.Add(col3)

      tab1.Create()

      ' default value of IsPersisted for computed column is false
      Console.WriteLine((col2.Name & "  Computed = " & col2.Computed & "  Persisted =  ") & col2.IsPersisted)
      Console.WriteLine((col3.Name & "  Computed = " & col3.Computed & "  Persisted =  ") & col3.IsPersisted)
   End Sub
End Class