• Tidak ada hasil yang ditemukan

Directory listing of http: uap.unnes.ac.id ebook biblebook Visual Basic 6 com & Library Books

N/A
N/A
Protected

Academic year: 2017

Membagikan "Directory listing of http: uap.unnes.ac.id ebook biblebook Visual Basic 6 com & Library Books"

Copied!
28
0
0

Teks penuh

(1)

Creating

Dat abase

Object s with

Oracle8i

I

n this c hapter, I’m go ing to sho w yo u ho w to use the two mo st c o mmo n utilities in Orac le8i, SQL*Plus and Enterprise Manager, to ac c ess yo ur database. Then I’ll talk abo ut ho w to c reate tables and indexes using Enterprise Manager. Finally, I’ll c o ver ho w to manage yo ur sec urity using Enterprise Manager.

Introducing SQL*Plus

SQL*Plus c o mes in two flavo rs: a c o mmand-line driven utility that runs under DOS and a windo w-o riented utility that pro vides a pane where yo u c an enter SQL statements and a pane to sho w the results. Bo th to o ls ac c ept the same set o f SQL statements and will return the same results. The o nly differenc e between the two is ho w the data is presented to the user. I’ll use the c o m-mand-line variety in this sec tio n.

Command-Line SQL*Plus

The c o mmand-line versio n o f SQL*Plus is started fro m a c o mmand pro mpt b y entering SQLPLUS. Yo u c an enter c o m-mands direc tly fro m the keyb o ard o r enter them into a file and exec ute the entire file. The results o f the c o mmands will b e displayed immediately fo llo wing the c o mmand yo u enter.

DOS and commands:In trying to eradicate the concept of DOS from the user’s m ind, Microsoft engineers cleverly renam ed the old DOS Window to Com m and Prom pt in Window s 2000; how ever, it’s the sam e old com m and interpreter you’ve com e to love and hate.

(2)

Connecting to your database with SQL*Plus

These parameters inc lude the user name, the passwo rd, and the database yo u plan to use. If yo u do n’t supply all o f the info rmatio n, yo u will be pro mpted fo r it. The fo rmat yo u must use is sho wn belo w:

<username>[/<password>][@<connectstring>]

where <username> is a valid user name fo r the database yo u wish to ac c ess, <passwo rd> is the passwo rd asso c iated with the user name, and <c o nnec tstring> c o ntains the name o f the database yo u wish to ac c ess.

Fo r example, if yo u want to have a user name o f toyand vb6db.athena.justpc. netas the name o f the database yo u wish to ac c ess, yo u c an start SQL*Plus using the fo llo wing c o mmand:

SQLPLUS [email protected]

SQL*Plus will pro mpt yo u fo r the passwo rd, and assuming that yo u entered it c o r-rec tly, yo u c o uld be pro mpted with an SQLPLUS>pro mpt ( see Figure 27-1) .

(3)

There are other options also: SQL*Plus supports several other options on the com m and line. See Oracle8i DBA Bible by Jonathan Gennick, and published by IDG Books, for m ore inform ation.

It’s not very hidden: While you can enter your passw ord on the com m and line, I don’t recom m end it. In Window s 2000, som eone can sim ply press the up arrow until they see the com m and you executed to start SQL*Plus, even inside the SQL*Plus program . After quitting SQL*Plus, this inform ation w ill rem ain in the com m and history of both Window s 2000/ NT and Window s 98/ 95 system s w ith DOSKEY running. If it w as the last com m and entered, it w ill be visible by sim ply hitting the F3 key.

Entering commands

Onc e SQL*Plus has been started, an SQL>pro mpt will be displayed. Yo u c an enter any c o mmand o r SQL statement at the pro mpt. If the syntax is c o rrec t, the c o m-mand o r SQL statement will be immediately exec uted and the results displayed belo w what yo u typed.

If the display is to o wide, it will auto matic ally b e wrapped to the next line. No te that the lines displayed in the DOS windo w will auto matic ally sc ro ll so that the mo st rec ent info rmatio n is displayed. This c an c ause a pro b lem if yo u are exec ut-ing a Se le ctstatement, whic h returns a large numb er o f ro ws. In this c ase, yo u sho uld either use SQL*Plus Windo w o r inc rease the sc reen b uffer size under the DOS windo w’s pro perty settings.

Confusing, isn’t it?: Com m ands and SQL statem ents are treated differently in SQL*Plus. Com m ands occupy only a single line, w hile SQL statem ents m ay occupy m ultiple lines. To indicate the end of an SQL statem ent, you m ust type a sem i-colon (;). Typing a sem ii-colon at the end of a com m and w ill generate an error m es-sage. Also, if you don’t supply sufficient inform ation for a com m and, you m ay be prom pted for the additional inform ation, or you m ay receive a m essage describing how to use the com m and.

Useful commands

(4)

avail-Table 27-1

Useful Commands in SQL*Plus

Command Description

Clear SQL Clears the contents of the SQL buffer.

Connect Logons to a different database server or the sam e database server as a different user.

Define _Editor Specifies the nam e of your favorite editor program that w ill be run w hen you use the Edit com m and.

Describe Provides a detailed description of a database object, such as a table or stored procedure.

Edit Edits the contents of the SQL buffer in your favorite editor.

Get Loads the contents of a file into the SQL buffer.

Help Provides basic help on SQL*Plus com m ands.

Host Runs the specified DOS com m and and returns to SQL*Plus.

List Lists the statem ents in the SQL buffer.

Quit Exits SQL*Plus and returns to DOS.

Run Lists the statem ents in the SQL buffer and executes them .

Save Saves the SQL buffer to a disk file.

Set Linesize Determ ines the w idth of the line.

Set Newpage Determ ines the num ber of lines displayed betw een pages.

Set Pagesize Determ ines the num ber of lines in a page.

Set Pause When On, m eans that the output w ill be displayed in pages.

Set Serveroutput When On, m eans that output w ill be directed to the console w hen using the DBM S_OUTPUT package.

Spool Directs output to an external file or to the system printer.

Start Runs the SQL statem ents in a disk file.

(5)

After running an SQL statement, it is sto red in the SQL buffer. Yo u c an list the c o n-tents o f this buffer, edit the statement, o r run the statement o ver again using the c o m-mands sho wn in Table 27-1. The c o ntents remain in the SQL buffer until ano ther SQL statement is entered o r the buffer is explic itly c leared using the Clear SQLc o mmand. Yo u c an list the c o ntents o f the SQL buffer with the Listc o mmand. The Saveand Get c o mmands will write a c o py o f the buffer to a disk file and lo ad it bac k again, respec -tively. Use the Runc o mmand to exec ute the statements in the SQL buffer.

The Editc o mmand c o pies the SQL b uffer to a file c alled afiedt.bufand lo ads it into uses whatever edito r yo u spec ify in the De fine _Edito rc o mmand. Yo u then edit yo ur statements, save them and c lo se the edito r to return to SQL*Plus. By default o n a Windo ws platfo rm, yo u’ll use Notepad. Yo u c o uld also use the Save c o mmand to save the SQL b uffer into a file and then use the Ho stc o mmand to perfo rm the same func tio n. No te that yo ur SQL*Plus sessio n is suspended until the edito r o r ho st c o mmand is c o mplete.

SQL*Plus c o ntains c o mmands that c an make wo rking with yo ur SQL statements eas-ier. The first thing yo u sho uld do if yo u are testing Se le ctstatements is to use the Se t Pause Onc o mmand. This c o mmand will auto matic ally break yo ur o utput into pages and pause the o utput at the end o f eac h page. The number o f lines in eac h page is c o ntro lled by the Se t Page sizec o mmand. Yo u c an also c o ntro l the number o f lines displayed between page breaks by using the Se t Ne wpagec o mmand.

If yo u c ho o se, yo u c an direc t the o utput o f the SQL statements to a disk file o r a printer by using the Spoolc o mmand. To redirec t yo ur o utput to a file, spec ify Spool fo llo wed by the name o f the disk file. To redirec t yo ur o utput to the printer, issue the Spool Outc o mmand. Then yo u c an issue any c o llec tio n o f SQL statements o r c o m-mands that generate o utput. When yo u’re finished, issue the Spool Offstatement to c lo se the o utput file o r send yo ur o utput to the printer.

M ake it fit:Use the Set Pagesize, Set Newpage,and Set Linesizecom m ands to adjust the characteristics of your printer.

Introducing Enterprise M anager

Enterprise Manager is a c o mprehensive to o l designed to help yo u manage yo ur database using graphic al to o ls. It pro vides a c entral po int fro m whic h yo u c an manage all o f yo ur Orac le8idatabase servers, even if they are o n multiple physic al c o mputers. It c o mmunic ates with the Orac le Management Server, whic h in turn c o mmunic ates with the database servers that yo u wish to ac c ess. While no t as easy to use as SQL Server’s Enterprise Manager, Orac le8iEnterprise Manager is a big impro vement o ver issuing SQL statements in SQL*Plus to perfo rm c o mmo n tasks suc h as c reating tasks and users.

(6)

The Enterprise M anager console

Rather than c o mbine all o f the to o ls into a single applic atio n, Enterprise Manager c o nsists o f the Enterprise Manager c o nso le, plus a number o f o ther utilities that c an be launc hed fro m the c o nso le o r in a stand-alo ne fashio n. So me o f the mo re impo rtant to o ls inc lude:

SQL* Plus Workshe e t— a graphic al versio n o f SQL*Plus.

DBA Studio— pro vides a graphic al way to c reate and maintain yo ur database struc tures.

Ente rprise Se curity Manage r— simplifies the pro c esses needed to c reate users and map them o nto the pro per ro les.

Ne t8 Assistant— makes it easy to c o nfigure yo ur c o mmunic atio ns netwo rk.

There’s no substitute for page count: If you are w orking w ith a database like Oracle8i w ith lots of tools and utilities, you should invest in a good reference. I suggest the Oracle8iDBA Bible by Jonathan Gennick published by IDG Books.

Logging onto the Enterprise M anager console

When yo u initially start the Enterprise Manager c o nso le ( c ho o se Start➪Orac le – OraHo me81➪Enterprise Manager➪Co nso le) , yo u will see the Enterprise Manager Lo gin windo w ( see Figure 27-2) . In this windo w, yo u need to supply a valid adminis-trato r ID and passwo rd, as well as c ho o se the lo c atio n o f the Orac le Management Server.

Figure 27-2: Logging onto the Enterprise Manager console.

Yet another ID: The adm inistrative ID used to log in to the Oracle Managem ent Server is not the sam e thing as the user nam e you specify w hen you log in to a database. The adm inistrative ID is used to m anage netw ork resources, not database resources.

(7)

Using the Enterprise Console

The Enterprise Co nso le presents a pac ked view o f the reso urc es and to o ls that are available fo r yo u to mo nito r and manage yo ur c o llec tio n o f database servers ( see Figure 27-3) .

Figure 27-3: Running the Enterprise Console.

Navigator pane Group pane

Jobs pane Extended Database Application

Service M anagement Database Application Application M anagement

Event pane Create group

Create event Create job Remove Help

(8)

Navigator panec o ntains info rmatio n abo ut the o bjec ts that c an be managed thro ugh the Enterprise Manager c o nso le.

Group paneis c usto mized to display the info rmatio n yo u wish fro m the Navigato r pane.

Jobs pane lists the jo bs defined in the database that perfo rms tasks like database bac kups and batc h pro c essing.

Eve nt panec o ntains info rmatio n abo ut the events yo u define in yo ur

He lpinvo kes the help subsystem.

Application Manage me ntallo ws yo u to launc h the Orac le Applic atio ns Manager.

Database Applicationsinc ludes o ptio ns to start the DBA Studio and the SQL*Plus Wo rksheet utilities.

Exte nde d Database Applicationspro vides butto ns that bring up the Orac le interMedia Text Manager, the Orac le Replic atio n Manager, and the Orac le Spatial Index Adviso r.

(9)

Figure 27-4: Connecting the Enterprise Manager to a database.

Applic atio n develo pers typic ally need many o f the func tio ns and reso urc es avail-able in the Orac le8iEnterprise Manager. Ho wever, the SQL*Plus Wo rksheet utility and the DBA Studio are two to o ls that are wo rth disc ussing in mo re detail.

SQL*Plus Worksheet

Running func tio ns inside a DOS windo w isn’t fo r everyo ne. Orac le8iinc ludes an alter-native to SQL*Plus, c alled SQL*Plus Wo rksheet. This utility is basic ally a graphic al versio n o f SQL*Plus. The main impro vement is that the SQL buffer is displayed in o ne pane, while the results o f its exec utio n are displayed in ano ther pane. Yo u c an start this utility direc tly fro m the Enterprise Manager o r by c ho o sing Start➪Orac le – OraHo me81➪Database Administratio n➪SQLPlus Wo rksheet.

SQL*Plus Window ain’t SQL*Plus Worksheet: There’s a third version of SQL*Plus, called SQL*Plus Window (Start➪Oracle – OraHom e81➪Application Develop-m ent➪SQL Plus). This utility is m erely SQL*Plus for DOS running in a w indow. You still enter com m ands at a prom pt. Its prim ary advantage is the scrollbars that allow you to look back at the com m ands and SQL statem ents you execute and their results.

Connecting to your database

Yo u start SQL*Plus Wo rksheet fro m the Enterprise Manager b y right c lic king o n the datab ase yo u wish to use and c ho o sing Datab ase Applic atio n➪SQL*Plus Wo rksheet fro m the po p-up menu. If yo u were already c o nnec ted to the datab ase, o r have a preferred c redential fo r this datab ase, yo u will auto matic ally b e c o n-nec ted when SQL*Plus Wo rksheet starts. Otherwise, SQL*Plus Wo rksheet will b e started witho ut an ac tive c o nnec tio n, and yo u will need to exec ute a Co nne ct statement to c o nnec t to yo ur datab ase.

(10)

If yo u start SQL*Plus Wo rksheet using the Start butto n, yo u’ll be pro mpted with the Enterprise Manager Lo gin fo rm. Yo u have a c ho ic e o f two ways to lo g in. Yo u c an lo g in thro ugh the Orac le Management Server using yo ur administrato r ID and passwo rd, o r yo u c an lo g in direc tly to the database using yo ur no rmal database passwo rd (see Figure 27-5). If yo u wish, yo u c an c lic k o n the Lo gin to the Orac le Management Server and lo g in to the Orac le Management Server first. Then the preferred c redentials will be auto matic ally used fo r this partic ular database instanc e.

Figure 27-5: Login to SQL*Plus Worksheet using a norm al database user nam e.

Running SQL*Plus Worksheet

After lo gging o nto SQL*Plus Wo rksheet, yo u’ll see a two -paned windo w with a set o f ic o ns alo ng the left side, as sho wn in Figure 27-6. The to p pane ho lds the SQL state-ments yo u wish to exec ute, while the bo tto m pane c o ntains their results. When yo u initially lo g in, yo u’ll see the results o f the Conne ctc o mmand that was used to ac c ess the database.

Command pane is the pane where yo u enter yo u SQL statements and/ o r c o m-mands fo r exec utio n.

Re sults paneis the pane where the results fro m exec uting a c o mmand are dis-played.

Conne ctionallo ws yo u to lo g o ut fro m the database and bac k o n as a different user.

Exe cutestarts pro c essing the SQL statements listed in the c o mmand area.

Histo rymaintains a list o f the c o mmands and SQL statements yo u have exec uted during this sessio n.

(11)

Figure 27-6: Running SQL*Plus Worksheet.

As yo u might expec t, all yo u need to do to exec ute a c o mmand o r SQL statement is to enter it into the Co mmand pane and press the Exec ute butto n. One wo rd o f c au-tio n — o nc e yo u start exec uting a c o mmand, yo u c an’t sto p it. While this isn’t a pro b-lem fo r mo st c o mmands, c o nsider the pro bb-lem that might o c c ur if yo u try to Se le ct several tho usand ro ws fro m a table.

Help Execute

Connection

Command pane

(12)

DBA Studio

The DBA Studio utility is designed to make yo ur life easier when yo u’re designing an Orac le8idatabase. Many func tio ns that previo usly required yo u to spec ify very c o mplex SQL statements, like Cre ate Tableo r Cre ate Sche ma, are no w imple-mented in a muc h easier to use GUI.

A real Oracle DBA uses ERWin: While DBA Studio is a pow erful tool, you m ight w ant to consider using ERWin by Com puter Associates. While this product is som ew hat expensive, it can be w orth its w eight in gold w hen designing com plex Oracle databases, and unlike database designer solutions from the database ven-dor, this tool allow s you to design databases that can be im plem ented for nearly any database vendor.

Starting DBA Studio

Yo u c an start this utility direc tly fro m the Enterprise Manager, o r by c ho o sing Start➪Orac le – OraHo me81➪Database Administratio n➪DBA Studio . When yo u start the DBA Studio direc tly fro m Windo ws, yo u will be pro mpted to launc h DBA Studio standalo ne o r to lo g in to the Orac le Management Server. In either c ase, yo u will want to c o nnec t to the database as SYSDBA ( see Figure 27-7) . This will ensure that yo u have all o f the appro priate c apabilities yo u’ll need while designing yo ur database.

Figure 27-7: Logging onto DBA Studio in standalone m ode.

But it’s encrypted:If you choose to save your login inform ation as the preferred credential w hen logging into DBA Studio in standalone m ode, you should know that the passw ord is stored on your local hard disk. Even though your passw ord is encrypted, anyone w ho has physical access to your m achine can access DBA Studio by using your default login inform ation.

(13)

Running DBA Studio

DBA Studio presents a two -paned view similar to that used by SQL Server Enterprise Manager ( see Figure 27-8) . It also inc ludes a c o lumn o f ic o ns do wn the left side o f the windo w that yo u c an use to perfo rm c o mmo nly used func tio ns.

Figure 27-8: Running DBA Studio.

Details view Tree view

Help Remove Create like Create

Show dependencies Refresh

(14)

Tre e vie w c o ntains a hierarc hic al list o f ic o ns that referenc e the database o bjec ts that yo u c an manipulate with this utility.

De tails vie wpro vides additio nal info rmatio n abo ut the c urrently selec ted ic o n in the tree view.

Conne ctallo ws yo u to establish a database c o nnec tio n to ano ther database.

Save Listc reates a file that c o ntains the list o f o bjec ts, suc h as the tables that are c o ntained in a partic ular sc hema.

Re fre shgets a fresh c o py o f the info rmatio n displayed in the details view and

Re move deletes the c urrently selec ted o bjec t.

He lpinvo kes the help subsystem.

Creating Tablespaces

Sinc e c reating databases is a task best suited to a database administrato r, I want to begin by walking yo u thro ugh the pro c ess to c reate a tablespac e. A table space rep-resents a po o l o f disk sto rage that c an be used to ho ld tables and indexes.

Before you create a tablespace

Befo re yo u c reate a tablespac e, yo u sho uld c o nsider the fo llo wing questio ns:

✦Whic h database instanc e sho uld ho ld the new tablespac e? Mo st servers that run Orac le8irun multiple database instanc es. This allo ws the database admin-istrato r to allo c ate tablespac e and tables to different database instanc es to o ptimize perfo rmanc e.

✦What name do yo u want to give the new tablespac e? Tablespac e names c an be fro m 1 to 30 c harac ters in length and c an’t duplic ate the name o f ano ther tablespac e o r an Orac le8ireserved wo rd.

(15)

✦What sho uld the initial size o f eac h file be? If yo u need to gro w yo ur tablespac e, yo u c an add additio nal files o r use the Alte r Table spacec o m-mand to mo dify ho w the existing data files c an gro w.

Creating your tablespace

Start Orac le DBA Studio and fo llo w these steps:

1.Verify that yo u are c o nnec ted to the database where yo u wish to add a tablespac e and c lic k o n the Create ic o n. This will display the Create On windo w, as sho wn in Figure 27-9.

Figure 27-9: Select the tablespace icon to create a new tablespace.

2.Cho o se Tablespac e and press the Create butto n. This will display the Create Tablespac e pro perty windo w, as sho wn in Figure 27-10. Then yo u just need to fill in the blanks. Enter a name fo r the tablespac e. This will auto matic ally fill in a value fo r the file name. If yo u wish, yo u c an c hange the name o f the file. If yo u plan to add additio nal files to this tablespac e, yo u sho uld inc lude a _01to indic ate that this is the first file. The File Direc to ry will default to the o ne c ur-rently used by the database. Yo u c an also c hange it, if yo u wish to plac e the file o n ano ther disk drive. Finally, yo u need to fill in the size o f the tablespac e. If yo u c lic k o n the area next to the numeric value under Size, yo u c an c hange the units fro m megabytes (MB) to kilo bytes (KB) .

(16)

Figure 27-10: Provide the inform ation for the tablespace.

Creating Tables and Indexes

Befo re yo u c reate the tab les fo r yo ur applic atio n, yo u sho uld dec ide o n a name fo r yo ur datab ase sc hema. A sc hema name will help yo u gro up all o f the datab ase o b jec ts yo u c reate into a single entity. While yo u do n’t explic itly c reate yo ur sc hema in the DBA Studio , yo u referenc e its name eac h time yo u c reate a new datab ase o b jec t.

Creating a table isn’t muc h mo re than spec ifying a name fo r yo ur table and the list o f c o lumns yo u want inc luded. Ho wever, the mo re time yo u spend preparing to build yo ur table, the better o ff yo u will be. Here are a few questio ns yo u may want to c o nsider.

✦What tablespac e will ho ld yo ur table?

✦What is the name o f yo ur table? Yo ur table name sho uld be prefixed by the sc hema name that yo u want to use. If yo u do n’t spec ify a sc hema name, yo ur user name will be used. Bo th identifiers c an be up to 30 c harac ters in length. While yo u c an use spac es and o ther spec ial c harac ters as part o f the table name, yo u will have to enc lo se the table name in quo tatio n marks eac h time yo u use it. Also , this will make the table name c ase-sensitive. Also , remember that the table name must be unique within the sc hema yo u spec ify.

(17)

✦What is the data type fo r eac h c o lumn? The data type sho uld be o ne o f the data types listed in Chapter 26. Yo u may have to c ho o se the size o f the field and the sc ale depending o n the data type yo u selec t.

✦Sho uld the c o lumn ac c ept Nullvalues? No te that Nullvalues sho uld no t be used in any c o lumn that is used as part o f a primary o r fo reign key.

✦Is there a default value fo r the c o lumn? This is an o ptio nal field that allo ws yo u to insert a spec ific value into the table instead o f marking the c o lumn as Null.

✦Sho uld yo u perfo rm a referential integrity c hec k? This implies that eac h value entered in this field must exist in ano ther table in this database.

Creating your table

Orac le DBA Studio allo ws yo u to c reate a table thro ugh a multi-step wizard o r by displaying a wo rksheet-like fo rm to fill o ut. I’m go ing to step yo u thro ugh the wizard sinc e it simplifies muc h o f the wo rk. Then I’ll sho w yo u ho w to mo dify the table using the fo rm.

1.Start DBA Studio , selec t the appro priate database, and press the Create but-to n but-to display the o bjec t list, as sho wn in Figure 27-11. Selec t Table fro m the list, make sure the Use Wizard c hec k bo x is c hec ked, and then press the Create butto n.

Figure 27-11: Starting the Create Table w izard.

(18)

Figure 27-12: Entering basic inform ation about the table.

3.In the next step o f the wizard ( see Figure 27-13) , yo u will enter the c o lumns yo u want to inc lude and their data type. Yo u c an also spec ify a default value fo r eac h c o lumn as well. Simply enter the info rmatio n in the Pro perties o f Co lumn sec tio n o f the fo rm and press the Add butto n. Yo u c an also remo ve a c o lumn that yo u have added by selec ting it in the Co lumns defined area o f the fo rm and pressing Remo ve.

(19)

4.In step 3 o f the Table Wizard, yo u selec t the primary key ( see Figure 27-14) . While Orac le permits yo u to c reate the table witho ut a primary key, I believe that every table yo u c reate sho uld have a primary key. Cho o se the Yes, I Want To Create a Primary Key radio butto n to display the list o f c o lumns fo r the table, and then spec ify the o rder o f the c o lumns that c o mprise the primary key. If a c o lumn is no t part o f the primary key, leave the o rder field blank.

Figure 27-14: Selecting the prim ary key for your table.

5.Pressing Next allo ws yo u to spec ify Nulland Unique c o nstraints o n eac h field in yo ur new table (see Figure 27-15). To mo dify a c o lumn, selec t the c o lumn in the Co lumns Defined area o f the fo rm. Yo u sho uld always ensure that bo th c o n-straints are selec ted fo r the primary key. Ho wever, yo u sho uld o nly use Unique fo r the primary key if yo u have a very go o d reaso n fo r do ing so bec ause eac h Uniquec lause yo u add after the primary key impo ses a lo t o f extra wo rk eac h time yo u insert a new ro w.

(20)

Figure 27-15: Choosing Null and Unique constraints for each colum n in your table.

Figure 27-16: Defining foreign key relationships.

(21)

Figure 27-17: Creating check constraints.

8.The remaining steps o f the wizard allo w yo u to o ptimize ho w the tab le is sto red. Unless yo u are a kno wledgeab le Orac le datab ase administrato r, I suggest that yo u skip these steps. Pressing the Finish b utto n will c reate yo ur tab le. When the wizard has finished, a message b o x will b e displayed indic ating that yo ur tab le was suc c essfully c reated.

Like Create Like, man:If you have to create a table that is sim ilar to another table that is already in your database, consider clicking on the Create Like button, instead of the Create button. Select an existing table in tree view and press the Create Like button. Your new table w ill include all of the definitions that are in the table you previously selected. You m ay then m ake any m odifications you w ant — add colum ns, delete colum ns, change nam es, data types, and so on. This can be m uch easier than you think.

M odifying a table

Yo u c an mo dify a tab le b y right c lic king o n the tab le name fro m the tree view and c ho o sing the Edit o ptio n fro m the po p-up menu. This will display the Edit Tab le pro perty windo w, as sho wn in Figure 27-18. Yo u may c hange any o f the c o lumn’s c harac teristic s, inc luding Datatype, Size, Sc ale, Fo reign Key Referenc es ( Ref) , Nulls, and Default Value, all o n this single fo rm. No tic e that yo u c an’t c hange any o f the info rmatio n at the to p part o f the fo rm suc h as the name o f the tab le, its sc hema o r tab le spac e.

(22)

Figure 27-18: Modifying a table’s characteristics.

Yo u c an make any c hanges yo u wish to a table as lo ng as it do esn’t have data in it. If yo ur table do es c o ntain data, yo u c an make c hanges as lo ng as yo u fo llo w these rules:

✦A new c o lumn must ac c ept Nullvalues. If yo u wish to add a c o lumn that do es-n’t permit Nullvalues, yo u add the c o lumn permitting Nullvalues, then use an Updatestatement to assign a value to this c o lumn fo r every ro w in the table. Then yo u c an mo dify the c o lumn to pro hibit Nullvalues.

✦Yo u always inc rease the size o f a c harac ter-based c o lumn (Char, Varchar2, etc .) . If yo u want to dec rease the size, yo u must first c hange the value fo r eac h ro w in the table to Null, then make the c hange.

✦Yo u c an always inc rease the numb er o f digits o r inc rease o r dec rease the numb er o f dec imal plac es in a Numbe rc o lumn. To dec rease the numb er o f digits in the c o lumn, yo u must first ensure that eac h ro w c o ntains a Null value fo r this c o lumn b efo re making the c hange.

✦Yo u c an c hange the data type assigned to a c o lumn o nly if the c o lumn’s value fo r eac h ro w in the table is Null.

There’s always a way if you really want to do something: One w ay to change the characteristics of a colum n is to add a tem porary colum n to your table that accepts Nullvalues, w ith all of the characteristics you w ant the changed colum n to have. Then use an Updatestatem ent and assign the value from the original col-um n to the tem porary colcol-um n using w hatever functions are necessary to convert the value properly. Then delete the old colum n from your table and give the origi-nal colum n’s nam e to the tem porary colum n.

(23)

Creating an index

Yo u c an always add an index to yo ur table by c lic king the Create butto n and c ho o s-ing Index fro m the list o f available database o bjec ts. This will display the Create Index pro perty windo w ( see Figure 27-19) . Simply fill in the values fo r the name o f the index, the sc hema it will be asso c iated with, and the tablespac e it will use fo r sto rage. Then c ho o se the sc hema and table name fo r the table where the index will be applied. Next, c ho o se the c o lumns and the o rder they will appear in the index and and press Create to build the index.

Figure 27-19: Creating an index.

M anaging Security

Managing sec urity is an impo rtant part o f every datab ase management system ( DBMS) . As yo u wo uld expec t, it invo lves three main pro c esses: c reating ro les, c reating users, and assigning permissio ns to b o th users and ro les.

Creating roles

(24)

database o bjec ts. This will display the Create Ro le pro perty windo w ( see Figure 27-20) . Yo u must enter a name fo r the ro le and c ho o se whether yo u want additio nal authentic atio n fro m the user in o rder to enable the ro le.

Figure 27-20: Creating a new role.

On the Ro le tab, yo u c an c ho o se to add any existing ro les to this ro le. This means yo u c an c reate a single ro le that enc o mpasses several o ther ro les, thus simplifying sec urity management.

Creating users

Using DBA Studio , yo u c an c reate a user very easily b y pressing the Create b utto n and selec ting Users fro m the list o f datab ase o b jec ts. This will display the Create User pro perty windo w. This pro perty windo w has three tab s: General, Ro le, and System Privileges, eac h o f whic h ho lds part o f the info rmatio n availab le ab o ut a user. After filling o ut the info rmatio n in eac h tab , simply press the Create b utto n to c reate the new user.

Create Like strikes again:Creating a new user is one of the m ost painful pro-cesses any com puter center has to m anage. One w ay to avoid som e of the pain is to create a standard user and then use the Create Like process to duplicate it, including all of its security roles and privileges. While you should still review every-thing to m ake sure that it is appropriate for the user you are creating, Create Like w ill help you avoid m aking sim ple m istakes.

(25)

Entering general information for a user

Figure 27-21 sho ws the General tab o f the Create User pro perty windo w. To c reate a new user, simply fill o ut the user’s name and spec ify the passwo rd info rmatio n. Then asso c iate the user with the appro priate Default and Tempo rary tablespac es. If yo u c hec k the Expire Passwo rd No w c hec k bo x, the user will be required to c hange their passwo rd the first time they lo g o n to the system. Also , selec ting Lo c ked means that the user is pro hibited fro m using the user name until yo u selec t the Unlo c ked radio butto n.

Figure 27-21: Entering general inform ation about a user.

Three strikes and you’re locked: You can enable a feature in your database that w ill lock a user out of the database if they specify an invalid passw ord three tim es in a row.

Granting roles

In o rder fo r the user to perfo rm any useful wo rk, yo u must assign them to o ne o r mo re ro les ( see Figure 27-22) . At a minimum, they sho uld be granted the CONNECT ro le, whic h will permit them to Conne ctto the database server. Simply selec t the ro les yo u wish to grant to the user and press the arro w that is po inting do wn. The selec ted ro les are c o pies to the Granted pane. When the user is c reated, the user will inherit the sec urity permissio ns o f eac h o f the ro les in the Granted pane.

(26)

Figure 27-22: Selecting roles for a user.

Selecting system privileges

Fo r the mo st part, a user sho uldn’t be assigned any o f the privileges listed o n the System Privileges tab ( see Figure 27-23) . These privileges sho uld be reserved fo r database administrato rs and/ o r database o perato rs. ( See Chapter 26, “Overview o f Orac le8i,” fo r a mo re detailed disc ussio n abo ut the system privileges and what they permit the user to do ) .

Granting permissions

(27)

I wo uld then c reate ano ther ro le fo r eac h ac c ess level fo r yo ur applic atio n and assign eac h o f the lo wer-level ro les c reated earlier that are appro priate fo r the applic atio n. This simplifies the pro c ess o f administratio n, sinc e yo u wo uld o nly have to asso c iate o ne ro le fo r eac h applic atio n that the user has ac c ess to . Then if yo u c hange the applic atio n slightly, yo u need o nly manage the permissio ns asso c iated with the lo wer-level ro les.

Figure 27-23: Selecting system privileges.

Thoughts on Creating Oracle8

i

Database Objects

Creating database objects in Oracle8ican be very sim ple or incredibly com plex —it’s your choice. Oracle8iincludes m any features that you can exploit w hen you build your database that I haven’t discussed here. These features can m ake you database m uch m ore efficient. How ever using these features can be difficult. This is another reason that an experienced database adm inistrator is w orth their w eight in m em ory chips.

(28)

Summary

In this c hapter yo u learned:

✦abo ut SQL*Plus and so me useful c o mmands yo u may want to use.

✦abo ut Enterprise Manager and ho w to use it to ac c ess multiple database instanc es.

✦abo ut SQL*Plus Wo rksheet and ho w it differs fro m SQL*Plus.

✦ho w to c reate a tablespac e.

✦ho w to c reate tables and indexes.

✦ho w to manage sec urity by c reating users and granting ro les.

Gambar

Figure 27-1: Logging onto a database with SQL*Plus.
Table 27-1Useful Commands in SQL*Plus
Figure 27-2: Logging onto the Enterprise Manager console.
Figure 27-3).
+7

Referensi

Dokumen terkait

Bila tidak ditetapkan, maka penyelesaian Transaksi Bursa dilakukan selambat-lambatnya pada Hari Bursa ke-3 setelah terjadinya transaksi (T+3) atau Hari Bursa yang sama

[r]

n salinannya sebagaimana tertuang dalam lam proses pembuktian kualifikasi

Uang merupakan uang milik masyarakat atau uang beredar di masyarakat (di luar Bank Sentral seperti Bank Indonesia dan perbankan atau semua bank), yang terdiri dari :.. Uang Kertas

Puji syukur kami panjatkan kepada Tuhan Yang Maha Esa atas limpahan rahmat dan hidayah-Nya sehingga Prosiding Seminar Nasional MIPA Universitas Negeri Yogyakarta

Basics Interior Design 02: Exhibition Design explores the role of the exhibition designer as a creative practitioner, and seeks to communicate a better understanding of

As everybody recognizes, book Carr: Five Years Of Rape And Murder By Edna Buchanan is very popular as the window to open up the globe. It implies that reading publication Carr:

Teori investasi menjelaskan bahwa ketidakpastian IHSG pada suatu pasar bursa disebabkan oleh adanya pengaruh faktor lingkungan bisnis yang terdiri dari faktor lingkungan