Ⅰ 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)".这样导出的脚本中就包含了索引的脚本,当然也包括表的脚本。