Translate

Monday, December 7, 2015


What is database normalization?


Normalization is the process of organizing data in a database. This includes creating tables and establishing relationships between those tables according to rules designed both to protect the data and to make the database more flexible by eliminating redundancy and inconsistent dependency.

Redundant data wastes disk space and creates maintenance problems. If data that exists in more than one place must be changed, the data must be changed in exactly the same way in all locations. A customer address change is much easier to implement if that data is stored only in the Customers table and nowhere else in the database.

What is an "inconsistent dependency"? While it is intuitive for a user to look in the Customers table for the address of a particular customer, it may not make sense to look there for the salary of the employee who calls on that customer. The employee's salary is related to, or dependent on, the employee and thus should be moved to the Employees table. Inconsistent dependencies can make data difficult to access because the path to find the data may be missing or broken.

There are a few rules for database normalization. Each rule is called a "normal form." If the first rule is observed, the database is said to be in "first normal form." If the first three rules are observed, the database is considered to be in "third normal form." Although other levels of normalization are possible, third normal form is considered the highest level necessary for most applications.

As with many formal rules and specifications, real world scenarios do not always allow for perfect compliance. In general, normalization requires additional tables and some customers find this cumbersome. If you decide to violate one of the first three rules of normalization, make sure that your application anticipates any problems that could occur, such as redundant data and inconsistent dependencies.

The following descriptions include examples.

First Normal Form

  • Eliminate repeating groups in individual tables.
  • Create a separate table for each set of related data.
  • Identify each set of related data with a primary key.
    Do not use multiple fields in a single table to store similar data. For example, to track an inventory item that may come from two possible sources, an inventory record may contain fields for Vendor Code 1 and Vendor Code 2.

    What happens when you add a third vendor? Adding a field is not the answer; it requires program and table modifications and does not smoothly accommodate a dynamic number of vendors. Instead, place all vendor information in a separate table called Vendors, then link inventory to vendors with an item number key, or vendors to inventory with a vendor code key.
    Second Normal Form

  • Create separate tables for sets of values that apply to multiple records.
  • Relate these tables with a foreign key.
    Records should not depend on anything other than a table's primary key (a compound key, if necessary). For example, consider a customer's address in an accounting system. The address is needed by the Customers table, but also by the Orders, Shipping, Invoices, Accounts Receivable, and Collections tables. Instead of storing the customer's address as a separate entry in each of these tables, store it in one place, either in the Customers table or in a separate Addresses table.
    Third Normal Form

  • Eliminate fields that do not depend on the key.
    Values in a record that are not part of that record's key do not belong in the table. In general, any time the contents of a group of fields may apply to more than a single record in the table, consider placing those fields in a separate table.

    For example, in an Employee Recruitment table, a candidate's university name and address may be included. But you need a complete list of universities for group mailings. If university information is stored in the Candidates table, there is no way to list universities with no current candidates. Create a separate Universities table and link it to the Candidates table with a university code key.

    EXCEPTION: Adhering to the third normal form, while theoretically desirable, is not always practical. If you have a Customers table and you want to eliminate all possible interfield dependencies, you must create separate tables for cities, ZIP codes, sales representatives, customer classes, and any other factor that may be duplicated in multiple records. In theory, normalization is worth pursing. However, many small tables may degrade performance or exceed open file and memory capacities.

    It may be more feasible to apply third normal form only to data that changes frequently. If some dependent fields remain, design your application to require the user to verify all related fields when any one is changed.
    Other Normalization Forms
    Fourth normal form, also called Boyce Codd Normal Form (BCNF), and fifth normal form do exist, but are rarely considered in practical design. Disregarding these rules may result in less than perfect database design, but should not affect functionality.
    Normalizing an Example Table
    These steps demonstrate the process of normalizing a fictitious student table.

1.    Unnormalized table:

Student#
Advisor
Adv-Room
Class1
Class2
Class3
1022
Jones
412
101-07
143-01
159-02
4123
Smith
216
201-01
211-02
214-01

2.    First Normal Form: No Repeating Groups

Tables should have only two dimensions. Since one student has several classes, these classes should be listed in a separate table. Fields Class1, Class2, and Class3 in the above records are indications of design trouble.

Spreadsheets often use the third dimension, but tables should not. Another way to look at this problem is with a one-to-many relationship, do not put the one side and the many side in the same table. Instead, create another table in first normal form by eliminating the repeating group (Class#), as shown below:

Student#
Advisor
Adv-Room
Class#
1022
Jones
412
101-07
1022
Jones
412
143-01
1022
Jones
412
159-02
4123
Smith
216
201-01
4123
Smith
216
211-02
4123
Smith
216
214-01

3.    Second Normal Form: Eliminate Redundant Data

Note the multiple Class# values for each Student# value in the above table. Class# is not functionally dependent on Student# (primary key), so this relationship is not in second normal form.

The following two tables demonstrate second normal form:

Students:

Student#
Advisor
Adv-Room
1022
Jones
412
4123
Smith
216

4.   

Registration:

Student#
Class#
1022
101-07
1022
143-01
1022
159-02
4123
201-01
4123
211-02
4123
214-01

5.    Third Normal Form: Eliminate Data Not Dependent On Key

In the last example, Adv-Room (the advisor's office number) is functionally dependent on the Advisor attribute. The solution is to move that attribute from the Students table to the Faculty table, as shown below:

Students:

Student#
Advisor
1022
Jones
4123
Smith

6.   

Faculty:

Name
Room
Dept
Jones
412
42
Smith
216
42


Sunday, January 5, 2014

Changing the Environment Layout,

SQL Server 2008 R2
13 out of 14 rated this helpful Rate this topic
The components of SQL Server Management Studio compete for screen space. To make more room, you can close, hide, or move Management Studio components. The practices on this page move the components to different locations.

To practice closing, hiding, and reopening component windows

  1. Hide Registered Servers by clicking the x in the upper right corner of Registered Servers. Registered Servers closes.
  2. In Object Explorer, click the push-pin button with the Auto Hide ToolTip. Object Explorer is minimized to the left side of the screen.
  3. Move your mouse over the Object Explorer title bar. It reopens.
  4. Click the push-pin again to pin Object Explorer in the open position.
  5. On the View menu, click Registered Servers to restore Registered Servers.
The environment that hosts Management Studio allows you to move components and dock them in a variety of configurations.

To practice moving components

  1. Click and drag the title bar of Registered Servers into the middle of the document window. The component undocks and remains floating until you drop it.
  2. Drag Registered Servers around to different locations on the screen. In several areas of the screen, you receive blue docking information. The arrows indicate that dropping the component in that location causes the window to dock to the top, bottom, or side of the frame. Moving the component into the arrow causes the underlying screen to darken in the target location. The center circle indicates that the component shares the space with other components. When dropped in the center, the available components appears as tabs within the frame.
You can customize the presentation of the Management Studio components.

To dock and undock components

  1. Right-click the title bar of Object Explorer and note the following menu options:
    • Floating
    • Dockable (checked)
    • Tabbed Document
    • Auto Hide
    • Hide
    These options are also available from the Window menu, or from the down arrow on the toolbar.
  2. Double-click the title bar of Object Explorer to undock it.
  3. Double-click the title bar again to dock Object Explorer.
  4. Click and drag the title bar of Object Explorer to the right border of Management Studio. When the gray outline box appears the entire height of the window, drop Object Explorer to its new location on the right side of Management Studio.
  5. Object Explorer can also be moved to the top or bottom of Management Studio. Drag and drop Object Explorer back to its original position on the left side.
  6. Right-click the title bar of Object Explorer, and then click Hide.
  7. On the View menu, click Object Explorer to restore the window.
  8. Right-click the title bar of Object Explorer, and then click Floating to undock Object Explorer.
  9. To restore the default configuration, on the Window menu, click Reset Window Layout.

Connecting with Registered Servers and Object Explorer,

SQL Server 2008 R2

4 out of 15 rated this helpful Rate this topic
Registered Servers and Object Explorer are similar to Enterprise Manager in Microsoft SQL Server 2000, but they have additional capabilities.
This tutorial uses the AdventureWorks2008R2 database. To help enhance security, by default, the sample databases are not installed. For more information, see Considerations for Installing SQL Server Samples and Sample Databases.
The toolbar of the Registered Servers component has buttons for the Database Engine, Analysis Services, Reporting Services, SQL Server Compact 3.5 SP2, and Integration Services. You can register one or more of these server types for convenient management. Try the following exercise to register the AdventureWorks2008R2 database.

To register the database

  1. On the Registered Servers toolbar, click Database Engine if you have to. (It may already be selected.)
  2. Expand Database Engine.
  3. Right-click Local Server Groups, and then click New Server Registration.
  4. In the New Server Registration dialog box, in the Server name text box, type the name of your instance of SQL Server.
  5. In the Registered server name box, type AdventureWorks2008R2.
  6. On the Connection Properties tab, in the Connect to database list, select <Browse server…>.
  7. In the Browse for Databases dialog box, click Yes.
  8. In the Browse Server for Database dialog box, select AdventureWorks2008R2, and then click OK.
  9. In the New Server Registration dialog box, click Save.
Like Registered Servers, Object Explorer can connect to the Database Engine, Analysis Services, Integration Services, Reporting Services, and SQL Server Compact 3.5 SP2.

To connect with Object Explorer

  1. On the toolbar of Object Explorer, click Connect for a list of possible connection types, and then select Database Engine.
  2. In the Connect to Server dialog box, in the Server name text box, type the name of your instance of SQL Server.
  3. Click Options and explore the choices.
  4. To connect to the server, click Connect. If you are already connected, this action just returns you to Object Explorer and sets the focus on that server.
    When you connect to an instance of SQL Server, Object Explorer presents information that looks and functions very much like the Console Root in SQL Server 2000 Enterprise Manager. Enhancements include greater scalability when exploring thousands of database objects. With Object Explorer you can administer SQL Server Security, SQL Server Agent, Replication, and Database Mail. Object Explorer can only manage some of the features of Analysis Services, Reporting Services, and SSIS. Each of those components has additional specialized tools.
  5. In Object Explorer, expand the Databases folder and select AdventureWorks2008R2.
    Notice that SQL Server Management Studio presents the system databases in a separate folder.

Starting SQL Server Management Studio

SQL Server 2008 R2

42 out of 72 rated this helpful Rate this topic
To begin this tutorial, let's take a look at SQL Server Management Studio.

To open SQL Server Management Studio

  1. On the Start menu, point to All Programs, point to Microsoft SQL Server 2008 R2, and then click SQL Server Management Studio.
    NoteNote
    SQL Server Management Studio is not installed by default. If Management Studio is unavailable, install it by running Setup. Management Studio is not available with SQL Server Express. Management Studio Express is available as a free download from the Microsoft Download Center.
  2. In the Connect to Server dialog box, verify the default settings, and then click Connect. To connect, the Server name box must contain the name of the computer where SQL Server is installed. If the Database Engine is a named instance, the Server name box should also contain the instance name in the format <computer_name>\<instance_name>.

Management Studio presents information in windows dedicated to specific types of information. Database information is shown in Object Explorer and document windows.
  • Object Explorer is a tree view of all the database objects in a server. This can include the databases of the SQL Server Database Engine, Analysis Services, Reporting Services, Integration Services, and SQL Server Compact 3.5 SP2. Object Explorer includes information for all servers to which it is connected. When you open Management Studio, you are prompted to connect Object Explorer to the settings that were last used. You can double-click any server in the Registered Servers component to connect to it, but you do not have to register a server to connect.
  • The document window is the largest portion of Management Studio. The document windows can contain query editors and browser windows. By default, the Summary page is displayed, connected to the instance of Database Engine on the current computer.

Users familiar with the SQL Server Enterprise Manager of SQL Server 2000 may wish to show the Registered Servers window.

To show the Registered Servers window

  1. On the View menu, click Registered Servers.
    The Registered Servers window appears above Object Explorer. Registered Servers lists servers which you manage frequently. You can add and remove servers from this list. If SQL Server 2000 Enterprise Manager was previously installed on this computer, you will be prompted to import the list of registered servers. Otherwise, the only servers listed are the SQL Server instances on the computer where you are running Management Studio.
  2. If your server does not appear, in Registered Servers, right-click Database Engine, and then click Update Local Server Registration.

Saturday, January 4, 2014

SQL Server Management Studio

 

SQL Server 2008 R2
26 out of 48 rated this helpful Rate this topic
Welcome to the SQL Server Management Studio tutorial. Hosted inside Microsoft Visual Studio, Management Studio brings graphical tools for database management together with a rich development environment. Management Studio enables you to access and manage the Database Engine, Analysis Manager, and SQL Query Analyzer in one tool, together with the ability to write Transact-SQL, MDX, XMLA, and XML statements.
This tutorial will help you understand the presentation of information in Management Studio and how to take advantage of the features.

The best way to get acquainted with Management Studio is through hands-on practice. This tutorial will teach you how to manage the components of Management Studio and how to find the features that you use regularly.
This tutorial is divided into four lessons:
Lesson 1: Basic Navigation in SQL Server Management Studio
In this lesson you will learn how to use the components of Management Studio, how to reconfigure the environment layout, and how to restore the default layout.
Lesson 2: Writing Transact-SQL
In this lesson, you will learn how to open Query Editor, how to manage code, and how to use the other new features of Query Editor.
Lesson 3: Using Help
In this lesson you will learn how the new Help system functions, several ways to access Help, and how to manage the Help windows.
Lesson 4: Working with Templates, Solutions, Script Projects, and Source Control
In this lesson you will learn how to use templates, manage solutions and script projects, and use Management Studio to integrate solutions with Microsoft Visual SourceSafe.

This tutorial is intended for users who are not familiar with Visual Studio, but who are experienced database administrators and Transact-SQL developers who are familiar with database concepts and the Transact-SQL language. It is helpful to be familiar with the SQL Server 2000 tools.
Your system must have the following installed to use this tutorial:
Visual SourceSafe for portions of Lesson 4.

Lesson 1: Basic Navigation in SQL Server Management Studio

SQL Server 2008 R2
72 out of 97 rated this helpful Rate this topic
Microsoft SQL Server Management Studio is a powerful and flexible tool. However, users new to Microsoft Visual Studio sometimes have trouble finding the quickest way to access the right feature. This lesson shows you how the windows work together to present a design surface that makes your work easier. At the end of this lesson, you will know how to clear unwanted windows out of your way, how to quickly bring up windows with the information you need, and how to configure the default surface to support the work you do most often.
This lesson contains the following topics:
  • Starting SQL Server Management Studio
  • Connecting with Registered Servers and Object Explorer
  • Changing the Environment Layout
  • Displaying the Document Window
  • Showing the Object Explorer Details page
  • Selecting the Keyboard Shortcut Scheme
  • Setting the Startup Options
  • Restoring the Default SQL Server Management Studio Configuration
  • Summary