一个数据库至少包含几个文件和文件组主数据文件和次数据文件有哪些不同

一个数据库至少包含几个文件和文件组主数据文件和次数据文件有哪些不同,第1张

最少1个主文件mdf,一个日志文件ldf,每个数据有一个主要文件组。主要文件主要数据文件包含数据库的启动信息,并指向数据库中的其他文件。用户数据和对象可存储在此文件中,也可以存储在次要数据文件中。每个数据库有一个主要数据文件。主要数据文件的建议文件扩展名是 mdf。次要文件次要数据文件是可选的,由用户定义并存储用户数据。通过将每个文件放在不同的磁盘驱动器上,次要文件可用于将数据分散到多个磁盘上。另外,如果数据库超过了单个 Windows 文件的最大大小,可以使用次要数据文件,这样数据库就能继续增长。次要数据文件的建议文件扩展名是 ndf。事务日志文件事务日志文件保存用于恢复数据库的日志信息。每个数据库必须至少有一个日志文件。事务日志的建议文件扩展名是 ldf。什么时候应该备份master数据库?最好每天都备份。一般可以在有系统设置,添加用户后备份也可以。

不太理解你的问题。如果是想将这个数据库中的三张表中数据导出保存到其它格式的文件(例如excel)是需要三个excel文件,但有手段也可以保存到一个excel文件中的三个sheet中。如果是要导出到access这样的数据库中也只要一个数据库,三张表就可以了。关键是你想要干什么。

/

--用BCP试试,不行再用下面的存储过程

EXEC masterxp_cmdshell 'bcp "select from testdboApo_village"

queryout "c:/Apo_SFZxlsx" -c -S"服务器" -U"sa" -P"密码"'

/

--这是用C#写的存储过程,不知道你会不会编译到SQL Server

--在数据库这样调用就是了

--Exec BulkCopyToXls 'SQL查询语句','路径','文件名',最大记录数

--Exec BulkCopyToXls 'select from 表','G:\Test','Table',60000

using System;

using SystemData;

using SystemDataSqlClient;

using SystemDataSqlTypes;

using MicrosoftSqlServerServer;

public partial class myProcedure

{

    [MicrosoftSqlServerServerSqlProcedure]

    public static void BulkCopyToXls(SqlString sql, SqlString savePath, SqlString tableName, SqlInt32 maxRecordCount)

    {

        if (sqlIsNull || savePathIsNull || tableNameIsNull)

        {

            SqlContextPipeSend(" 输入信息不完整!");

        }

        //每个excel文件最大容纳65534

        ushort _maxRecordCount = ushortMaxValue - 1;

        if (maxRecordCountIsNull == false && maxRecordCountValue < ushortMaxValue && maxRecordCountValue > 0)

            _maxRecordCount = (ushort)maxRecordCountValue;

        ExportXls(sqlValue, savePathValue, tableNameValue, _maxRecordCount);

    }

    private static void ExportXls(string sql, string savePath, string tableName, SystemUInt16 maxRecordCount)

    {

        //创建文件路径

        if (SystemIODirectoryExists(savePath) == false)

        {

            SystemIODirectoryCreateDirectory(savePath);

        }

        using (SqlConnection conn = new SqlConnection("context connection=true"))

        {

            connOpen();

            using (SqlCommand command = connCreateCommand())

            {

                commandCommandText = sql;

                using (SqlDataReader reader = commandExecuteReader())

                {

                    int i = 0;

                    int totalCount = 0;

                    int tick = SystemEnvironmentTickCount;

                    SqlContextPipeSend(" 开始导出数据");

                    while (true)

                    {

                        string fileName = stringFormat(@"{0}/{1}{2}xls", savePath, tableName, i++);

                        int iExp = Write(reader, maxRecordCount, fileName);

                        long size = new SystemIOFileInfo(fileName)Length;

                        totalCount += iExp;

                        SqlContextPipeSend(stringFormat(" 文件{0}, 共{1} 条, 大小{2} 字节", fileName, iExp, sizeToString("###,###")));

                        if (iExp < maxRecordCount) break;

                    }

                    tick = SystemEnvironmentTickCount - tick;

                    SqlContextPipeSend(" 导出数据完成");

                    SqlContextPipeSend("-------");

                    SqlContextPipeSend(stringFormat(" 共{0} 条数据,耗时{1}ms", totalCount, tick));

                }

            }

        }

    }  private static void WriteObject(ExcelWriter writer, object obj, SystemUInt16 x, SystemUInt16 y)

    {

        //判断写数字还是写字符

        string type = objGetType()NameToString();

        switch (type)

        {

            case "SqlBoolean":

            case "SqlByte":

            case "SqlDecimal":

            case "SqlDouble":

            case "SqlInt16":

            case "SqlInt32":

            case "SqlInt64":

            case "SqlMoney":

            case "SqlSingle":

                if (objToString()ToLower() == "null")

                    writerWriteString(x, y, objToString());

                else

                    writerWriteNumber(x, y, ConvertToDouble(objToString()));

                break;

            default:

                writerWriteString(x, y, objToString());

                break;

        }

    }

   

    private static int Write(SqlDataReader reader, SystemUInt16 count, string fileName)

    {

        int iExp = count;

        ExcelWriter writer = new ExcelWriter(fileName);

        writerBeginWrite();

        //写字段信息

        for (SystemUInt16 j = 0; j < readerFieldCount; j++)

        {

            writerWriteString(0, j, readerGetName(j));

        }

        //循环一行一行读入数据

        for (SystemUInt16 i = 1; i <= count; i++)

        {

            if (readerRead() == false)

            {

                iExp = i - 1;

                break;

            }

            //循环一格一格写入数据

            for (SystemUInt16 j = 0; j < readerFieldCount; j++)

            {

                WriteObject(writer, readerGetSqlValue(j), i, j);

            }

        }

        writerEndWrite();

        return iExp;

    }

   

    public class ExcelWriter

    {

        SystemIOFileStream _wirter;

        //创建文件

        public ExcelWriter(string strPath)

        {

            _wirter = new SystemIOFileStream(strPath, SystemIOFileModeOpenOrCreate);

        }

        

        //写数组

        private void _writeFile(SystemUInt16[] values)

        {

            foreach (SystemUInt16 v in values)

            {

                byte[] b = SystemBitConverterGetBytes(v);

                _wirterWrite(b, 0, bLength);

            }

        }

       

        //写文件头

        public void BeginWrite()

        {

            _writeFile(new SystemUInt16[] { 0x809, 8, 0, 0x10, 0, 0 });

        }

       //文件尾

        public void EndWrite()

        {

            _writeFile(new SystemUInt16[] { 0xa, 0 });

            _wirterClose();

        }

       //写数字到单元格

        public void WriteNumber(SystemUInt16 x, SystemUInt16 y, double value)

        {

            _writeFile(new SystemUInt16[] { 0x203, 14, x, y, 0 });

            byte[] b = SystemBitConverterGetBytes(value);

            _wirterWrite(b, 0, bLength);

        }

       //写字符到单元格

        public void WriteString(SystemUInt16 x, SystemUInt16 y, string value)

        {

            byte[] b = SystemTextEncodingDefaultGetBytes(value);

            _writeFile(new SystemUInt16[] { 0x204, (SystemUInt16)(bLength + 8), x, y, 0, (SystemUInt16)bLength });

            _wirterWrite(b, 0, bLength);

        }

    }

};

access数据库不会将各种数据库对象存储为多种不同的文件。在Access数据库中,各种数据库对象被存储在一个文件中,该文件通常被称为“数据库文件”(accdb或mdb)。这些对象包括表、查询、表单、报表、宏、模块等等。因此,Access数据库不会将不同的数据库对象存储为多种不同的文件,而是将它们存储在同一个文件中。

由于工作需要,涉及到抽取多个sqlite文件。。考虑到不能写多个sqlite数据库的链接不确定个数因此和同事研究解决。

1 新建一个transA:内容如下

Get File Names---》Select Values---》Copy rows to result

2 新建一个 transB:内容如下

主要是处理sqlite数据库的。。形式不固定。。但是配置sqlite数据库连接那里要注意的是下面的jdbc:sqlite:${filename}

这里非常关键,因为不确定有多少个sqlite文件。

设置好后。在transB的右工作区右键选择trans setting或者ctrl+T,在parameter折页下的parameter下输入filename并保存

3 新建一个job,内容如下

start---》transA---》transB

其中对transB右键。到advanced下选中copy previous results to parameters 和Execute for every input row,并到parameter折页下的parameter输入filename,Stream column name 输入filename保存即可

4执行job

以上就是关于一个数据库至少包含几个文件和文件组主数据文件和次数据文件有哪些不同全部的内容,包括:一个数据库至少包含几个文件和文件组主数据文件和次数据文件有哪些不同、一个数据库对象可存放在多个文件中是对还是错、如何将SQLSERVER数据库备份到多个文件等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/9535994.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-29
下一篇2023-04-29

发表评论

登录后才能评论

评论列表(0条)

    保存