File: aguide05.htm

package info (click to toggle)
solid-desktop 2.2-3
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 3,620 kB
  • ctags: 2,830
  • sloc: sh: 290; sql: 80; makefile: 64
file content (405 lines) | stat: -rw-r--r-- 22,284 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
<HTML>
<HEAD>
<TITLE></TITLE>
<LINK REL="ToC" HREF="httoc.htm">
<LINK REL="Index" HREF="htindex.htm">
<LINK REL="Next" HREF="aguide06.htm">
<LINK REL="Previous" HREF="aguide04.htm"></HEAD>
<BODY BGCOLOR="#FFFFFF">
<P ALIGN=CENTER>
<A HREF="aguide04.htm" TARGET="_self"><IMG SRC="gaguide/graprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>
<A HREF="httoc.htm" TARGET="_self"><IMG SRC="gaguide/gratop.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>
<A HREF="htindex.htm" TARGET="_self"><IMG SRC="gaguide/graindex.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Index"></A>
<A HREF="aguide06.htm" TARGET="_self"><IMG SRC="gaguide/granext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>

<A NAME="E9E5"></A>
<H1>
<FONT FACE="Arial"><B>ADMINISTRATION WITH SQL STATEMENTS</B></FONT></H1>
<BR>
<BLOCKQUOTE>
<P>This chapter tells you how to manage users, tables, and indexes using SQL statements<A NAME="I2"></A>. You can use SOLID <I>SQL Editor</I> and many ODBC compliant tools for executing these SQL statements.
</BLOCKQUOTE>
<BLOCKQUOTE>
<P>To automate these tasks, you may want to save the SQL statements to a file. You can use these files for rerunning your SQL statements later or as a document of your users, tables, and indexes.
</BLOCKQUOTE>
<BLOCKQUOTE>
<P>The SQL syntax is based on the ANSI X3.135-1989 level 2 standard including important ANSI X3.135-1992 (SQL2) extensions. User and role management services missing from previous standards are based on the ANSI SQL3 draft. For a more formal definition of the syntax, refer to <I>Appendix D SOLID </I><I>Server SQL Syntax</I> of this document. For the full description of the SOLID <I>SQL API</I>, refer to the <B>SOLID </B><B><I>SQL API</I></B><B> Help</B> file. The same information is included in <B>SOLID </B><B><I>Server</I></B><B> Programmer's Guide</B> and <B>SOLID </B><B><I>Server</I></B><B> </B><B>Programmer's Reference</B>.
</BLOCKQUOTE>
<A NAME="E10E27"></A>
<P>
<FONT FACE="Arial"><B>Managing User Privileges and Roles</B><A NAME="I3"></A><A NAME="I4"></A></FONT>
<BLOCKQUOTE>
<P>You can use SOLID <I>SQL Editor</I> and many ODBC compliant SQL tools to modify user privileges. Users and roles are created and deleted using SQL statements or commands. A file consisting of several SQL statements is called a SQL script.
</BLOCKQUOTE>
<BLOCKQUOTE>
<P>In the SOLID directory, you will find an SQL script<A NAME="I5"></A> called users.sql<A NAME="I6"></A>, which gives an example of creating users and roles. You can open, view and run it using SOLID <I>SQL Editor</I>. To create your own users and roles, you can make your own script describing your user environment.
</BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<P>NOTE. All SQL statements must be terminated with a semicolon (;).
<HR ALIGN=CENTER>
</BLOCKQUOTE>
<P>
<FONT FACE="Arial"><A NAME="I7"></A><A NAME="I8"></A><A NAME="I9"></A><A NAME="I10"></A><A NAME="I11"></A><A NAME="I12"></A><A NAME="I13"></A><A NAME="I14"></A><A NAME="I15"></A><A NAME="I16"></A><A NAME="I17"></A><A NAME="I18"></A><A NAME="I19"></A><A NAME="I20"></A><A NAME="I21"></A><A NAME="I22"></A><A NAME="I23"></A><A NAME="I24"></A><A NAME="I25"></A><A NAME="I26"></A><A NAME="I27"></A><A NAME="I28"></A><A NAME="I29"></A><A NAME="I30"></A>User Privileges<A NAME="I31"></A></FONT>
<BLOCKQUOTE>
<P>When using SOLID <I>Server</I> in a multi-user environment, you may want to apply user privileges to hide certain tables from some users. For example, you may not want an employee to see the table in which employee salaries are listed, or you may not want other users to mess with your test tables.
</BLOCKQUOTE>
<BLOCKQUOTE>
<P>SOLID <I>Server</I> allows you to apply five different kinds of user privileges. A user may be able to view, delete, insert, update or reference information in a table or view. Any combination of these privileges may also be applied. A user who has none of these privileges to a table is not able to use the table at all.
</BLOCKQUOTE>
<P>
<FONT FACE="Arial"><A NAME="I32"></A><A NAME="I33"></A><A NAME="I34"></A><A NAME="I35"></A><A NAME="I36"></A><A NAME="I37"></A><A NAME="I38"></A><A NAME="I39"></A><A NAME="I40"></A><A NAME="I41"></A><A NAME="I42"></A><A NAME="I43"></A><A NAME="I44"></A><A NAME="I45"></A><A NAME="I46"></A><A NAME="I47"></A><A NAME="I48"></A><A NAME="I49"></A><A NAME="I50"></A><A NAME="I51"></A><A NAME="I52"></A><A NAME="I53"></A><A NAME="I54"></A><A NAME="I55"></A>User Roles<A NAME="I56"></A></FONT>
<BLOCKQUOTE>
<P>Privileges can also be granted to an entity called a role. A role is a group of privileges that can be granted to users as one unit. SOLID <I>Server</I> allows you to create roles and assign users to certain roles.
</BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<P>NOTE. Same string can not be used both as a user name and a role name<A NAME="I57"></A><A NAME="I58"></A>.
<HR ALIGN=CENTER>
</BLOCKQUOTE>
<BLOCKQUOTE>
<P>The following user and role names are reserved:
</BLOCKQUOTE>
<BLOCKQUOTE><TABLE>
<TR>
<TD WIDTH=240 VALIGN=top >
<P><B>Reserved name</B>
</TD><TD WIDTH=216 VALIGN=top >
<A NAME="E7E129"></A>
<P>Description</TD>
</TR>
<TR>
<TD WIDTH=240 VALIGN=top >
<P>PUBLIC
</TD><TD WIDTH=216 VALIGN=top >
<A NAME="E7E130"></A>
<P>You can use this role to grant privileges to all users. When user privileges to a certain table are granted to the role PUBLIC, all current and future users have the specified user privileges to this table. This role is granted automatically to all users.</TD>
</TR>
<TR>
<TD WIDTH=240 VALIGN=top >
<P>SYS_ADMIN_ROLE
</TD><TD WIDTH=216 VALIGN=top >
<A NAME="E7E131"></A>
<P>This is the default role<A NAME="I59"></A> for the database administrator. This role has administration privileges to all tables, indexes and users. This is also the role of the creator of the database.</TD>
</TR>
<TR>
<TD WIDTH=240 VALIGN=top >
<P>_SYSTEM
</TD><TD WIDTH=216 VALIGN=top >
<A NAME="E7E132"></A>
<P>This is the schema name of all system tables and views. </TD>
</TR>
<TR>
<TD WIDTH=240 VALIGN=top >
<P>SYS_CONSOLE_ROLE
</TD><TD WIDTH=216 VALIGN=top >
<A NAME="E7E133"></A>
<P>This role<A NAME="I60"></A> has right to use SOLID<I> Remote </I><I>Control</I>, but does not have other administration privileges.</TD></TR></TABLE></BLOCKQUOTE>
<P>
<FONT FACE="Arial"><A NAME="I61"></A><A NAME="I62"></A><A NAME="I63"></A><A NAME="I64"></A><A NAME="I65"></A><A NAME="I66"></A><A NAME="I67"></A><A NAME="I68"></A><A NAME="I69"></A><A NAME="I70"></A><A NAME="I71"></A><A NAME="I72"></A><A NAME="I73"></A><A NAME="I74"></A><A NAME="I75"></A><A NAME="I76"></A><A NAME="I77"></A><A NAME="I78"></A><A NAME="I79"></A><A NAME="I80"></A><A NAME="I81"></A><A NAME="I82"></A><A NAME="I83"></A><A NAME="I84"></A>Examples of SQL Statements<A NAME="I85"></A></FONT>
<BLOCKQUOTE>
<P>Below are some examples of SQL commands for administering users, roles and user privileges.
</BLOCKQUOTE>
<BLOCKQUOTE>
<H4>
<FONT FACE="Arial"><B>Creating Users</B><A NAME="I86"></A></FONT></H4>
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>CREATE USER &lt;username&gt; IDENTIFIED BY &lt;password&gt;;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<P>Only an administrator has the privilege to execute this statement. The following example creates a new user named CALVIN with the password HOBBES<A NAME="I87"></A>.
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>CREATE USER CALVIN IDENTIFIED BY HOBBES;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<H4>
<FONT FACE="Arial"><B>Deleting Users</B><A NAME="I88"></A></FONT></H4>
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>DROP USER &lt;username&gt;;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<P>Only an administrator has the privilege to execute this statement. The following example deletes the user named CALVIN.
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>DROP USER CALVIN;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<H4>
<FONT FACE="Arial"><B>Changing a Password</B></FONT></H4>
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>ALTER USER &lt;username&gt; IDENTIFIED BY &lt;new password&gt;;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<P>The user &lt;username&gt; and the administrator have the privilege to execute this command. The following example changes CALVIN<B>'</B>s password to GUBBES<A NAME="I89"></A>.
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>ALTER USER CALVIN IDENTIFIED BY GUBBES;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<H4>
<FONT FACE="Arial"><B>Creating Roles</B><A NAME="I90"></A></FONT></H4>
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>CREATE ROLE &lt;rolename&gt;;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<P>The following example creates a new user role named GUEST_USERS.
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>CREATE ROLE GUEST_USERS;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<H4>
<FONT FACE="Arial"><B>Deleting Roles</B><A NAME="I91"></A></FONT></H4>
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>DROP ROLE &lt;role_name&gt;;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<P>The following example deletes the user role named GUEST_USERS.
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>DROP ROLE GUEST_USERS;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<H4>
<FONT FACE="Arial"><B>Granting Privileges to a User or a Role</B><A NAME="I92"></A><A NAME="I93"></A></FONT></H4>
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>GRANT &lt;user_privilege&gt; ON &lt;table_name&gt; TO &lt;username or role_name&gt;;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<P>The possible user privileges on tables are SELECT, INSERT, DELETE, UPDATE, REFERENCES and ALL. ALL will give a user or a role all five privileges mentioned above. EXECUTE privilege will give a user a right to execute a stored procedure. A new user has not any privileges.
</BLOCKQUOTE>
<BLOCKQUOTE>
<P>The following example grants INSERT and DELETE privileges on a table named TEST_TABLE to the GUEST_USERS role.
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>GRANT INSERT, DELETE ON TEST_TABLE TO GUEST_USERS;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<P>The following example grants EXECUTE privilege on a stored procedure named SP_TEST to user CALVIN.
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>GRANT EXECUTE ON SP_TEST TO CALVIN;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<H4>
<FONT FACE="Arial"><B>Granting Privileges to a User by Giving the User a Role</B><A NAME="I94"></A><A NAME="I95"></A></FONT></H4>
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>GRANT &lt;role_name&gt; TO &lt;username&gt;;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<P>The following example gives the user CALVIN the privileges that are defined for the GUEST_USERS role.
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>GRANT GUEST_USERS TO CALVIN;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<H4>
<FONT FACE="Arial"><B>Revoking Privileges from a User or a Role</B><A NAME="I96"></A><A NAME="I97"></A></FONT></H4>
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>REVOKE &lt;user_privilege&gt; ON &lt;table_name&gt; FROM &lt;username or role_name&gt;;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<P>The following example revokes the INSERT privilege on the table named TEST_TABLE from the GUEST_USERS role.
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>REVOKE INSERT ON TEST_TABLE FROM GUEST_USERS;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<H4>
<FONT FACE="Arial"><B>Revoking Privileges by Revoking the Role of a User</B><A NAME="I98"></A></FONT></H4>
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>REVOKE &lt;role_name&gt; FROM &lt;username&gt;;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<P>The following example revokes the privileges that are defined for the GUEST_USERS role from CALVIN.
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>REVOKE GUEST_USERS FROM CALVIN;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<H4>
<FONT FACE="Arial"><B>Granting Administrator Privileges to a User</B><A NAME="I99"></A></FONT></H4>
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>GRANT SYS_ADMIN_ROLE TO &lt;username&gt;;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<P>The following example grants administrator privileges to CALVIN, who now has all privileges to all tables<A NAME="I100"></A>.
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>GRANT SYS_ADMIN_ROLE TO CALVIN;</PRE></BLOCKQUOTE>
<A NAME="E10E28"></A>
<P>
<FONT FACE="Arial"><B>Managing Tables</B><A NAME="I101"></A></FONT>
<BLOCKQUOTE>
<P>SOLID <I>Server</I> has a dynamic data dictionary that allows you to create, delete and alter tables on-line. SOLID <I>Server</I> tables are managed using SQL commands.
</BLOCKQUOTE>
<BLOCKQUOTE>
<P>In the SOLID directory, you can find an SQL script named sample.sql<A NAME="I102"></A>, which gives an example of managing tables. You can view and run the script using SOLID <I>SQL Editor</I>.
</BLOCKQUOTE>
<BLOCKQUOTE>
<P>Below are some examples of SQL statements for managing tables<A NAME="I103"></A>. For a formal definition of the SOL syntax of SOLID <I>Server</I>, refer to <I>Appendix D SOLID Server SQL Syntax</I> of this document.
</BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<P>TIP. If you want to see the names of all tables in your database, issue the SQL statement SELECT * FROM TABLES or use predefined command TABLES from SOLID <I>SQL Editor</I>. The table names can be found in the column TABLE_NAME.
<HR ALIGN=CENTER>
</BLOCKQUOTE>
<P>
<FONT FACE="Arial"><A NAME="I104"></A><A NAME="I105"></A><A NAME="I106"></A><A NAME="I107"></A><A NAME="I108"></A><A NAME="I109"></A><A NAME="I110"></A><A NAME="I111"></A><A NAME="I112"></A><A NAME="I113"></A><A NAME="I114"></A><A NAME="I115"></A><A NAME="I116"></A><A NAME="I117"></A><A NAME="I118"></A><A NAME="I119"></A><A NAME="I120"></A><A NAME="I121"></A><A NAME="I122"></A><A NAME="I123"></A><A NAME="I124"></A><A NAME="I125"></A>Examples of SQL Statements </FONT>
<BLOCKQUOTE>
<P>Below are some examples of SQL commands for administering tables.
</BLOCKQUOTE>
<BLOCKQUOTE>
<H4>
<FONT FACE="Arial"><B>Creating Tables</B><A NAME="I126"></A></FONT></H4>
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>CREATE TABLE &lt;table_name&gt; (&lt;column&gt; &lt;column type&gt; 
<BR>   [,&lt;column&gt; &lt;column type&gt;]...);</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<P>All users have privileges to create tables. 
</BLOCKQUOTE>
<BLOCKQUOTE>
<P>The following example creates a new table named TEST with the column I of the column type INTEGER and the column TEXT of the column type VARCHAR.
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>CREATE TABLE TEST (I INTEGER, TEXT VARCHAR);</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<H4>
<FONT FACE="Arial"><B>Removing Tables</B><A NAME="I127"></A></FONT></H4>
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>DROP TABLE &lt;table_name&gt;;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<P>Only the creator of the particular table or users having SYS_ADMIN_ROLE have privileges to remove tables.
</BLOCKQUOTE>
<BLOCKQUOTE>
<P>The following example removes the table named TEST.
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>DROP TABLE TEST;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<H4>
<FONT FACE="Arial"><B>Adding Columns to a Table</B><A NAME="I128"></A><A NAME="I129"></A></FONT></H4>
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>ALTER TABLE &lt;table_name&gt; ADD COLUMN &lt;column_name&gt; 
<BR>   &lt;column type&gt;;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<P>Only the creator of the particular table or users having SYS_ADMIN_ROLE have privileges to add or delete columns in a table.
</BLOCKQUOTE>
<BLOCKQUOTE>
<P>The following example adds the column C of the column type CHAR(1) to the table TEST.
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>ALTER TABLE TEST ADD COLUMN C CHAR(1);</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<H4>
<FONT FACE="Arial"><B>Deleting Columns from a Table</B><A NAME="I130"></A><A NAME="I131"></A></FONT></H4>
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>ALTER TABLE &lt;table_name&gt; DROP COLUMN 
<BR>   &lt;column_name&gt;;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<P>The following example statement deletes the column C from the table TEST.
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>ALTER TABLE TEST DROP COLUMN C;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<P><A NAME="I132"></A><A NAME="I133"></A><A NAME="I134"></A><A NAME="I135"></A><A NAME="I136"></A><A NAME="I137"></A><A NAME="I138"></A><A NAME="I139"></A><A NAME="I140"></A>
</BLOCKQUOTE>

<HR ALIGN=CENTER>
<TABLE>
<TR>
<TD WIDTH=100 VALIGN=top >
<IMG SRC="gaguide/aguide15.gif" WIDTH = 24 HEIGHT = 22 ALT="Commit button">
<P><I>SOLID</I> SQL Editor: 
<P>
<I>Commit button</I>
</TD>
<TD WIDTH=600 VALIGN=top >
<BLOCKQUOTE>
<P>NOTE. If the autocommit mode is set OFF, you need to commit your work before you can modify the table you altered. To commit your work after altering a table, use the SQL statement COMMIT WORK;, or press the Commit button in SOLID <I>SQL Editor</I><A NAME="I141"></A><A NAME="I142"></A>. If the autocommit mode is set ON - this is the default in SOLID <I>SQL </I><I>Editor</I> - the transactions are committed automatically.</TD></TR></BLOCKQUOTE>
</TABLE>

<HR ALIGN=CENTER>
<A NAME="E10E29"></A>
<P>
<FONT FACE="Arial"><B>Managing Indexes</B><A NAME="I143"></A></FONT>
<BLOCKQUOTE>
<P>Indexes are used to speed up access to tables. The database engine uses indexes to access the rows in a table directly. Without indexes, the engine would have to search the whole contents of a table to find the desired row. There are two kinds of indexes: non-unique indexes and unique indexes. A unique index is an index where all key values are unique. You can create as many indexes as you like to a single table. However, adding indexes slows down updates on that table.
</BLOCKQUOTE>
<BLOCKQUOTE>
<P>SOLID <I>Server </I>allows<I> </I>you to create and delete indexes using the following SQL statements<A NAME="I144"></A>. For a formal definition of the syntax of these statements, refer to <I>Appendix </I><I>D SOLID Server SQL Syntax</I> of this document.
</BLOCKQUOTE>
<P>
<FONT FACE="Arial"><A NAME="I145"></A><A NAME="I146"></A><A NAME="I147"></A><A NAME="I148"></A><A NAME="I149"></A><A NAME="I150"></A><A NAME="I151"></A><A NAME="I152"></A><A NAME="I153"></A><A NAME="I154"></A><A NAME="I155"></A><A NAME="I156"></A><A NAME="I157"></A><A NAME="I158"></A><A NAME="I159"></A><A NAME="I160"></A><A NAME="I161"></A><A NAME="I162"></A><A NAME="I163"></A><A NAME="I164"></A><A NAME="I165"></A><A NAME="I166"></A>Examples of SQL Statements<A NAME="I167"></A></FONT>
<BLOCKQUOTE>
<P>Below are some examples of SQL commands for administering indexes.
</BLOCKQUOTE>
<BLOCKQUOTE>
<H4>
<FONT FACE="Arial"><B>Creating an Index to a Table</B><A NAME="I168"></A></FONT></H4>
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>CREATE INDEX &lt;index_name&gt; ON &lt;table_name&gt; 
<BR>   (&lt;column_name&gt; [ASC | DESC]);
Only the creator of the particular table or users having SYS_ADMIN_ROLE have privileges to create or delete indexes.</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<P>The following example creates an index named X_TEST on the table TEST to the column I.
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>CREATE INDEX X_TEST ON TEST (I);</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<H4>
<FONT FACE="Arial"><B>Creating a Unique Index to a Table</B><A NAME="I169"></A></FONT></H4>
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>CREATE UNIQUE INDEX &lt;index_name&gt; ON &lt;table_name&gt; 
<BR>   (&lt;column_name&gt;);</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<P>The following example creates a unique index named UX_TEST on the table TEST to the column I.
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>CREATE UNIQUE INDEX UX_TEST ON TEST (I);</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<H4>
<FONT FACE="Arial"><B>Deleting an Index</B><A NAME="I170"></A></FONT></H4>
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>DROP INDEX &lt;index_name&gt;;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<P>The following example deletes the index named X_TEST.
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>DROP INDEX X_TEST;</PRE></BLOCKQUOTE>
<BLOCKQUOTE>
<P><A NAME="I171"></A><A NAME="I172"></A><A NAME="I173"></A><A NAME="I174"></A><A NAME="I175"></A><A NAME="I176"></A><A NAME="I177"></A><A NAME="I178"></A>
</BLOCKQUOTE>

<HR ALIGN=CENTER>
<TABLE>
<TR>
<TD WIDTH=100 VALIGN=top >
<P>
<IMG SRC="gaguide/aguide16.gif" WIDTH = 24 HEIGHT = 22 ALT="Undisplayed Graphic">
<P><I>SOLID</I> SQL Editor:
<BR>
<I>Commit button</I>
</TD><TD WIDTH=600 VALIGN=top >
<BLOCKQUOTE>
<P>NOTE. If the autocommit mode is set OFF, you need to commit your work before you can modify the table on which you altered the indexes. To commit your work after modifying indexes, use the SQL statement COMMIT WORK;, or press the Commit button in SOLID <I>SQL Editor</I><A NAME="I179"></A><A NAME="I180"></A>. If the autocommit mode is set ON - this is the default in SOLID <I>SQL </I><I>Editor</I> - the transactions are committed automatically.</TD></TR></BLOCKQUOTE></TABLE></BLOCKQUOTE>
<HR ALIGN=CENTER>
<A NAME="E10E30"></A>
<P>
<FONT FACE="Arial"><B>Primary Keys</B><A NAME="I181"></A></FONT>
<BLOCKQUOTE>
<P>A primary key is a column or combination of columns that uniquely identify each record in a table. Primary keys like indexes speed up access to tables. The difference between primary keys and indexes in SOLID <I>Server</I> is that the primary key cluster<A NAME="I182"></A> data in the database according to the key values. 
</BLOCKQUOTE>
<BLOCKQUOTE>
<P>This behavior differs from the default clustering in SOLID <I>Server, </I>where the data is clustered according to the insertion time only.<A NAME="I183"></A>
</BLOCKQUOTE>
<A NAME="E10E31"></A>
<P>
<FONT FACE="Arial"><B>Foreign Keys</B><A NAME="I184"></A></FONT>
<BLOCKQUOTE>
<P>A foreign key is a column or group of columns within a table that refers to, or relates to, some other table through its values. The foreign key must always include enough columns in its definition to uniquely identify a row in the referenced table. The main reason for defining foreign keys is to ensure that rows in one table always have corresponding rows in another table; that is, to ensure that referential integrity<A NAME="I185"></A> of data is maintained.
</BLOCKQUOTE><P ALIGN=CENTER>
<A HREF="aguide04.htm" TARGET="_self"><IMG SRC="gaguide/graprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>
<A HREF="httoc.htm" TARGET="_self"><IMG SRC="gaguide/gratop.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>
<A HREF="htindex.htm" TARGET="_self"><IMG SRC="gaguide/graindex.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Index"></A>
<A HREF="aguide06.htm" TARGET="_self"><IMG SRC="gaguide/granext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>

<center><p><font SIZE=-2>Copyright &copy; 1992-1997 Solid Information Technology Ltd All rights reserved.</font></p></center></BODY></HTML>