1 out of 2 rated this helpful - Rate this topic

Table Class

The Table object represents a Microsoft SQL Server table.

Namespace: Microsoft.SqlServer.Management.Smo
Assembly: Microsoft.SqlServer.Smo (in microsoft.sqlserver.smo.dll)
public sealed class Table : TableViewBase, IColumnPermission, IObjectPermission, ICreatable, 
	IAlterable, IDroppable, IRenamable
public final class Table extends TableViewBase implements IColumnPermission, IObjectPermission, 
	ICreatable, IAlterable, IDroppable, IRenamable
public final class Table extends TableViewBase implements IColumnPermission, IObjectPermission, 
	ICreatable, IAlterable, IDroppable, IRenamable

Updated text:

Updated text:

This namespace, class, or member is supported only in version 2.0 of the Microsoft .NET Framework.

To get Table object properties, users can be a member of the public fixed server role.

To set Table object properties, users must have ALTER permission on the table.

To create a table, users must have CREATE TABLE permission on the parent database and ALTER permission in the schema.

To drop a table, users must have CONTROL permission on the table, or be a member of the db_ddladmin or db_owner fixed database roles.

To grant, deny, or revoke permission on the table to other users, users must have CONTROL permission on the table.


Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Development Platforms

For a list of the supported platforms, see Hardware and Software Requirements for Installing SQL Server 2005.

Target Platforms

Release

History

New content:
  • Added text to explain that the PartitionSchemeParameters property represents file groups.

Content changed:
  • Changed the return type to Int64 for the RowCount property.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Retrieve All Tables In All Databases on a SQL Server Using PowerShell

#-------------------------------------------------------------------------
# ScriptName : get-SQLServerTables.ps1
#
# Author : Richard Vantrease
#
# Purpose : Returns a collection of table objects for each
# database on a SQL Server. Will display interesting
# properties if the -Display switch is used.
#
# Dependencies : Microsoft.SQLServer.SMO
#-------------------------------------------------------------------------
param(
[string]$ServerName,
[switch]$Display
)

#-------------------------Environment Preferences-------------------------
Set-PSDebug -strict
#-------------------------------------------------------------------------

# Load Microsoft.SQLServer.SMO Library
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | out-null


$SQLServer = new-object "Microsoft.SQLServer.Management.SMO.Server" $ServerName


if($Display)
{
foreach($Database in $SQLServer.Databases)
{
$Database.Tables | ft Name, RowCount, DataSpaceUsed -AutoSize
}
}
else
{
foreach($Database in $SQLServer.Databases){ $Database.Tables }
}

Create Table Using PowerShell

#-------------------------------------------------------------------------

# ScriptName : create-SQLTable.ps1

#

# Author : Richard Vantrease

#

# Purpose : Create a new SQL Server table

#

# NOTE: I didn't really bother parameterizing the table columns as there

# are too many variables to make it feasible for this example. So, it will

# simply create two columns:

# A VARCHAR(50)

# B INT

#

# Dependencies : Microsoft.SQLServer.SMO

#-------------------------------------------------------------------------

param

(

[string]$ServerName,

[string]$DBName,

[string]$TableName

)


[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO')


#http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.sqldatatype.aspx

$DataTypes = [Microsoft.SQLServer.Management.SMO.SQLDataType]

$_VarChar = $DataTypes::VarChar

$_INT = $DataTypes::Int


$SQLServer = new-object ('Microsoft.SQLServer.Management.SMO.Server') $ServerName

$Database = $SQLServer.Databases[$DBName]


$Table = new-object 'Microsoft.SQLServer.Management.SMO.Table' ($Database, $TableName)


$Column = new-object 'Microsoft.SQLServer.Management.SMO.Column' ($Table, 'A', $_VarChar)

$Column.Properties['Length'].Value = 50

$Table.Columns.Add($Column)


$Column = new-object 'Microsoft.SQLServer.Management.SMO.Column' ($Table, 'B', $_INT)

$Table.Columns.Add($Column)

$Database.Tables.Add($Table)


$Database.Alter()

$SQLServer.Alter()

$Table.Create()