Friday 7 January 2011

What is a Device in SQL?


What Is A Device?

The terms device and database are often confused. The basic storage container for Microsoft SQL Server is a device, which is an operating system file that resides on the physical disk, or hard drive, of the server. A device is the container that allocates space to Microsoft SQL Server on the server’s hard drive. Microsoft SQL Server does not acquire disk space on the server dynamically. You must specify the amount of disk to set aside for it to use. This allocation is accomplished through the device. 

The space that you set aside for devices is essentially lost to the rest of the machine. A device cannot be made smaller. You can, however, expand a device to make more room for your databases to grow—provided you have enough free disk space. You can—and will—have multiple devices on your server. Databases can span multiple devices to accommodate their growth. A device carries with it a file extension of .DAT. This is important to know if you are in a multiple-programmer environment and are using the data server for file services as well as data services. For example, in File Manager or Windows NT Explorer, note the physical file C:\MSSQL\Data\master.dat. You can highlight this file, hit the Delete key, and if it is not currently being used by Microsoft SQL Server, it will be deleted like any other file. If it is in use, Microsoft SQL Server and the operating system will not allow it to be deleted.

This prevents an accidental delete. The only acceptable way to recover the space given to a device is to drop the device and re-create it with a smaller size. When you drop a device, ensure that you go to the file system and delete the physical file. If you do not remove the device file, you will receive an error message when you re-create the device with the same name. Once you remove the file, you use the Enterprise Manager to re-create the device with a smaller size. You can then restore any contents of the old device to the new device, provided all the objects fit in the new space.

Try to avoid creating one big device that takes up the whole hard drive. Doing so will not give you the flexibility you need from the server. You will be very limited in your options down the road and will have to jump through some fairly complicated hoops to change this configuration on a production machine.

From a slightly different perspective, a device can be thought of as a large, empty office. This space is rented or leased by your company. If your business expands beyond the square footage you have set aside, you must acquire more office space to accommodate the growth. This can be achieved by expanding the existing office into adjoining space in the same building or perhaps in another office building altogether.

This growth scenario applies to your devices as well. I will use this and other analogies a lot throughout this book to help you associate Microsoft SQL Server to a real-world example. Many of my students have found they frequently do not remember the exact piece of information they need but can draw on these analogies to figure out what to do.

No comments:

Post a Comment