dbadmin d d d d d a a a a a t t t t t a a a a a b b b b b a a a a a s s s s s e e e e...

16
DBAdmin D D D D D a a a a a t t t t t a a a a a b b b b b a a a a a s s s s s e e e e e Administration / Embedded SQL by: Glen Orsburn Chapter 6

Upload: audra-tyler

Post on 19-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: DBAdmin D D D D D a a a a a t t t t t a a a a a b b b b b a a a a a s s s s s e e e e eAdministration / Embedded SQL by: Glen Orsburn Chapter 6

DBAdmin

D DDDD

a a a aa

t t tt

t

a a aa

a

b bb

bb

a aa

aa

s s ss

s

e ee

ee Administration

/ Embedded SQL

by: Glen Orsburn

Chapter 6

Page 2: DBAdmin D D D D D a a a a a t t t t t a a a a a b b b b b a a a a a s s s s s e e e e eAdministration / Embedded SQL by: Glen Orsburn Chapter 6

Database Administration

• Views

• Security using Grant and Revoke

• Creating an Index

• Advantages /Disadvantages

• SQL Catalog

• Integrity

Page 3: DBAdmin D D D D D a a a a a t t t t t a a a a a b b b b b a a a a a s s s s s e e e e eAdministration / Embedded SQL by: Glen Orsburn Chapter 6

Views• Create view Database as

Select packid, packname, packcost from package where packtype = ‘Database’

• When we do the following...Select * from Database where

packcost > 400The SQL engine translates the select of the view to the original select.

Select packid, packname, packcost from package where packtype = ‘Database’

and packcost > 400

Page 4: DBAdmin D D D D D a a a a a t t t t t a a a a a b b b b b a a a a a s s s s s e e e e eAdministration / Embedded SQL by: Glen Orsburn Chapter 6

Creating a view and change column names.

• Create view Database (pkid, name, cost) asSelect packid, packname, packcost

from package where packtype = ‘Database’

• Prompt F4 --

Page 5: DBAdmin D D D D D a a a a a t t t t t a a a a a b b b b b a a a a a s s s s s e e e e eAdministration / Embedded SQL by: Glen Orsburn Chapter 6

Specify CREATE VIEW Statement

Type choices, press Enter.

View . . . . . . . . . softpack Name Library . . . . . . goolib Name, F4 for list

Field names for view 1 1=Use result file names 2=Specify names

WITH CHECK OPTION . . 1 1=NONE 2=CASCADED

3=LOCAL CHECK OPTION is a validity check that can be placed in SQL views. The possible choices are: CASCADED check specifies the constraint LOCAL conform to the definition of that view

Page 6: DBAdmin D D D D D a a a a a t t t t t a a a a a b b b b b a a a a a s s s s s e e e e eAdministration / Embedded SQL by: Glen Orsburn Chapter 6

Views - Advantages

• Views provide data independence. If the underlying table structure is to change, a view may still be created that would emulate the original structure.

• The same data can be viewed by different users in different ways.

• A view should only contain the information a given user or group needs to see.

Page 7: DBAdmin D D D D D a a a a a t t t t t a a a a a b b b b b a a a a a s s s s s e e e e eAdministration / Embedded SQL by: Glen Orsburn Chapter 6

Views - Disadvantages

• Views can be difficult to impossible to update without violating referential integrity.

• Many systems do not allow updates of a view that incorporates a join.

Page 8: DBAdmin D D D D D a a a a a t t t t t a a a a a b b b b b a a a a a s s s s s e e e e eAdministration / Embedded SQL by: Glen Orsburn Chapter 6

Removing a View

• SyntaxDrop view Database

http://publib.boulder.ibm.com/pubs/html/as400/online/v4r3eng.htm

Page 9: DBAdmin D D D D D a a a a a t t t t t a a a a a b b b b b a a a a a s s s s s e e e e eAdministration / Embedded SQL by: Glen Orsburn Chapter 6

Security

• Grant - This command allows a user to access a particular object.

• Revoke - This command disallows a user to access a particular object.

• Syntax...Grant operation on object to user

– Operation can be select, insert, update, delete, index, alter or all.

– Object is a table, view or stored procedure– User is the UserID

Page 10: DBAdmin D D D D D a a a a a t t t t t a a a a a b b b b b a a a a a s s s s s e e e e eAdministration / Embedded SQL by: Glen Orsburn Chapter 6

Indexes

• Speeds access to records by keeping track of row numbers for a selected attribute (or set of attributes) .

• Advantage - Increases speed to access specific data points.

• Disadvantage - Slows updates, inserts and deletes due to overhead of updating index table and data table.

Page 11: DBAdmin D D D D D a a a a a t t t t t a a a a a b b b b b a a a a a s s s s s e e e e eAdministration / Embedded SQL by: Glen Orsburn Chapter 6

Index Syntax

• Create [unique] index ind_packid on package (packid)

• An index may be made from more than one field...

Create index ind_empname on employee(firstname, lastname)

• To drop an index...Drop Index indexname

Optional Index Name Table field to index

Page 12: DBAdmin D D D D D a a a a a t t t t t a a a a a b b b b b a a a a a s s s s s e e e e eAdministration / Embedded SQL by: Glen Orsburn Chapter 6

System Catalog

• A set of related tables that define all objects in the database.– SYSTABLES - Information about all of the

tables in the database (name, creator, creation date…)

– SYSCOLUMNS -Information about the columns within the tables (datatypes, length, null allowed…)

– SYSINDEXES - Information about the indexes on the tables (attribute being indexed, unique

Page 13: DBAdmin D D D D D a a a a a t t t t t a a a a a b b b b b a a a a a s s s s s e e e e eAdministration / Embedded SQL by: Glen Orsburn Chapter 6

select * from syscolumns

SYSCHKCST *FILE LF 24576 SQL catalog view SYSCOLUMNS *FILE LF 49152 SQL catalog view SYSCST *FILE LF 49152 SQL catalog view SYSCSTCOL *FILE LF 40960 SQL catalog view SYSCSTDEP *FILE LF 40960 SQL catalog view SYSINDEXES *FILE LF 65536 SQL catalog view SYSKEYCST *FILE LF 69632 SQL catalog view SYSKEYS *FILE LF 49152 SQL catalog view SYSPACKAGE *FILE LF 69632 SQL catalog view SYSREFCST *FILE LF 40960 SQL catalog view SYSTABLES *FILE LF 40960 SQL catalog view SYSVIEWDEP *FILE LF 65536 SQL catalog view SYSVIEWS *FILE LF 36864 SQL catalog view

System Catalog - Views

Page 14: DBAdmin D D D D D a a a a a t t t t t a a a a a b b b b b a a a a a s s s s s e e e e eAdministration / Embedded SQL by: Glen Orsburn Chapter 6

Database Integrity

• IEF - Integrity Enhancement Feature. An ANSI standard for supporting integrity.

• The following are added to the ‘create table ‘ SQL.– Check (location IN (‘Accounting’, ‘Sales’,

‘Home’))– Primary Key (tagnum)– Foreign Key (compid) references computer

Page 15: DBAdmin D D D D D a a a a a t t t t t a a a a a b b b b b a a a a a s s s s s e e e e eAdministration / Embedded SQL by: Glen Orsburn Chapter 6

Integrity ExampleCREATE TABLE pc

(tagnum char(5),

compid char(4),

empnum decimal(3,0),

location char(12),

CHECK (location IN (‘Accounting’, ‘Sales’, ‘Home’))

PRIMARY KEY (tagnum)

FOREIGN KEY (compid) REFERENCES computer

Page 16: DBAdmin D D D D D a a a a a t t t t t a a a a a b b b b b a a a a a s s s s s e e e e eAdministration / Embedded SQL by: Glen Orsburn Chapter 6

HLL

- Similar statement we have been using in ISQL (Interactive SQL)