Previous Topic

Next Topic

SQL Naming and Statement Rules

This section briefly describes the SQL naming and statement rules, as well as the additional features and extensions of SQL and the database management system (DBMS).

The following statements and features enable the control of:

Previous Topic

Next Topic

Object Naming Rules

The rules for naming database objects (such as tables, columns, views, and database procedures) are as follows:

Previous Topic

Next Topic

Regular and Delimited Identifiers

Identifiers in SQL statements specify names for the following objects:

Specify these names using regular (unquoted) identifiers or delimited (double-quoted) identifiers. For example:

Delimited identifiers enable you to embed special characters in object names. The use of special characters in regular identifiers is restricted.

Note: Case sensitivity for delimited identifiers are specified when a database is created. For compliance with ANSI/ISO Entry SQL-92, delimited identifiers must be case sensitive.

Previous Topic

Next Topic

Restrictions on Identifiers

The following table lists the restrictions for regular and delimited identifiers (the names assigned to database objects):

Restrictions

Regular Identifiers

Delimited Identifiers

Quotes

Specific without quotes

Specified in double quotes

Keywords

Cannot be a keyword

Can be a keyword

Valid special characters

"At" sign (@)
(not ANSI/ISO)

Crosshatch (#)
(not ANSI/ISO)

Dollar sign ($)
(not ANSI/ISO)

Underscore (_)

Ampersand (&)
Asterisk (*)
"At" sign (@)
Colon (:)
Comma (,)
Crosshatch (#)
Dollar sign ($)
Double quotes (")
Equal sign (=)
Forward slash (/)
Left and right caret (< >)
Left and right parentheses
Minus sign (-)
Percent sign (%)
Period (.)
Plus sign (+)
Question mark (?)
Semicolon (;)
Single quote (')
Space
Underscore (_)
Vertical bar (|)
Backslash (\)
Caret (^)
Curly braces ({ })
Exclamation point (!)
Left quote (ASCII 96 or X'60')
Tilde (~)

Note: The maximum length of an identifier is 32 characters. For ANSI/ISO Entry SQL-92 compliance, identifiers must be no longer than 18 characters.

The following characters cannot be embedded in object names using either regular or delimited identifiers:

DEL (ASCII 127 or X'7F')

To specify double quotes in a delimited identifier, repeat the quotes.

For example:

"""Identifier""Name"""

is interpreted as:

"Identifier"Name"

Trailing spaces are deleted from object names specified using delimited identifiers.

For example:

create table "space test " (scolumn int);

creates a table named, space test, with no trailing blanks (leading blanks are retained).

If an object name composed entirely of spaces is specified, the object is assigned a name consisting of a single blank. For example, the following creates a table named " ".

create table "     " (scolumn int);

Previous Topic

Next Topic

Case Sensitivity of Identifiers

Case sensitivity for regular and delimited identifiers is specified at the time a database is created. By default, delimited identifiers are not case sensitive. For compliance with ANSI/ISO Entry SQL-92, however, delimited identifiers must be case sensitive.

The DBMS Server treats database, user, group, role, cursor, and location names without regard to case, and mixed-case database or location names cannot be created.

Previous Topic

Next Topic

Comment Delimiters

To indicate comments in interactive SQL, use the following delimiters:

/* and */ (left and right delimiters, respectively).

For example:

/* This is a comment */

When using /*...*/ to delimit a comment, the comment can continue over more than one line. For example:

/* Everything from here...
...to here is a comment */

The delimiter, --, indicates that the rest of the line is a comment. A comment delimited by -- cannot be continued to another line.-- (left side only).

For example:

--This is a comment.

To indicate comments in embedded SQL, use the following delimiters:

--, with the same usage rules as interactive SQL. Host language comment delimiters.

For information about comment delimiters, see the Embedded SQL Companion Guide.

Previous Topic

Next Topic

Statement Terminators

Statement terminators separate one SQL statement from another. In interactive SQL, the statement terminator is the semicolon (;). Terminate statements with a semicolon when entering two or more SQL statements before issuing the go command (\g), selecting the Go menu item, or issuing some other terminal monitor command.

In the following example, semicolons terminate the first and second statements. The third statement does not need to be terminated with a semicolon, because it is the final statement.

select * from addrlst;
select * from emp
     where fname = 'john';
select * from emp
     where mgrname = 'dempsey'\g

If only one statement is entered, the statement terminator is not required. For example, the following single statement does not require a semicolon:

select * from addrlst\g

In embedded SQL applications, the use of a statement terminator is determined by the rules of the host language. For details, see the Embedded SQL Companion Guide.

Previous Topic

Next Topic

Correlation Names

Correlation names are used in queries to clarify the table (or view) to which a column belongs or to abbreviate long table names. For example, the following query uses correlation names to join a table with itself:

select a.empname from emp a, emp b
     where a.mgrname = b.empname
     and a.salary > b.salary;

Previous Topic

Next Topic

Correlation Names Rules

Correlation names can be specified in a Select, Delete, Update, Create Integrity, or Create Rule SQL statement. The rules of using correlation names are as follows:

The DBMS Server checks the description of the sales_departments table for the mgrno and manager columns; if they are not found, it checks the employee table next, but does not check the mktg_departments table. Similarly, the DBMS Server first checks the mktg_departments table for the mgrno and manager_id columns. If they are not found, it checks the employee table, but never checks the sales_departments table.

Previous Topic

Next Topic

Database Procedures

Database procedures are compiled, stored, and managed by the DBMS Server. Database procedures can be used in conjunction with rules to enforce database integrities, or to perform frequently repeated operations. When the procedure is created, its execution plan is saved, reducing the execution overhead.

Previous Topic

Next Topic

Database Procedure Creation

Database procedures can be created interactively or in an embedded program. A database procedure can be executed in a host language program, in terminal monitor, in another database procedure, or in a 4GL program. Database procedures can also be invoked by rules. For more information, see Database Procedures and Rules in the chapter "Understanding Database Procedures, Sessions, and Events."

Previous Topic

Next Topic

Determine Settings for a Database

To determine the settings for the database to which a session is connected, use dbmsinfo(db_name_case) and dbmsinfo(db_delim_case).

For details about dbmsinfo, see Status Information

Previous Topic

Next Topic

Object Management Extension

The Object Management Extension allows data types to be created in addition to the standard SQL data types. Using the Object Management Extension, you can define operators and a function to manipulate your data types, and integrate the new data types, operators, and functions into the DBMS Server.

Previous Topic

Next Topic

ANSI Compliance

Ingres is compliant with ANSI/ISO Entry SQL-92. In addition, Ingres contains numerous vendor extensions. For embedded SQL applications, the ESQL preprocessor can be directed to flag statements in your program that are not compliant with entry-level ANSI/ISO SQL-92. For details, see the Embedded SQL Companion Guide.

Information about the settings required to operate in compliance with ANSI/ISO Entry SQL-92, can be found in the appendix "ANSI Compliance Settings."

Previous Topic

Next Topic

OpenSQL

OpenSQL is the subset of SQL statements that can be used to access non-Ingres databases through Enterprise Access products.

Previous Topic

Next Topic

Security Levels

Basic Ingres installations can be administered in compliance with the C2 security standard. The following statements are of particular interest to C2 security administrators and DBAs:

For details about administering a C2 site, see the Database Administrator Guide.


© 2007 Ingres Corporation. All rights reserved.