문서를 영문으로 보려면 영문 확인란을 선택하세요. 마우스 포인터를 텍스트 위로 이동시켜 팝업 창에서 영문 텍스트를 표시할 수도 있습니다.
번역
영문

Column.IsPersisted 속성

Gets the Boolean property value that specifies whether the computed value of the Column object is saved with the data, thus avoiding a computation each time the column is accessed.

네임스페이스:  Microsoft.SqlServer.Management.Smo
어셈블리:  Microsoft.SqlServer.Smo(Microsoft.SqlServer.Smo.dll)

[SfcPropertyAttribute(SfcPropertyFlags.None|SfcPropertyFlags.Standalone|SfcPropertyFlags.SqlAzureDatabase|SfcPropertyFlags.Design)]
public bool IsPersisted { get; set; }

속성 값

유형: System.Boolean
A Boolean property value that specifies whether the computed value of the Column object is saved with the data.If True, the computed value of the Column object is saved with the data.If False (default), the computed value of the Column object is computed every time the column data is requested. The IsPersisted property can only be set to True for computed columns. Otherwise, it will cause an error.

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

커뮤니티 추가 항목

추가
표시: