Download Create and Access Databases

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

DBase wikipedia , lookup

Serializability wikipedia , lookup

IMDb wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Oracle Database wikipedia , lookup

Functional Database Model wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Microsoft Access wikipedia , lookup

Btrieve wikipedia , lookup

Concurrency control wikipedia , lookup

Ingres (database) wikipedia , lookup

Database wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

SQL wikipedia , lookup

ContactPoint wikipedia , lookup

Clusterpoint wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Relational model wikipedia , lookup

PL/SQL wikipedia , lookup

Database model wikipedia , lookup

Transcript
SQL 71 0 LAB 4
CREATE AND ACCESS DATABASES
1: Use Online Books
Objective: In this exercise you’ll be investigating information about databases available on Online
Books.
1. Start  Programs Microsoft SQL Server Books Online
2. Select Index tab and type in system and double click on system databases
3. Double click on System and Sample Databases and note the database file name and transaction
log file name of:
 master:

tempdb:

model:

msdb:
4. Double click on system databases again and then double click on System Databases and Data
and note the purpose of:
 master:

tempdb:

model:

msdb:
5. Type in master in the index search and in master database double click on Information Stored
in System Tables. Then double click on System Tables and double click on sysfiles. Note the
purpose of each of the following columns:
 Maxsize

Growth

Status
6. Now press Back  toolbar button and double click on sysobjects. Note the purpose and
possible values for each of the following columns:
 xtype

parentobj

Schema_ver
7. Type in recovery in the index search and double click on recovery model and then double click
on selecting a recovery model and note information in the table below:
Model
Benefits
Loss of data?
Data recovery limits
SIMPLE
FULL
BULKLOGGED
2: Create Database (Enterprise Manager)
Objective: In this exercise you’ll be creating a SQL Database using Enterprise Manager. This is the
easiest way to create a database.
Start  Programs Microsoft SQL Server Enterprise Manager
Expand Microsoft SQL Server, SQL Server Group, your Server, Database
Right click on Databases and click on New Database and press Enter
Type TestDatabase in the Database Name field
Accept all default settings. A Database called TestDatabase has been created as per
specification of Model Database.
6. Right click on TestDatabase and click on Properties and then click on Data Files. Note space
allocated and file growth parameters:
1.
2.
3.
4.
5.
7. Click on Transaction Log tab and note space allocated and file growth parameters:
8. Click on Options tab and note recovery model:
3: Create Database (Query Analyzer)
Objective: In this exercise you will drop and recreate a database called TestDatabase using TransactSQL commands. The syntax is copied from a template.
1.
2.
3.
4.
5.
6.
Start  Programs Microsoft SQL Server Query Analyzer
If you do not see alist of objects in the left pane press F8 for Object Browser.
Click the Templates tab
Click Create Database
Click Create Database Basic Template
Modify the code as follows:
-- =============================================
-- Basic Create Database Template
-- =============================================
IF EXISTS (SELECT *
FROM master..sysdatabases
WHERE name = N'TestDatabase')
DROP DATABASE Testdatabase
GO
CREATE DATABASE TestDatabase
GO
7. Press CTRL+F5
8. If you receive the message “Command successfully completed” then press F5
9. The TestDatabase has now been created for you.
4: Set Database Options using Transact-SQL command
Objective: In this exercise you will be setting Database Recovery Option to Simple by using TransactSQL Commands
1. Reposition cursor in query window and delete text by clicking on Edit and Clear Window
2. Type
ALTER DATABASE TestDatabase
SET RECOVERY SIMPLE
3. Press CTRL + F5
4. If you receive the message command successfully completed then press F5
5. Reposition cursor in query window and press Edit and Clear Window. Then use the Stored
Procedure sp_helpdb to display information about your databases by typing in query window:
sp_helpdb
6. Press F5 to see results
7. Note down the detail information about your database TestDatabase:
5: Use SQL Tools Query Analyzer to access Data
Objective: In this exercise you will be using Transact-SQL Commands to access data.
To work on a specific Database, you can select the database from the drop down database list as
follows:
Or type in the query window
Use Pubs
GO
(Both have the same effect and it is strongly recommended to use the command line to familiarize
yourself with it.)
Then:
1.
2.
3.
4.
5.
6.
7.
8.
9.
Open Query Analyzer query window
Use Object Browser button to expand Pubs
Expand user tables and dbo.authors
Right click on dbo.authors
Select Script object to New Window As
Click Select option (Page 127 , fig 4.2)
Press F5.
What is displayed on the Result Window?
Modify Select statement by removing fname column and rerun query.
6: Create SQL Script
Objective: TRANSACT-SQL allows you to save the statements in a sql file ( called scripts) so that
you can use it later on. In this example you will be creating a script that contains the SELECT
statement from exercise 5.
1.
2.
3.
4.
Click file and click Save As
On File Name type c:\temp\test.sql (Make sure you create the Temp Directory in C: drive)
Press Enter
Verify that Transact-SQL statement is saved in test.sql file in C:\temp directory
7: SQL 2000 Server The Web Assistant
Objective: Create some web pages displaying information from SQL Server databases. In this exercise
you will create a web page using the SQL Server 2000 Web Assistant tool.
1.
2.
3.
4.
5.
6.
7.
8.
9.
Start Enterprise Manager, Expand Microsoft SQL ServerSQL Server Groupyour server
Click Tools
Click Wizards
Expand Management object
Click Web Assistant wizard and click OK
Click Next to Welcome to the Web Assistant Wizard and click Next
Select Pubs database from drop down Menu and click Next
Type SQL 710 WebPage and Next
From the authors table select au_fname, au_lname,address, city, stat, zip, and click Add and
click Next
10. Select all of the rows and click Next
11. Select default settings on Schedule Web Assistant Job and click Next
12. In the publish.web page , select file Name C:\temp\SQL710.html and click Next in the Format
the webpage,
13. Select default settings Click Next
14. In the Specify Title Page type
Seneca College SQL 710 Page and click next
15. In the Format a Table page click Next (if you want a different format than the default you may
change this)
16. In Add Hyperlinks to the web page click Next
17. In limit Rows click Next
18. Click Finish
19. Click OK
20. Open Internet Explorer and in address bar type C:\temp\SQL 710.html
21. What is displayed on the web page – Data from table: __________ How many rows: _______
8. Set up ODBC Connection:
Objective: All Windows systems have built-in ODBC. You can also upgrade to MDAC that comes
with the SQL Server 2000 CD. In this exercise we’ll configure Windows 2000 server’s built-in ODBC
driver.
Start  settings  control panel administrative tools  ODBC
Click System DSN
Click Add
Select SQL Server and click Finish
Fill in the values as follows:
a. Name: Pubs
b. Description: This is SQL 710 System DSN
c. Server: 127.0.0.1 (or type your IP address (to find your IP address type IPCONFIG in
command prompt))
6. Click next.
7. Click With Windows NT authentication using Network Login ID and click Next.
8. Change the default database to pubs and click next
9. In the next window click finish
10. Click “Test Data Source”
11. Once the test is successful click OK
12. Click OK again
13. The pubs database should now show up on the System DSN data sources.
1.
2.
3.
4.
5.