Download MS SQL SERVER 2005 / 2008 – Management Studio

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

IMDb wikipedia , lookup

DBase wikipedia , lookup

Relational algebra wikipedia , lookup

Tandem Computers wikipedia , lookup

Oracle Database wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Microsoft Access wikipedia , lookup

Concurrency control wikipedia , lookup

Database wikipedia , lookup

Btrieve wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Ingres (database) wikipedia , lookup

Open Database Connectivity wikipedia , lookup

ContactPoint wikipedia , lookup

Clusterpoint wikipedia , lookup

Relational model wikipedia , lookup

SQL wikipedia , lookup

Database model wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

PL/SQL wikipedia , lookup

Transcript
Chapter 4:
MS SQL SERVER 2008
Creating Database via TABLES
MS SQL SERVER 2005 / 2008 – Management Studio (MS)
1. Create Database via Tables
Create Database via table generation using Unispares example.
Creating the tables and generate an Entity-Relationship Diagram within SQL Server EM
environment.
At UoT jump to part d) as at the UoT you do NOT have admin rights to create DATABASES
but do have the rights to create tables.
a. Run SQL Server 2005 / 2008 – Manager Studio and expand the Databases tag. Right
click in the summary dialogue box to create a new database.
b. Type in the name of the database you want to create. The example shows the creation
of a new database called UNISPARES. Type in unispares and click ok.
Mansha Nawaz
MS SQL SERVER 2005 / 2008 – Creating Database via Tables
Chapter 4:
1
Chapter 4:
c.
MS SQL SERVER 2008
Creating Database via TABLES
Note the database UNISPARES is added to the SQL Server database list. Double click
unispares in the summary dialogue box..
d. Note the standard option for all databases.
Mansha Nawaz
Double click tables.
MS SQL SERVER 2005 / 2008 – Creating Database via Tables
Chapter 4:
2
Chapter 4:
MS SQL SERVER 2008
Creating Database via TABLES
e. Right click to create a new table.
f.
Note the table field grid … similar to MS Access.
Mansha Nawaz
MS SQL SERVER 2005 / 2008 – Creating Database via Tables
Chapter 4:
3
Chapter 4:
MS SQL SERVER 2008
Creating Database via TABLES
g. An ERD for the following purchase order has been produced (see next page for ERD)
CASE STUDY 1 :
UNISPARES PURCHASE ORDERS
Unispares is a retailer of computer equipment. Unispares use a standard Purchase Order
Form when buying goods from its suppliers.
FIGURE (a) SAMPLE PURCHASE ORDER (PO) FORM
UNISPARES
PURCHASE ORDER (PO) FORM
Unispares Computer Ltd, 99 Borough Rd, Middlesbrough, TS1 3BA
tel: 01642-123456 fax: 01642-654321
PO No. 002594
Supplier#
Supplier Name:
Supplier Address:
PO Date: 15.12.96
3451
SELWOOD CONSULTANCY LTD
KINGSDAEL HOUSE
MARINTET ROAD
THORNABY
CLEVELAND
TS17 0BB
PO DETAILS :
PART
CPU012
PRI6214
MON023
CON061
CPU015
KEY031
CPU072
PART DESCRIPTION
Pentium 100 16/1000
HP Deskjet 660C
Philips 14" Colour Monitor
HP Deskjet 660C Cartridge
Pentium 166 32/2000 CD
Extended Keyboard
Pentium 120 16/1000
COST£
175.00
125.00
45.00
20.00
700.00
6.00
400.00
QTY
2
3
1
4
1
10
2
Payment Terms : COD/7days/30days/45days
In case of queries, please staff# 012 staff-name : FRED BLOGGS ext. 321
Mansha Nawaz
MS SQL SERVER 2005 / 2008 – Creating Database via Tables
Chapter 4:
4
Chapter 4:
MS SQL SERVER 2008
Creating Database via TABLES
Implement the tables from the following Unispares ERD in MS SQL Server.
Purchase Order (PO) comprises of data from the following 5 tables – this process is
covered in the lecture notes on ERD 07 to 11.
PURCHASE-ORDERS ( @po#, odate, s#, pt#, ct# )
SUPPLIERS ( @s#, sname, saddress, …….)
PARTS ( @p#, pdesc, …..)
PO-PARTS ( po#, p#, qty )
PAYMENT-TERMS ( @pt#, ptdesc )
CONTACT ( @ct#, cname, cext )
h. To create the table PO (purchase orders) enter the following fields into the grid and then
click on file save Table_1
Mansha Nawaz
MS SQL SERVER 2005 / 2008 – Creating Database via Tables
Chapter 4:
5
Chapter 4:
MS SQL SERVER 2008
i.
Replace the name Table_1 with PO and click ok.
j.
Note the new table PO.
Mansha Nawaz
Creating Database via TABLES
MS SQL SERVER 2005 / 2008 – Creating Database via Tables
Chapter 4:
6
Chapter 4:
k.
MS SQL SERVER 2008
Creating Database via TABLES
Repeat the procedure until you have all the following Unispares tables created.
PURCHASE-ORDERS ( @po#, odate, s#, pt#, ct# )
SUPPLIERS ( @s#, sname, saddress, …….)
PARTS ( @p#, pdesc, …..)
PO-PARTS ( po#, p#, qty )
PAYMENT-TERMS ( @pt#, ptdesc )
CONTACT ( @ct#, cname, cext )
Mansha Nawaz
MS SQL SERVER 2005 / 2008 – Creating Database via Tables
Chapter 4:
7
Chapter 4:
Mansha Nawaz
MS SQL SERVER 2008
Creating Database via TABLES
MS SQL SERVER 2005 / 2008 – Creating Database via Tables
Chapter 4:
8
Chapter 4:
l.
MS SQL SERVER 2008
Creating Database via TABLES
Note the llist of new tables created. Also note the options available when you right click
on any of the table names. The Modify and Open Table work similar to MS Access.
m. Under the Unispares database either click Database Diagrams or right click and choose
new database diagram.
Mansha Nawaz
MS SQL SERVER 2005 / 2008 – Creating Database via Tables
Chapter 4:
9
Chapter 4:
MS SQL SERVER 2008
Creating Database via TABLES
n. Note you are now able to develop your ERD (data model) within this environment. Click
on YES.
o. Choose all the tables you want to add to your diagram.
p. Arrange the tables as follows
Mansha Nawaz
MS SQL SERVER 2005 / 2008 – Creating Database via Tables
Chapter 4:
10
Chapter 4:
MS SQL SERVER 2008
Creating Database via TABLES
q. Note the options available when right clicking on a table. Change the Table View to
Standard and change the table: payment terms field: pt# to nchar(10).
r.
Allocate the keys by clicking on the appropriate primary key field(s) and clicking the
Mansha Nawaz
MS SQL SERVER 2005 / 2008 – Creating Database via Tables
Chapter 4:
11
Chapter 4:
s.
MS SQL SERVER 2008
Creating Database via TABLES
You may now drag and drop the keys to implement the relationships (similar to MS
Access). You are also able to right click and add new tables or amend existing tables if
you need to. Any changes done in the diagram section are reflected in the tables.
The following screen is displayed when the pt# from the table: payment-terms is dragged
over the pt# from the table: PO.
Also note the integrity between the relationship. Go with the default settings.
Mansha Nawaz
MS SQL SERVER 2005 / 2008 – Creating Database via Tables
Chapter 4:
12
Chapter 4:
t.
MS SQL SERVER 2008
Creating Database via TABLES
The following screen demonstrates the linkage between all tables.
u. You can use the diagram to adjust the tables/columns/data-types via the diagrams. Note
to avoid the following error Save changes not permitted you will need to change one
of the option settings as indicate below:
Fix: http://msdn.microsoft.com/en-us/library/bb895146.aspx
Save (Not Permitted) Dialog Box
The Save (Not Permitted) dialog box warns you that saving changes is not permitted because the
changes you have made require the listed tables to be dropped and re-created.
The following actions might require a table to be re-created:

Adding a new column to the middle of the table

Dropping a column

Changing column nullability

Changing the order of the columns

Changing the data type of a column
To allow saves to be permitted change the following option, on the Tools menu, click Options,
expand Designers, and then click Table and Database Designers. Select or clear the Prevent
saving changes that require the table to be re-created check box.
Mansha Nawaz
MS SQL SERVER 2005 / 2008 – Creating Database via Tables
Chapter 4:
13
Chapter 4:
v.
MS SQL SERVER 2008
Creating Database via TABLES
Click on File Save and name the diagram UNISPARES ERD
w. Note how SQL asks if you wish to update the live tables. Click yes.
x.
Note the tables and diagram created.
Mansha Nawaz
MS SQL SERVER 2005 / 2008 – Creating Database via Tables
Chapter 4:
14
Chapter 4:
MS SQL SERVER 2008
Creating Database via TABLES
y. You may wish to tackles the CASE STUDY relating to UniSpares. The unispares
case study is also online under the case study list.
z.
You may also consider implementing any of the Library
Mansha Nawaz
of Free Data Models
MS SQL SERVER 2005 / 2008 – Creating Database via Tables
Chapter 4:
15