Chapter 1: SQL Building Blocks


About this book

This manual, the Transact-SQL User’s Guide, documents Transact-SQL®, an enhanced version of the SQL relational database language. The Transact-SQL User’s Guide is intended for both beginners and those who have experience with other implementations of SQL.

Audience

Users of the Sybase® Adaptive Server® Enterprise database management systems who are unfamiliar with SQL can consider this guide as a textbook and start at the beginning. Novice SQL users should concentrate on the first part of this book. The second part describes advanced topics.

This manual is useful both as a review, for those acquainted with other versions of SQL, and as a guide to Transact-SQL enhancements. SQL experts should study the capabilities and features that Transact-SQL has added to standard SQL, especially the material on stored procedures.

How to use this book

This book is a complete guide to Transact-SQL. It contains an introductory chapter, which gives an overview of SQL. The remaining chapters are divided into two subjects: basic concepts and advanced topics.

Chapter 1, “SQL Building Blocks,” describes the naming conventions used by SQL and the enhancements (also known as extensions) added by Transact-SQL. It also includes a description of how to get started with Transact-SQL using the isql utility. Sybase recommends that all users read this chapter.

Chapters 2–9 introduce you to the basic functionality of SQL. Users new to SQL should become familiar with the concepts described in these chapters before moving on to Chapters 10–18. Experienced users of SQL may want to skim through these chapters to learn about the Transact-SQL extensions introduced there and to review the material.

Chapters 10–18 describe Transact-SQL in more detail. Most of the Transact-SQL extensions are described here. Users familiar with SQL, but not Transact-SQL, should concentrate on these chapters.

The examples in this guide are based on the pubs2 and, where noted, pubs3 sample databases. For best use of the Transact-SQL User’s Guide, new users should work through the examples. Ask your System Administrator how to get a clean copy of pubs2 and pubs3. For a complete description of these databases, see Appendix A, “The pubs2 Database,” and Appendix B, “The pubs3 Database.”

You can use Transact-SQL with the Adaptive Server standalone program isql. The isql program is a utility program called directly from the operating system.

Related documents

The Sybase Adaptive Server Enterprise documentation set consists of the following:

Other sources of information

Use the Sybase Getting Started CD, the Sybase Technical Library CD and the Technical Library Product Manuals Web site to learn more about your product:

Sybase certifications on the Web

Technical documentation at the Sybase Web site is updated frequently.

StepsFinding the latest information on product certifications

  1. Point your Web browser to Technical Documents.

  2. Select Products from the navigation bar on the left.

  3. Select a product name from the product list and click Go.

  4. Select the Certification Report filter, specify a time frame, and click Go.

  5. Click a Certification Report title to display the report.

StepsCreating a personalized view of the Sybase Web site (including support pages)

Set up a MySybase profile. MySybase is a free service that allows you to create a personalized view of Sybase Web pages.

  1. Point your Web browser to Technical Documents.

  2. Click MySybase and create a MySybase profile.

Sybase EBFs and software updates

StepsFinding the latest information on EBFs and software updates

  1. Point your Web browser to the Sybase Support Page.

  2. Select EBFs/Maintenance. If prompted, enter your MySybase user name and password.

  3. Select a product.

  4. Specify a time frame and click Go. A list of EBF/Maintenance releases is displayed.

    Padlock icons indicate that you do not have download authorization for certain EBF/Maintenance releases because you are not registered as a Technical Support Contact. If you have not registered, but have valid information provided by your Sybase representative or through your support contract, click Edit Roles to add the “Technical Support Contact” role to your MySybase profile.

  5. Click the Info icon to display the EBF/Maintenance report, or click the product description to download the software.

Conventions

The following sections describe conventions used in this manual.

SQL is a free-form language. There are no rules about the number of words you can put on a line or where you must break a line. However, for readability, all examples and most syntax statements in this manual are formatted so that each clause of a statement begins on a new line. Clauses that have more than one part extend to additional lines, which are indented. Complex commands are formatted using modified Backus Naur Form (BNF) notation.

Table 1 shows the conventions for syntax statements that appear in this manual:

Table 1: Font and syntax conventions for this manual

Element

Example

Command names,procedure names, utility names, and other keywords display in sans serif font.

select

sp_configure

Database names and datatypes are in sans serif font.

master database

Book names, file names, variables, and path names are in italics.

System Administration Guide

sql.ini file

column_name

$SYBASE/ASE directory

Variables—or words that stand for values that you fill in—when they are part of a query or statement, are in italics in Courier font.

select column_name     from table_name     where search_conditions

Type parentheses as part of the command.

compute row_aggregate (column_name)

Double colon, equals sign indicates that the syntax is written in BNF notation. Do not type this symbol. Indicates “is defined as”.

::=

Curly braces mean that you must choose at least one of the enclosed options. Do not type the braces.

{cash | check | credit}

Brackets mean that to choose one or more of the enclosed options is optional. Do not type the brackets.

[cash | check | credit]

The comma means you may choose as many of the options shown as you want. Separate your choices with commas as part of the command.

cash, check, credit

The pipe or vertical bar( | ) means you may select only one of the options shown.

cash | check | credit

An ellipsis (...) means that you can repeat the last unit as many times as you like.

buy thing = price [cash | check | credit] [, thing = price [cash | check | credit] ]...

You must buy at least one thing and give its price. You may choose a method of payment: one of the items enclosed in square brackets. You may also choose to buy additional things, as many of them as you like. For each thing you buy, give its name, its price, and (optionally) a method of payment.

In this manual, most of the examples are in lowercase. However, you can disregard case when typing Transact-SQL keywords. For example, SELECT, Select, and select are the same.

Sensitivity to the case of database objects, such as table names, depends on the sort order installed on Adaptive Server. You can change case sensitivity for single-byte character sets by reconfiguring the Adaptive Server sort order. For more information, see the System Administration Guide.

Accessibility features

This document is available in an HTML version that is specialized for accessibility. You can navigate the HTML with an adaptive technology such as a screen reader, or view it with a screen enlarger.

This version of the Enhanced Specialty Data Store and the HTML documentation have been tested for compliance with U.S. government Section 508 Accessibility requirements. Documents that comply with Section 508 generally also meet non-U.S. accessibility guidelines, such as the World Wide Web Consortium (W3C) guidelines for Web sites.

The online help for this product is also provided in HTML, which you can navigate using a screen reader.

NoteYou might need to configure your accessibility tool for optimal use. Some screen readers pronounce text based on its case; for example, they pronounce ALL UPPERCASE TEXT as initials, and MixedCase Text as words. You might find it helpful to configure your tool to announce syntax conventions. Consult the documentation for your tool.

For information about how Sybase supports accessibility, see Sybase Accessibility. The Sybase Accessibility site includes links to information on Section 508 and W3C standards.

If you need help

Each Sybase installation that has purchased a support contract has one or more designated people who are authorized to contact Sybase Technical Support. If you cannot resolve a problem using the manuals or online help, please have the designated person contact Sybase Technical Support or the Sybase subsidiary in your area.





Copyright © 2005. Sybase Inc. All rights reserved. Chapter 1: SQL Building Blocks

View this book as PDF