Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

DataType.UserDefinedTableType Method (String, String)

Returns an object that represents the specified type with the specified schema.

Namespace:  Microsoft.SqlServer.Management.Smo
Assembly:  Microsoft.SqlServer.Smo (in Microsoft.SqlServer.Smo.dll)
public static DataType UserDefinedTableType(
	string type,
	string schema
)

Parameters

type
Type: System.String
A String value that specifies the type.
schema
Type: System.String
A String value that specifies the schema.

Return Value

Type: Microsoft.SqlServer.Management.Smo.DataType
A DataType object value.

The following code example shows how to create a user-defined table type.

C#

Server srv = new Server("(local)");
Database db = srv.Databases["AdventureWorks2012"];
Schema schema1 = new Schema(db, "ExampleSchema");
schema1.Create();
UserDefinedTableType udtt = new UserDefinedTableType(db, "udtt", "ExampleSchema");
Column c = new Column(udtt, "Column 1", DataType.Int);
udtt.Columns.Add(c);
udtt.Create();
DataType userTable = new DataType(SqlDataType.UserDefinedTableType, "udtt", "ExampleSchema");

Powershell

$srv = new-object Microsoft.SqlServer.Management.Smo.Server("(local)")
$db = $srv.Databases.Item("AdventureWorks2012")
$schema1 = new-object Microsoft.SqlServer.Management.Smo.Schema($db, "ExampleSchema")
$schema1.Create()
$udtt = new-object Microsoft.SqlServer.Management.Smo.UserDefinedTableType($db, "udtt", "ExampleSchema")
$c = new-object Microsoft.SqlServer.Management.Smo.Column($udtt, "Column 1", [Microsoft.SqlServer.Management.Smo.DataType]::Int)
$udtt.Columns.Add($c)
$udtt.Create()
$userTable = new-object Microsoft.SqlServer.Management.Smo.DataType([Microsoft.SqlServer.Management.Smo.SqlDataType]::UserDefinedTableType, "udtt", "ExampleSchema")
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.