Get Tables of SQLServer in PowerShell
2012-09-28 15:41
483 查看
This is a function that it is show the tables of database using poweshell, as follow:
function TableListShow
{
$SQLSERVER=read-host "Enter SQL Server Name:"
$Database=read-host "Enter Database Name:"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$CnnString = "Server=$SQLSERVER;Database=$DATABASE;Integrated Security=True"
$SqlConnection.ConnectionString = $CnnString
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = "select name from sysobjects where type='u'"
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$SqlConnection.Close()
$DataSet.Tables[0]
}
function TableListShow
{
$SQLSERVER=read-host "Enter SQL Server Name:"
$Database=read-host "Enter Database Name:"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$CnnString = "Server=$SQLSERVER;Database=$DATABASE;Integrated Security=True"
$SqlConnection.ConnectionString = $CnnString
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = "select name from sysobjects where type='u'"
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$SqlConnection.Close()
$DataSet.Tables[0]
}
相关文章推荐
- How to Get First and Last Day of a Month in SQL Server
- System tables of a geodatabase in SQL Server
- System tables of a geodatabase in SQL Server
- Display the size of all tables in Sql Server 2005
- sql server query to get the list of column name in a table
- Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.
- How to Get First and Last Day of a Week in SQL Server
- SQL Server Autogrow of file ‘xxx_Log’ in database ‘xxx’ was cancelled by user or timed out解决方法
- Using INSTEAD OF triggers in SQL Server for DML operations
- Partitioning & Archiving tables in SQL Server (Part 2: Split, Merge and Switch partitions)
- ORA-30926: unable to get a stable set of rows in the source tables
- In order to run a trace against SQL Server you must be a member of sysadmin fixed server role or have the ALTER TRACE permission.
- Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection
- Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance
- Database cannot be started in this edition of SQL Server" error when restoring a Microsoft Dynamics CRM database
- Get Error when restoring database in Sql Server 2008 R2
- Sample script that displays all of the users in a given SQL Server DB
- Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection
- Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path 解决(VS2010+IIS7.5)
- Partitioned Tables and Indexes in SQL Server 2005