Professional Documents
Culture Documents
Studio Express
CCAH
With the release of SQL Server 2005 Express Edition, TI students and professionals
began to have an efficient, professional and cheap solution for creation and
management of SQL databases. However, to the surprise of most, the Express
distribution is not accompanied by any front-end to manipulate the databases and its
objects. This happens because of the fact that all the Visual Studio tools have the
capability to manage the SQL Server from inside of its IDEs.
In order for the database administrators to use SQL Express, Microsoft released a
free tool called SQL Server Management Studio Express. This program, obtained
through download, substitutes the old “Enterprise Manager” and “Query Analyzer” of
SQL Server 2000, now centering all of the database management in a single tool.
In this article you will get acquainted with Management Studio Express and will
learn to create the database of a small library through the resources offered by the
tool. You will also see how to create a Database diagram, insert views and export the
database created.
Relative to the authentication mode, a warning: in case you have installed the SQL
Express along with the installation of an Express Tool or Visual Studio 2005, you will
not have the “sa” user password and will not be able to effect the authentication
through SQL Server Authentication. You will have to use the Windows Authentication
option to gain access to the program. In our example, we will connect using Windows
authentication.
Creating tables
Created the database, we will visualize and add the desired tables, diagrams and
views. To visualize our database’s folders, we will expand the Databases objects and,
after that, Library, through the Object Explorer. Once the database is open, the
following folders’ structure is presented:
We will begin by creating the Books table. To create a table, click the right hand
button over Tables and choose the New Table option. The new table’s data structure
then opens composed of three parts: the Table Designer toolbar, the spread sheet for
creation of the columns and the column’s properties’ box, as in Figure 4.
Figure 4. Creating a table in data structure mode
To insert a field, you must write the name of the column, choose the kind of data
and examine if it will accept null values. After, with the new field selected, you will
be able to set all its properties in the Column Properties box. Amongst the existing
properties, we can highlight the Identity Specification option, where you can
attribute the identity property and set the auto increment of the field, as shown in
Figure 4. To attribute a primary key to a field, just select it and click the Set
Primary Key button located in the Table
Designer toolbar.To finish the creation of the Books table, just click over the “X” in
the right hand side of the table structure window. The Management Studio Express
asks if you wish to save this table and what name should be attributed to this new
object. Once it is saved, the table begins to appear in the list of the Tables folder.
For our example, we will create the tables in accordance with Table 1.
• categoryID – int
Categories
• name – varchar(200)
• publisherID – int
Publishers • name – varchar(200)
• email – varchar(MAX)
• authorID – int
Authors • name – varchar(200)
• email – varchar(MAX)
• bookID – int
• category – int
• publisher – int
Books
• author – int
• title – varchar(200)
• summary – text
Table 1. List of tables to be created in the Management Studio
All the ID fields at the beginning of the tables are primary keys. After they are
created, fill in the tables with three categories, three editors, three authors and 10
books of your choice. To do this, click the right hand button over the table and
choose the Open Table option.
Creating views
View has always been a very useful and very practical feature for the creation of
reports integrating data from the various tables of the database. In our example, we
will create a View for a report of book titles organized by author.
Right-click over Views and choose the New View option. Automatically it will open a
blank diagram and ask to which tables you wish to insert inside the new diagram. For
our example, we will select Books and Authors tables; we click the Add button to add
them and finally the Close button. You will have on your screen the Views setting and
testing window, as Figure 9 shows.
Figure 9. Setting and Views test window
The Views window is divided in four parts: Diagram Panel, Criteria Panel, SQL Panel
and Results Panel. Through these panels you can assemble its views through SQL
language or through mouse selection.
In our report, will be displayed the authors (in alphabetical order), their respective e-
mails and books. For this matter, in Diagram Panel, select the fields name and email
in the Authors table; and the title field in the Books table. Notice that, as you go
along selecting the fields, the Management Studio Express assembles the entire
query in the SQL Panel.
Having done this, select the Execute SQL button in the View Designer toolbar. It
will already show, in the Results Panel, the data of both the tables.
But we are not yet finished: we need to put the name field in alphabetical order. In
the Criteria Panel, go to the Sort Type field of the line of the name column and
choose the Ascending option. When you execute the query, the result will be a listing
by order of author, with their respective e-mails and books.
To finish, go to the Alias column and type “Author Name”, “E-mail” and “Book Title”
on their respective fields (see Figure 10). Alias will make these texts appear at the
heading of the results table, avoiding the user from visualizing the names of the
fields in the report. When finished, your Views window will look like Figure 10. Save
with the name “view_books_author” and close the window.