You are on page 1of 10




forqot mv oassword

sign up!







Publish your post

Mr.Bool Credits

Buy Credits

This post is part of: Online course(s): • Administration of Microsoft SQL Server


add to favorites

Creating databases using SQL Server Management Studio Express
Learn how to create databases using SQL Server Management Studio Express

"Have You EveI'"


Earnit'l.9 At'I.
Extl'"il .1=:1....000 per .I¥.ot'"
MUYla Khan,

.2 q gY"S old. iFO.REX PersoYl<l/
HERLESON PAIVA PONTES(ENGUSH) Herleson Paiva Pontes ( is Microsoft


Creating databases using SQL Server Management Studio Express
Herleson Paiva Pontes 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 adlTinistrators 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 leam to create the database of a small library through the resources offered by the tool. You will also see how to create Database diagram, insert views and export the database Download and installation of the manager created.


To obtain the SQL Server Management Studio Express, just download directly from Microsoft's site at the Having done this, sirTllly install the software. After its installation, a program shortcut is created in the Start menu of Windows, inside the Microsoft SQL Server 2005 folder. Gaining access to SQL Server 2005 Express

When you open Management StudiO Express, a connection window with SQL Server will be opened, as Figure 1 shows. In this window, you will enter the data for connection with SQL Express existent in your machine. A detail to be observed is that you can, through the Management StudiO, connect to a server SQL Server which is in another machine in the net. Just click in the Server name box and choose the Browser for more option to search for the other server. In our exarrple, we will connect to the existing SQLEXPRESS instance in the machine itself (that, in this case, has the name PND).

I!'J Connect

to Server


SQL Servetzoos
Server lYpe:



.2 erver



). Toolbar.e1'i I B> [ill ~ ~ ~ " . especially the Databases folder.R~"«I~5eil . In our example. SQL Server Management Studio Express Work Area Through the Object Explorer box we can navigate among all of the SQL Server parts. you will not have the "sa" user password and will not be able to effect the authentication through SQL Server Authentication.------------------------- ~ on"". This window possesses the following areas: Menu Bar. Figure 2. tIo~":""'!""'~!. as: Compatibility level. where you insert the name. Connection Cancel II'------'-------' II Help Qpliom» Studio Express window of the SQL Management Relative to the authentication mode.~11 Figure 1. . In order to create a new database.."""""'~ . a waming: in case you have installed the SQL Express along with the installation of an Express Tool or Visual Studio 2005. click the OK button to finish our database . where you decide if the database created will be read-only. as you can verify in Figure 3. the work area of Management Studio Express is then presented. it is enough to right-click over the Databases folder and choose the New Database option.6uthentlcatlon: User name: Eassword: ~D\6. After perforlTing all the actions. Database Read-Only. as Figure 2 shows..Q1jrw~ Qj ~ iI " . In our example.. and Restrict Access. choose the owner and configure the initial size of the data and log files. Object Explorer and Active Files.1399· c.0. where you choose with which version of the SQL Server the new database will be compatible.) PND\SQUEXPRESS (SQL Server 9.dministrator D Remember password lu. we will connect using Windows authentication. where the created databases and their objects are contained (tables. where you set the database creation. views etc. You will have to use the Windows Authentication option to gain access to the program. you will be able to set some of the new database'sadvanced options. access restrictions. In the Options page. The window for the creation of the database is then opened.we call our new database "Library" and leave the initial data file size at 3 MB. Management Studio Work Area After connected.

To create a table. as in Figure 4. programming: stored procedures. place where you set all of the database's · Security: in this last item. through the Object Explorer. you set all the security Certificates. B~'OpeJ~. the spread sheet for creation of the columns and the column's properties' box.!DJ 1 Ie..dbo. ~~_b) 'f!!'JW>' 'Do<o Log Ii IMIlSil..i. Library. /T able .. "". 1 Me. the following folders' structure is presented: · Database Diagrams: the entity-relationship diagrams are stored in this location. diagrams and views.Booka] Name Column I ~II bookID Data Type int int int int varchar(200) text category publisher author title summary D D D D D 0 D Column Properties No Yes Yes Yes .«. Once the database is open. after that. · Views: here stay all the views that have been created.(... the Books table. click the right hand button over Tables and choose the New Table option. Figure Creating 3. The new table's data structure then opens composed of three parts: the Table Designer toolbar... To visualize our database's folders.! ~1<~~~r~~ ~~ PRIWoif'( NoI~ ~I[J ~""" [ ~N"'" L.. we will expand the Databases objects and. such as Users. etc. function.[u. """. We will begin by creating parameters. Schemes. · Programmability: rules etc.~'~ . The "New Database" tables Window Created the database... we will visualize and add the desired tables. · Synonyms: directory of the synonymous that have been created.. · Tables: folder where the database tables are.

int Books author . the table begins to appear in the list of the Tables folder. as Figure 5 shows. Creating entity-relationship diagrams Management Studio's resources is the creation of entity-relationship of the One of the most interesting diagrams (the database diagrams). choose the kind of data and examine if it will accept null values. Table Name COlumns and Data Types categoryID .varchar(200) email .int title . besides favoring the visualization tables and their relations. click the right hand button over the table and choose the Open Table option. After. For our example. With all of the tables created. we will select all the tables available. To do so.III Identity Specification Figure 4. we can highlight the Identity Specification option. with the new field selected. To attribute a primary I) key to a field. Once it is saved. fill in the tables with three categories. After they are Authors name . Add button to add them and then the Close button. you will be able to set all its properties in the Column Properties box. three authors and 10 books of your choice. In your screen you will have all the tables .varchar{MAX) authorID . List of tables to be created in the Management Studio All the ID fields at the beginning of the tables are primary keys.varchar(200) email . For our example. where you can attribute the identity property and set the auto increment of the field. we will create the tables in accordance with Table 1.text Table 1.varchar(MAX) bookID . To finish the creation of the Books category . The Management Studio Express asks if you wish to save this table and what name should be attributed to this new object. allow the user to understand the whole database. Automatically.varchar(200) publisherID . and their respective fields. These diagrams.varchar(200) summary . all the necessary Diagram we will now add a database diagram to our database and create Diagrams and choose the New relations. Amongst the existing properties. just click over the "X" in the right hand side of the table structure window. just select it and click the Set Primary Key button located in the Table Designer Publishers name .int Categories name . it will open a blank diagram and ask which tables you wish to clicking the insert in the new diagram. Creating a table in data structure mode To insert a field. To do publisher . right click over Database option. as shown in Figure 4. three editors. you must write the name of the column.

description. such as: name of the relation. a new with the name FK_Books_Books. Clicking the Add button. Window with the Entity-Relation Diagram In case it is the first time you are using the database diagram resource in Management Studio Express. ITl~ I FK_Books_Authors . the relations' definitions. The 'Tables And Columns Specification' property needs to be filled in before the new relationship willbe accepted. the Books table) and click the Relations relation is created button ~ located in the Database Diagram toolbar. we will now create a relation between the Authors and Books tables. according to Figure 6. EI Database Designer Enforce For Replication I±l INSERT And UPDATE Specific El Yes Enforce Foreign Key Constre Yes _ _ - Identity (Name) FK_Books_Books ~criPtion - '----=----' add II !i. Foreign Key Relationships ~~ :2_elected Relationship: FK_Books_Books* Editing properties for new relationship. In our example.Books I! bookID category publisher author title summary Publishers I! publisherID name email Categories I! categoryID name Authors I! authorID name email Figure 5. Tables and Columns Relationship o. click the Tables and Columns Specifications property and then the 0 button. the tables that are part of the relation and the respective To edit fields. Just click Yes so that these files are installed. you will be able to set all the properties of the new relation. select the table that contains the foreign key (in our case. The box where you will determine as Figure 7 shows.elete Figure 6. you will be asked to install some files necessary to the proper functioning of the diagrams module. Relations' Window In this window. El j~~~~~~ij: Check Existing Data On Cree Yes I±I Tables And Columns Specific.ame: which tables and fields will take part in the relation is opened. To add a relation between two tables. referential integrity rules.

After. For our example. Automatically it will open a blank diagram and ask to which tables you wish to insert inside the new diagram. we will select Books and Authors tables. all the work belonging to this author will be removed from the table Books.0011 Figure 7. and not the one that contained the primary key. Diagram after the creation of all the relations table primary key. for the creation of reports integrating In our example. In our example.t~'JI' ~ """" "" Figure 8. choose the author field and confirm the new relation clicking over the OK button. With this. save the diagram with the name "Library Diagram" and close the window. in the Delete Rule field. we will create a View for a report of book Right-click over Views and choose the New View option. After that. Create the other relationships so that we have the same diagram as the one in Figure 8. Modify the Primary key table field for the Authors table and. we create the first relation. we will choose. Determining the tables and fields in the relation Cancel Notice that the Foreign key table field for table choice is disabled. this assures that. When you expand.. This is the reason because of which you selected the table with the foreign key to start the relationship window. making the alteration impossible. when removing an author. choose the authorID field.U> . Creating views feature View has always been a very useful and very practical data from the various tables of the database. Tip: You can select a field in the table and drag it until the referenced to visually set the relation. the Cascade option. after that. You will have on your screen the Views setting and testing window. the relationship is created. in the Books table. 1 bo>i. In case it is necessary to set the referential integrity in the relationship. you will be able to choose the relation's rules of update and delete. .:. titles organized by author. With this. as Figure 9 shows. we click the Add button to add them and finally the Close button. just open the window of relations and expand the INSERT and UPDATE Specification option.

sql) archive. Notice that. In the Criteria Panel. But we are not yet finished: we need to put the name field in alphabetical order. Exporting after field selection and setup the database it to a SQL Server. choose the Library After creating the database in your machine.euthorju dbo. After selected.euchor Figure 9. their respective e-mails and books. Setting and Views test window The Views window is divided in four parts: Diagram Panel.Books ON dbo. Criteria Panel. select the Execute in the SQL Panel. Through these panels you can assemble its views through SQL language or through mouse selection. Click with the right hand button over Library. In our report.I Column I Alias I Table I Output IFill~ ~ ~ ~ ~ SELECT FROM dbo. Figure 10.Authors. as Figure 11 shows. When you execute the query. the data of both the tables. select the fields name and email in the Authors table. and the title field in the Books table. Click Next and database. SQL Panel and Results Panel. go to the Alias column and type "Author Name". mark the Script button. When finished. SQL button t in the View Designer toolbar. avoiding the user from visualizing the names of the fields in the report. will be displayed the authors (in alphabetical order). We will show you here the exportation of the a Script (* . there might be the necessity to export or to generate a backup for later use.Books. Alias will make these texts appear at the heading of the results table. To finish. Views window. It will already show. Library database to Generate Scripts. all objects in the selected database option and click the Finish . the Management Studio Express assembles the entire query Having done this.Authors INNER JOIN = ~ dbo. in the Results Panel. go to the Sort Type field of the line of the name column and choose the Ascending option. For this matter. in Diagram Panel. the result will be a listing by order of author. "E-mail" and "Book Title" on their respective fields (see Figure 10). your Views window will look like Figure 10. Go to Task> The Management Studio will show a wizard for the script generation. with their respective e-mails and books. as you go along selecting the fields. Save with the name "view_books_author" and close the window.

3 Digg Reddit DZone Email ShareThis Uke Add a comment! tony 10/27/"lIXJl7:28pm good good article! Answer it cd 12/8/2IXIl9:41pm Mgm: Studio Express Thank you! very informative Answer it Stu 12/18/"lIXJl6:3Opm great tutorial Have been searching for a tutDrial like this. great work! Answer it johnnyxp64 5/12/2000 4:57am sill1Jly great . with/vstudio/express/sql. database diagrams and views). just go to File> save..sql file for the purpose of backup or of transference to a SQL Server. To save this script. choose the folder and name the file._2elect a database: master model msdb tempdb lielp Figure 11. a window with the entire script of the generated database is opened. Conclusion The Management Studio Express is a Microsoft SQL Server free management tool which makes developers' and DBAs day to day easier..Microsoft. In this article we saw the visual interface of this tool and show how to create some resources that are present in the entire database (tables. We finished the article showing how to export our just-created database to an * . You can find more information on the SQL Server Express and the Management Studio Express at the address ffrTP://msdn. easy simply great & easy Answer it Richard de Fortune A/1Q/'XVlR7'A::am Thanks so IRIch . Scripts <_Il_ack IIIT~II Einish»1 II Cancel generation assistant After executing the processing on behalf of the Management Studio.

Answer it suryabeniwal 11/12/2rnJ 11: 19am Sql Table Relation Great job dear thanks .. Answer it [List aliI Creating databases using SQL Server Management 5bJdio Express . good luck . But.. That's worth any human teacher. net Answer it Rickard 4/'l2/2WJ l1:29am VERY GOOD Thank you a bunch. I built a database that's being used to store software testing data... and I just wanted to say that it helped me a lot.! Answer it julien 6/9/2rnJ 9: 31am grSjob I really liked the article. keep on the good work! Answer it AMEET 7/12/2WJ 5:45am NlCEl nICE aRTICLE Answer it MikeG 10/23/2rnJ 6:42pm Nee Tutorial This simple tutorial really helped me get started . now what comes next? We'll be waiting Answer it Erni 9/7/2008 3: 24pm IT OK:) Answer it Erni 9/7/2008 3: 24pm IT OK:) Answer it kiny 9/9/2008 12: teem 111anlcs Thank you!!! really helpful Answer it gyanesh joshi 11/20/2008 8:50am data base it is good article but need to tell that how use in ado.Thanks.

all rights reserved to www.web-03.Help us to i~rove! Qve us your feedback: Giveyour note to the technical content ("10 ("9 ("8 ("7 ("6 ("5 ("4 ("3 ("2 ("1 Giveyour note to the post's learning Is this post helpful? Send Feedback ("10 ("9 ("8 ("7 ("6 ("5 ("4 ("3 ("2 ("1 ("Yes ("No .com contact us I publish your post I buy credits Copyright 2012 .