當前位置:首頁 » 編程語言 » sql2012導出數據
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql2012導出數據

發布時間: 2022-07-30 21:12:01

sqlserver2012怎樣將一個表中的數據導出sql腳本

之後彈出SQLServer腳本生成向導
選擇資料庫
把編寫數據可腳本這一項改為true,默認是false只導出表結構
選擇需要導出的對象
選擇需要導出的表

Ⅱ sql2012導出數據選項在哪

對於會寫查詢SQL語句的則是直接寫查詢語句查詢出結果。如下圖:

接下來到桌面新建一個空的excel文件。
接下來回到SQLServer查詢界面。滑鼠右鍵點擊查詢結果的左上角空白列,點擊「連同標題一起復制」。則已復制好了數據。如下圖:

接下來打開之前建好的Excel文件把復制好的數據黏貼到excel即可。如下圖:

Ⅲ sql server2012如何導出數據到dbf

將SQL資料庫表導出為DBF文件。方法步驟如下:

1、打開SQL企業管理器,找到伺服器下對應資料庫的表,右鍵 所有任務-》導出數據
2、下一步之後選擇數據源時默認,目的數據源是選擇DBASE III ,文件名出填寫需要導出的目錄即可
3、繼續下一步即可。

Ⅳ SQL2012 全部數據太大 怎麼導出到多個文件

/*
--用BCP試試,不行再用下面的存儲過程
EXEC master..xp_cmdshell 'bcp "select * from test.dbo.Apo_village"
queryout "c:/Apo_SFZ.xlsx" -c -S"伺服器" -U"sa" -P"密碼"'
*/

--這是用C#寫的存儲過程,不知道你會不會編譯到SQL Server
--在資料庫這樣調用就是了
--Exec BulkCopyToXls 'SQL查詢語句','路徑','文件名',最大記錄數
--Exec BulkCopyToXls 'select * from 表','G:\Test','Table',60000
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
public partial class myProcere
{
[Microsoft.SqlServer.Server.SqlProcere]
public static void BulkCopyToXls(SqlString sql, SqlString savePath, SqlString tableName, SqlInt32 maxRecordCount)
{
if (sql.IsNull || savePath.IsNull || tableName.IsNull)
{
SqlContext.Pipe.Send(" 輸入信息不完整!");
}
//每個excel文件最大容納65534
ushort _maxRecordCount = ushort.MaxValue - 1;
if (maxRecordCount.IsNull == false && maxRecordCount.Value < ushort.MaxValue && maxRecordCount.Value > 0)
_maxRecordCount = (ushort)maxRecordCount.Value;
ExportXls(sql.Value, savePath.Value, tableName.Value, _maxRecordCount);
}
private static void ExportXls(string sql, string savePath, string tableName, System.UInt16 maxRecordCount)
{
//創建文件路徑
if (System.IO.Directory.Exists(savePath) == false)
{
System.IO.Directory.CreateDirectory(savePath);
}
using (SqlConnection conn = new SqlConnection("context connection=true"))
{
conn.Open();
using (SqlCommand command = conn.CreateCommand())
{
command.CommandText = sql;
using (SqlDataReader reader = command.ExecuteReader())
{
int i = 0;
int totalCount = 0;
int tick = System.Environment.TickCount;
SqlContext.Pipe.Send(" 開始導出數據");
while (true)
{
string fileName = string.Format(@"{0}/{1}.{2}.xls", savePath, tableName, i++);
int iExp = Write(reader, maxRecordCount, fileName);
long size = new System.IO.FileInfo(fileName).Length;
totalCount += iExp;
SqlContext.Pipe.Send(string.Format(" 文件{0}, 共{1} 條, 大小{2} 位元組", fileName, iExp, size.ToString("###,###")));
if (iExp < maxRecordCount) break;
}
tick = System.Environment.TickCount - tick;
SqlContext.Pipe.Send(" 導出數據完成");
SqlContext.Pipe.Send("-------");
SqlContext.Pipe.Send(string.Format(" 共{0} 條數據,耗時{1}ms", totalCount, tick));
}
}
}
}

private static void WriteObject(ExcelWriter writer, object obj, System.UInt16 x, System.UInt16 y)
{
//判斷寫數字還是寫字元
string type = obj.GetType().Name.ToString();
switch (type)
{
case "SqlBoolean":
case "SqlByte":
case "SqlDecimal":
case "SqlDouble":
case "SqlInt16":
case "SqlInt32":
case "SqlInt64":
case "SqlMoney":
case "SqlSingle":
if (obj.ToString().ToLower() == "null")
writer.WriteString(x, y, obj.ToString());
else
writer.WriteNumber(x, y, Convert.ToDouble(obj.ToString()));
break;
default:
writer.WriteString(x, y, obj.ToString());
break;
}
}

private static int Write(SqlDataReader reader, System.UInt16 count, string fileName)
{
int iExp = count;
ExcelWriter writer = new ExcelWriter(fileName);
writer.BeginWrite();
//寫欄位信息
for (System.UInt16 j = 0; j < reader.FieldCount; j++)
{
writer.WriteString(0, j, reader.GetName(j));
}
//循環一行一行讀入數據
for (System.UInt16 i = 1; i <= count; i++)
{
if (reader.Read() == false)
{
iExp = i - 1;
break;
}
//循環一格一格寫入數據
for (System.UInt16 j = 0; j < reader.FieldCount; j++)
{
WriteObject(writer, reader.GetSqlValue(j), i, j);
}
}
writer.EndWrite();
return iExp;
}

public class ExcelWriter
{
System.IO.FileStream _wirter;
//創建文件
public ExcelWriter(string strPath)
{
_wirter = new System.IO.FileStream(strPath, System.IO.FileMode.OpenOrCreate);
}

//寫數組
private void _writeFile(System.UInt16[] values)
{
foreach (System.UInt16 v in values)
{
byte[] b = System.BitConverter.GetBytes(v);
_wirter.Write(b, 0, b.Length);
}
}

//寫文件頭
public void BeginWrite()
{
_writeFile(new System.UInt16[] { 0x809, 8, 0, 0x10, 0, 0 });
}
//文件尾
public void EndWrite()
{
_writeFile(new System.UInt16[] { 0xa, 0 });
_wirter.Close();
}
//寫數字到單元格
public void WriteNumber(System.UInt16 x, System.UInt16 y, double value)
{
_writeFile(new System.UInt16[] { 0x203, 14, x, y, 0 });
byte[] b = System.BitConverter.GetBytes(value);
_wirter.Write(b, 0, b.Length);
}
//寫字元到單元格
public void WriteString(System.UInt16 x, System.UInt16 y, string value)
{
byte[] b = System.Text.Encoding.Default.GetBytes(value);
_writeFile(new System.UInt16[] { 0x204, (System.UInt16)(b.Length + 8), x, y, 0, (System.UInt16)b.Length });
_wirter.Write(b, 0, b.Length);
}
}
};

Ⅳ 如何SQL語句導出資料庫里的所有表(SQL2012)

數據量不小了,還用excel??直接還原到資料庫里查看不就行了,或者直接用access連過來看也行。還原bak文件的話,不需要寫sql。
首先,連接sqlserver,單擊「資料庫」右鍵->還原資料庫->"常規"->"還原的源"->"源設備"->選擇「...」按鈕->(出現指定備份的窗口)添加->選擇backup文件所在目錄(ps:文件的類型要所有文件,不然backup文件是看不見的)->(返回指定備份的窗口)確定->(這時你會看到很多備份的記錄)->目標資料庫選擇—>完成!

Ⅵ sqlserver2012怎樣導出數據

在要備份的資料庫上滑鼠右鍵單擊,選擇備份,見下圖:

在下圖中刪除默認的備份設備(一定要做這一步,否則SQL將創建媒體集,還原資料庫會失敗的。)

單擊添加按鈕,選擇備份路徑,和備份文件名後單擊確定即可

Ⅶ sqlserver2012里邊表怎麼導出

在SQL SERVER 2000裡面 有一個導入導出數據的嘛,你把要復制出來的數據選上,然後下一步就有復制到什麼地方,你就選擇EXCEL就可以進行操作了。
你試著做一下哈,應該沒有問題的!!!!!!!!!

Ⅷ sql2012怎麼導出資料庫腳本

索引是建立在表的基礎上的。所以SQL Server 2008沒有提供只導出索引腳本的選項。
可以在導出向導中將選項"生成索引腳本(Script Indexes)"設置為True,然後在對象類型中只選擇「表(Tables)".這樣導出的腳本中就包含了索引的腳本,當然也包括表的腳本。