1.It’s worth noting that a lot of
people will never need to create their own database.You may never create your own tables or other data structures either.
You may only ever run backups and restores and manipulate the security on the system and let application installs create databases for you.That’s completely understandable and perfectly in line with the needs of many businesses and many accidental DBAs.However, it’s a good idea to understand what this stuff is and how it works as part of understanding SQL Server.
1.值得一提的是许多人不需要去创建自己数据库。你可能也从不会创建自己的桌面和其他的数据结构。.你也许只运行备份、恢复和维护系统的安全性并且在应用程序安装时为你创建数据库。那是完全可以理解的而且符合许多商人和临时的数据库的需要。然而,理解这件事情是一个好主意和理解数据库的一部分是如何工作的
2.A Database Is Actually Files
You need to store information that you want to be able to retrieve later. It’s necessary that you organize that information. If you were working with a word processing program, you store different documents in different files. You really wouldn’t put all of your documents into a single, large file. SQL Server functions in a very similar manner. While you have a server, you’re not going to simply store all the various types of information necessary to run your business in one large pile within that server. Instead you’re going to organize that information. The initial organizational mechanism for SQL Server is the database. A database allows you to keep sets of information in separate storage areas. Further it allows you to isolate the security for those different sets of information so that you can control who gets to see or modify that data.
2.数据库是一个真实的文件
你需要你的信息以后可以检索。整理信息是必要的。如果你在做一个一个文字处理程序,你要储存不同的文档在不同的文件里。你不会将所有文件放入一个大文件里 ,SQL server 有一个十分相似的功能。当你有一个服务器,你不会简单地存储所有所需的各种类型的信息在一个大型的服务器里运行你的业务。相反,你要组织这些信息。这些组织原理机制一开始来自于SQL server 数据库。数据库允许你输入的信息在不同的存储区域。它允许你进一步对于信息的安全分离,这样你可以控制谁可以看到或修改数据。
3.Within a database there are these things called tables. Tables are how the relational storage gets defined. The information that you’ve organized for storage in a given database will be added to these tables. You will be able to add or remove data to the database by way of these tables. You’ll also be able to retrieve the information from the database from these tables.
3.这些东西在数据库中称为表。表是表示存储是怎么定义的。在给定的数据库中储存信息会被添加到表中。你可以通过这些表来向数据库中添加和移动数据。你也可以在表中搜索数据库中的信息。
4.In addition to tables in the database, there are a number of different constructs that will help you manage the information within your database that are also stored within the database. These include a number of different types of objects that help you manipulate the data such as views, stored procedures and functions. You also get a full set of security objects such as roles and users.
4.除了数据库中的表之外,还有许多不同的构造可以帮助您管理数据库中的信息,这些信息也存储在数据库中。其中包括许多不同类型的对象,这些对象可以帮助您操作诸如视图、存储过程和函数等数据。您还可以得到一组完整的安全对象,如角色和用户。
5.Databases are actually made up of files that are stored somewhere on the Windows file system. These files are in a proprietary, binary format and cannot be read directly except through SQL Server. Writing data to these files is one of the most expensive and time consuming operations within SQL Server (although in most cases, the time involved is measured in microseconds). Because of this expense, it’s important to understand that your databases are defined by files and that it matters where they are stored as part of your understanding of the database.
5.数据库实际上是由储存在Windows文件系统里的文件组成的。这些数据是以二进制的形式存储的并且不能被直接读取除了通过数据库。在数据库中把这些文件写成数据是最昂贵和耗时的操作(即使在大多数情况下,这些复杂的时间是以微秒衡量的)。因为这种花费,理解你的数据库是如何通过文件定义的是重要的并且它们作为你理解数据库的一部分被储存在哪里也是重要的。
6.Two Types of Files
You could simply store your data in a text file or a spreadsheet and plenty of people do. But when you need multiple people to access it at the same time, updating some of the date, deleting some, inserting new information, all at the same time, those other storage mechanisms become very problematic. That’s why you need to use a database. Because SQL Server has to do so much different kinds of work with the data that it’s storing, it’s come up with some different mechanisms for performing those actions. Databases are structured around two different types of files that store different kinds of information . You can refer to this figure as we go through the two types.
NOTE: There are actually several other file types that can be added to a database, but we’re talking fundamentals here, so we’ll keep it straight forward and simple for now.
6.两种类型的文件
你可以简单地将你的数据存储在一个文本文件或表格,并且很多人这样做。但是当你需要多人同时访问它,更新的日期,删除一些,插入新的信息的时候,那些其他存储机制变得非常有问题。这就是为什么你需要使用一个数据库。因为SQL Server有许多的不同种类的工作与数据存储,并提出了一些不同的机制来执行这些操作。数据库是围绕两种不同类型的文件存储来储存不同种类的信息。当我们讨论这两个类型时,你可以参考这里的数据。
注意:还有其他文件类型,可以添加到一个数据库,但是我们这里说的基础,所以现在简单直接的说明。
7.Data File
The first type of file needed to define your database is the data file. The data file is easy to understand and explain. This type of file is where the information that you write to your database is going to be stored. Any given database can be made up of multiple data files. The data files can be placed on more than one hard drive with your system. If you have more advanced storage mechanisms, such as Storage Area Networks (SAN), you may have other constructs than simple hard drives on a server, but they will be mapped to the Windows operating system as drives and SQL Server can use those for storage of the data files as well.
7.定义数据库所需的第一种文件是数据文件。数据文件很容易理解和解释。这种类型的文件是您写入数据库的信息将要存储的地方。任何给定的数据库都可以由多个数据文件组成。数据文件可以被放置在您的系统的多个硬盘上。如果你有更先进的存储机制,如存储区域网络(SAN),你可能有其他构造简单的服务器上的硬盘,但他们将作为驱动器映射到Windows操作系统和SQL服务器可以使用这些存储的数据文件。
8.Log File
The second type of file needed to create a database is the log file. A log file is a slightly more complex thing to understand than the data file. A log file records every transaction that takes place within the database. A transaction occurs when data is manipulated in some way within the system. These manipulations can be updates to existing data, adding new data by inserting it into a table, or deletes of data from tables. All these actions cause information to be written to the log file. There are a number of other functions also associated with the log file. These files are usually much smaller than the data files because the entries into the log file only need to be kept around until all the data has been successfully written to the data file. Because writing to the data file is subject to different kinds of failures, log files are kept to help deal with those failures. Once information has been written to the data file, the log entry can be removed. The process to clean up log files will be discussed in detail in another post.
8.创建数据库所需的第二种文件是日志文件。日志文件比数据文件稍微复杂一点。日志文件记录在数据库中发生的每一个事务。当数据在系统中以某种方式被操纵时,就会发生事务。这些操作可以对现有数据进行更新,通过将新数据插入到表中,或者从表中删除数据来添加新数据。.所有这些操作都会将信息写入日志文件。还有许多其他函数也与日志文件有关。这些文件通常比数据文件小得多,因为日志文件中的条目只需要保存,直到所有数据都成功写入数据文件。因为写入数据文件会受到不同类型的失败,所以保存日志文件以帮助处理这些失败。一旦信息写入数据文件,日志条目就可以被删除。清理日志文件的过程将在另一个帖子中详细讨论。
9.When you’re initially creating the files you can adjust their size. You can adjust that size, both up and down, after creating the files as well. Each file can also be set to grow automatically and this is complicated enough so it’s worth spending a little more time understanding exactly what it means.
9.你可以调整它们的尺寸当你最初创建这些文件时,你也可以在创建这些文件之后来回调整它的尺寸。每个文件也可以被设置成自动变化,这是足够复杂的因此花费点时间理解它准确意味着什么是值得的。
10.Autogrowth settings
Managing files on databases can be a lot of work if you have a lot of databases. You’ll have to check for the available space and then set the files to larger sizes when there is enough. One way around all this manual work is to use the autogrow property settings on the database.
10.自动增长设置
数据库可以在管理文件中做大量的工作,如果你有很多的数据库。你必须检查可用空间,来保证输入文件的空间足够。在本手册所有工作的方法之一是使用上的自动增长属性设置数据库。
11.A word of caution: Be very careful using this setting. You can fill a drive and cause your server to go offline.
Setting a database to autogrow means that the database will automatically adjust the file size upwards when it starts to run out of room. Many people use this setting and many applications set it to on when they’re installed. You should set an upper growth limit on the files in order to avoid that problem. You can set the files to grow by a percentage of the database or in fixed sizes. For smaller databases, growing by percentages can work, but as the database expands in size, growing by percentages becomes a longer and longer process. The best practice is to set the growth to a particular value instead of a percentage. The details on how to set all these will be covered when databases get created.
11.注意:使用这个设置时要非常小心。您可以填充驱动器并使您的服务器脱机。将数据库设置为autogrow意味着数据库在开始运行时将自动调整文件大小。许多人使用这个设置,许多应用程序在安装时设置它。为了避免这个问题,您应该设置文件的上增长限制。您可以通过数据库或固定大小的百分比来设置文件。对于较小的数据库,按百分比增长是可行的,但随着数据库规模的扩大,以百分比增长的过程将变得更长更长的过程。最佳实践是将增长设置为特定值,而不是百分比。关于如何设置所有这些的细节将在数据库被创建时覆盖。
12.Where to place your files
When you install SQL Server, you have the option of defining where your database files will be placed. You can also adjust this through the Server Properties window. It’s always best to know where you are going to be placing files when you create a database in order to be sure that you have enough space on that drive. To see this location, connect to your server as was outlined in Database Fundamentals #2. Once connected, in the Object Explorer window, right click on the server name itself. This will bring up a context menu. Select the “Properties” menu choice at the bottom of that menu. This will open the Server Properties window and you will be in the default, “General”, tab. Select the “Database Settings” tab and you will see something very similar to this:
12.当您安装SQL Server时,您可以选择定义数据库文件的位置。您还可以通过服务器属性窗口进行调整。当您创建一个数据库时,最好知道您将在哪里放置文件,以确保您在该驱动器上有足够的空间。要查看此位置,请与您的服务器连接,如数据库基础2所述。在连接后,右键单击服务器名称本身。这将弹出一个上下文菜单。在菜单的底部选择“Properties”菜单选项。这将打开服务器属性窗口,您将处于默认的“General”选项卡中。选择选项卡,您将看到与此类似的东西:
13.The interesting area to look at here is at the bottom of the window in the section titled Database default locations. You’ll see three different directories listed, one each for Data, Log and Backup. By clicking on the ellipsis at the right side of the entry you can bring up a default file browser window to make a change to the default location of your log or data files. You can also modify them by typing directly into the text box with either a physical path as shown above or using a Universal Naming Convention (UNC) path.
13.有趣的地方是看这个在窗口的底部被命名为数据错误位置的部分。你将看到三个不同的列成表的引导,在数据,记录,备份中的一个。通过点击入口的右边的省略号,你可以提出一个浏览器窗口的错误文件来改变你的记录和数据文件的错误的位置。你也可以通过在这个文本框直接输入来修改它们用上面展示的物理路线或使用一个通用的名为公约路线。
14.The goal for placing files should be to attempt to separate functionality as much as you can. If you have the capability, you’re better off separating your operating system files from your data and log files. This means placing the data and log files on something other than the C:\ drive, if possible. Further, you should at least consider storing the data and log files on completely separate drives as well. This allows for the maximum throughput of data to the files on the drives.
14.放置文件的目标应该是尽可能地分离功能。如果有能力,最好将操作系统文件与数据和日志文件分离。这意味着,如果可能的话,将数据和日志文件放在驱动器以外的其他东西上。此外,至少应该考虑将数据和日志文件存储在完全独立的驱动器上。这允许对驱动器上的文件进行数据的最大吞吐量。
15.Once you’ve determined that the storage location is appropriate, if you’ve made changes, click on the OK button to save those changes. If you haven’t made any changes, or you don’t wish to save the changes you made, click the Cancel button. Either of these clicks will close the Server Properties window.
15.如果您已经进行了更改并确定了存储位置是适当的,那么单击OK按钮来保存这些更改。如果您没有做任何更改,或者您不希望保存所做的更改,请单击Cancel按钮。这两种单击都将关闭服务器属性窗口。
16.Each of the two file types have several properties in addition to the physical location that will matter when you create your databases. Part of the physical location will be the file name and extension. These can be any valid Windows operating system name and extensions. By default the extensions will usually be .mdf for the data file and .ldf for the log file. You can change these if you want, but it could lead to confusion since most people use the defaults as a best practice. There is a logical file name that allows you to refer to the file for operations within the database without having to refer back to the full file location including the drive. The logical name does not have to match the physical name at all, but usually they do.
16.在创建数据库是,除了物理位置之外,这两种文件类型中的每个都具有多个属性。物理位置的一部分将是文件名和扩展名。这些都是有效的窗口操作系统名字和扩展。默认情况下扩展通常是用于数据文件的mdf和用于日志文件的idf。如果你愿意,你可以改变这些。但这可能会导致混淆,因为大多是人使用这些错误作为一个最好的锻炼。有一个逻辑文件名称允许你引用该文件的操作当在数据库中不需要引用包括驱动器在内的完整文件位置。逻辑名称不一定要与物理名称匹配,但是通常是这样。
17.Conclusion
That introduces the guts of the file storage for databases. Next post we’re going to actually create a database on the server, which is a heck of a lot easier than this post makes it feel like.
17.结论
这就介绍了数据库文件存储的本质。下一篇文章,我们将在服务器上实际创建一个数据库,这比这篇文章要简单得多。
Share this:
2 Comments
Interesting, but how files are stored into the file system?
Few days ago I imported a .txt file of 200MB size and once imported into SQL Server the size was up to 500MB.
Why this difference?
June 20, 2017 at 4:47 pm
Reply
18.有趣但这些文件是如何储存到文件系统中的呢?几天前我输入了一个200MB的文本文件之前输入到数据库中的大小超过了500MB。为什么不同?
The files on the operating system are just files. Nothing special. As to how your text file went from 200mb to 500mb, without a lot more details, I’m only going to offer some speculation. First up, data types. Let’s say you have CHAR(500) defined (just making stuff up) and the actual data largely only consists of 30-50 characters in length. You’ll have an additional 450 characters stored. Another possible data type issue, let’s say you’re defining NVARCHAR instead of VARCHAR (pretty common). NVCHAR stores twice as much in size as the actual data, so 200mb can easily become 400mb. Also, you’re not talking about whether that data storage is just the data or the data and the log. A transaction can be as large as the data that’s moved through, larger even sometimes. All of that can add up to show more data than is strictly observed just by the size of some text in a text file. There are lots of other possible causes, so don’t get hung up on these examples.
June 21, 2017 at 7:34 am
Reply
OK, fine, but what do you think?
19.操作系统上的文件只是文件没什么特别的。至于您的文本文件如何从200mb到500mb,没有更多的细节,我只会提供一些猜测。首先,数据类型。假设您已经定义了CHAR(500)(只是把数据编出来),实际的数据在很大程度上只包含30-50个字符。您将额外存储450个字符。另一种可能的数据类型问题,假设您定义的是nv替代VARCHAR(相当常见)。NVCHAR存储的大小是实际数据的两倍,因此200mb很容易变成400mb。此外,您并不是在讨论数据存储只是数据,还是数据和日志。事务可以像移动的数据一样大,甚至有时更大。所有这些都可以显示出更多的数据,而不仅仅是文本文件中某些文本的大小。还有很多其他可能的原因,所以不要挂在这些例子上。
2017年6月21日上午7:34
好吧,但是你觉得呢?
摘自https://www.scarydba.com/2017/06/20/database-fundamentals-3-whats-database/
作者:Grant Fritchey, Microsoft Data Platform MVP