SSMS
 sql >> Teknologi Basis Data >  >> Database Tools >> SSMS

SQL Server Management Studio 2012 - Ekspor semua tabel database sebagai csv

Wisaya ekspor hanya mengizinkan satu per satu. Saya menggunakan skrip PowerShell untuk mengekspor semua tabel saya ke csv. Silakan coba ini jika ini membantu Anda.

$server = "SERVERNAME\INSTANCE"
$database = "DATABASE_NAME"
$tablequery = "SELECT schemas.name as schemaName, tables.name as tableName from sys.tables inner join sys.schemas ON tables.schema_id = schemas.schema_id"

#Delcare Connection Variables
$connectionTemplate = "Data Source={0};Integrated Security=SSPI;Initial Catalog={1};"
$connectionString = [string]::Format($connectionTemplate, $server, $database)
$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connectionString

$command = New-Object System.Data.SqlClient.SqlCommand
$command.CommandText = $tablequery
$command.Connection = $connection

#Load up the Tables in a dataset
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $command
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$connection.Close()



# Loop through all tables and export a CSV of the Table Data
foreach ($Row in $DataSet.Tables[0].Rows)
{
    $queryData = "SELECT * FROM [$($Row[0])].[$($Row[1])]"

    #Specify the output location of your dump file
    $extractFile = "C:\mssql\export\$($Row[0])_$($Row[1]).csv"

    $command.CommandText = $queryData
    $command.Connection = $connection

    $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
    $SqlAdapter.SelectCommand = $command
    $DataSet = New-Object System.Data.DataSet
    $SqlAdapter.Fill($DataSet)
    $connection.Close()

    $DataSet.Tables[0]  | Export-Csv $extractFile -NoTypeInformation
}

Terima kasih



  1. DBeaver
  2.   
  3. phpMyAdmin
  4.   
  5. Navicat
  6.   
  7. SSMS
  8.   
  9. MySQL Workbench
  10.   
  11. SQLyog
  1. SSMS mengizinkan catatan duplikat dalam tabel, tetapi bukan pembaruan berikutnya

  2. Skrip semua prosedur tersimpan di Management Studio 2005

  3. Bagaimana cara membuat ekstensi untuk SQL Server Management Studio 17 di C # di VS2017?

  4. T-SQL Masukkan ke dalam tabel tanpa harus menentukan setiap kolom

  5. CTRL+R tidak menyembunyikan jendela Hasil Kueri di SSMS