没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Transact-SQL® User’s Guide
Adaptive Server Enterprise
12.5
DOCUMENT ID: 32300-01-1250-03
LAST REVISED: August 2002
Copyright © 1989-2002 by Sybase, Inc. All rights reserved.
This publication pertains to Sybase software and to any subsequent release until otherwise indicated in new editions or technical notes.
Information in this document is subject to change without notice. The software described herein is furnished under a license agreement,
and it may be used or copied only in accordance with the terms of that agreement.
To order additional documents, U.S. and Canadian customers should call Customer Fulfillment at (800) 685-8225, fax (617) 229-9845.
Customers in other countries with a U.S. license agreement may contact Customer Fulfillment via the above fax number. All other
international customers should contact their Sybase subsidiary or local distributor. Upgrades are provided only at regularly scheduled
software release dates. No part of this publication may be reproduced, transmitted, or translated in any form or by any means, electronic,
mechanical, manual, optical, or otherwise, without the prior written permission of Sybase, Inc.
Sybase, the Sybase logo, AccelaTrade, ADA Workbench, Adaptable Windowing Environment, Adaptive Component Architecture,
Adaptive Server, Adaptive Server Anywhere, Adaptive Server Enterprise, Adaptive Server Enterprise Monitor, Adaptive Server
Enterprise Replication, Adaptive Server Everywhere, Adaptive Server IQ, Adaptive Warehouse, Anywhere Studio, Application
Manager, AppModeler, APT Workbench, APT-Build, APT-Edit, APT-Execute, APT-FORMS, APT-Translator, APT-Library, Backup
Server, BizTracker, ClearConnect, Client-Library, Client Services, Convoy/DM, Copernicus, Data Pipeline, Data Workbench,
DataArchitect, Database Analyzer, DataExpress, DataServer, DataWindow, DB-Library, dbQueue, Developers Workbench, Direct
Connect Anywhere, DirectConnect, Distribution Director, e-ADK, E-Anywhere, e-Biz Integrator, E-Whatever, EC-GATEWAY,
ECMAP, ECRTP, eFulfillment Accelerator, Embedded SQL, EMS, Enterprise Application Studio, Enterprise Client/Server, Enterprise
Connect, Enterprise Data Studio, Enterprise Manager, Enterprise SQL Server Manager, Enterprise Work Architecture, Enterprise Work
Designer, Enterprise Work Modeler, eProcurement Accelerator, EWA, Financial Fusion, Financial Fusion Server, Gateway Manager,
GlobalFIX, ImpactNow, Industry Warehouse Studio, InfoMaker, Information Anywhere, Information Everywhere, InformationConnect,
InternetBuilder, iScript, Jaguar CTS, jConnect for JDBC, MainframeConnect, Maintenance Express, MDI Access Server, MDI Database
Gateway, media.splash, MetaWorks, MySupport, Net-Gateway, Net-Library, New Era of Networks, ObjectConnect, ObjectCycle,
OmniConnect, OmniSQL Access Module, OmniSQL Toolkit, Open Biz, Open Client, Open ClientConnect, Open Client/Server, Open
Client/Server Interfaces, Open Gateway, Open Server, Open ServerConnect, Open Solutions, Optima++, PB-Gen, PC APT Execute, PC
Net Library, Power++, power.stop, PowerAMC, PowerBuilder, PowerBuilder Foundation Class Library, PowerDesigner,
PowerDimensions, PowerDynamo, PowerJ, PowerScript, PowerSite, PowerSocket, Powersoft, PowerStage, PowerStudio, PowerTips,
Powersoft Portfolio, Powersoft Professional, PowerWare Desktop, PowerWare Enterprise, ProcessAnalyst, Rapport, Report Workbench,
Report-Execute, Replication Agent, Replication Driver, Replication Server, Replication Server Manager, Replication Toolkit, Resource
Manager, RW-DisplayLib, S-Designor, SDF, Secure SQL Server, Secure SQL Toolset, Security Guardian, SKILS, smart.partners,
smart.parts, smart.script, SQL Advantage, SQL Anywhere, SQL Anywhere Studio, SQL Code Checker, SQL Debug, SQL Edit, SQL
Edit/TPU, SQL Everywhere, SQL Modeler, SQL Remote, SQL Server, SQL Server Manager, SQL SMART, SQL Toolset, SQL Server/
CFT, SQL Server/DBM, SQL Server SNMP SubAgent, SQL Station, SQLJ, STEP, SupportNow, S.W.I.F.T. Message Format Libraries,
Sybase Central, Sybase Client/Server Interfaces, Sybase Financial Server, Sybase Gateways, Sybase MPP, Sybase SQL Desktop, Sybase
SQL Lifecycle, Sybase SQL Workgroup, Sybase User Workbench, SybaseWare, Syber Financial, SyberAssist, SyBooks, System 10,
System 11, System XI (logo), SystemTools, Tabular Data Stream, TradeForce, Transact-SQL, Translation Toolkit, UNIBOM, Unilib,
Uninull, Unisep, Unistring, URK Runtime Kit for UniCode, Viewer, Visual Components, VisualSpeller, VisualWriter, VQL,
WarehouseArchitect, Warehouse Control Center, Warehouse Studio, Warehouse WORKS, Watcom, Watcom SQL, Watcom SQL Server,
Web Deployment Kit, Web.PB, Web.SQL, WebSights, WebViewer, WorkGroup SQL Server, XA-Library, XA-Server and XP Server are
trademarks of Sybase, Inc. 07/02
Unicode and the Unicode Logo are registered trademarks of Unicode, Inc.
All other company and product names used herein may be trademarks or registered trademarks of their respective companies.
Use, duplication, or disclosure by the government is subject to the restrictions set forth in subparagraph (c)(1)(ii) of DFARS 52.227-
7013 for the DOD and as set forth in FAR 52.227-19(a)-(d) for civilian agencies.
Sybase, Inc., One Sybase Drive, Dublin, CA 94568.
Contents
Transact-SQL User’s Guide iii
About This Book......................................................................................................................... xix
CHAPTER 1 SQL Building Blocks....................................................................... 1
SQL in Adaptive Server.................................................................... 1
Queries, data modification, and commands.............................. 2
Tables, columns, and rows........................................................ 3
The relational operations........................................................... 3
Compiled objects....................................................................... 4
Naming conventions......................................................................... 6
SQL data characters ................................................................. 7
SQL language characters.......................................................... 7
Identifiers................................................................................... 7
Expressions in Adaptive Server ..................................................... 13
Arithmetic and character expressions ..................................... 13
Relational and logical expressions.......................................... 19
Transact-SQL extensions............................................................... 20
The compute clause ................................................................ 21
Control-of-flow language ......................................................... 21
Stored procedures................................................................... 21
Extended stored procedures ................................................... 22
Triggers ................................................................................... 23
Defaults and rules ................................................................... 23
Error handling and set options ................................................ 23
Additional Adaptive Server extensions to SQL........................ 25
Compliance to ANSI standards ...................................................... 27
Federal Information Processing Standards (FIPS) flagger...... 28
Chained transactions and isolation levels ............................... 28
Identifiers................................................................................. 28
SQL standard-style comments ................................................ 29
Right truncation of character strings........................................ 29
Permissions required for update and delete statements ......... 29
Arithmetic errors ...................................................................... 29
Synonymous keywords ........................................................... 30
Treatment of nulls.................................................................... 31
Contents
iv
Adaptive Server
Adaptive Server login accounts...................................................... 31
Group membership.................................................................. 32
Role membership .................................................................... 32
Getting information about your Adaptive Server account........ 33
Changing your password......................................................... 33
Understanding remote logins .................................................. 34
How to use Transact-SQL with the isql utility................................. 36
Default databases ................................................................... 36
Using network-based security services with isql ..................... 37
Logging out of isql ................................................................... 38
Using the pubs2 and pubs3 sample databases ............................. 38
What is in the sample databases? .......................................... 38
CHAPTER 2 Queries: Selecting Data from a Table.......................................... 41
What are queries?.......................................................................... 41
select syntax............................................................................ 42
Choosing columns: the select clause............................................. 44
Choosing all columns: select * ............................................... 44
Choosing specific columns...................................................... 45
Rearranging the order of columns........................................... 45
Renaming columns in query results ........................................ 46
Expressions............................................................................. 47
Selecting text and image values.............................................. 53
Select list summary ................................................................. 55
Eliminating duplicate query results with distinct............................. 55
Specifying tables: the from clause ................................................. 57
Selecting rows: the where clause................................................... 58
Comparison operators............................................................. 59
Ranges (between and not between) ....................................... 61
Lists (in and not in).................................................................. 62
Pattern matching............................................................................ 65
Matching character strings: like............................................... 65
Character strings and quotation marks ................................... 71
“Unknown” values: NULL ........................................................ 71
Connecting conditions with logical operators .......................... 77
CHAPTER 3 Using Aggregates, Grouping, and Sorting.................................. 81
Using aggregate functions ............................................................. 81
Aggregate functions and datatypes......................................... 83
count vs. count(*).................................................................... 84
Using aggregate functions with distinct................................... 85
Null values and the aggregate functions ................................. 86
Organizing query results into groups: the group by clause............ 87
Contents
Transact-SQL User’s Guide v
group by syntax....................................................................... 88
Referencing other columns in queries using group by ............ 90
Expressions and group by....................................................... 93
Nesting aggregates with group by........................................... 94
Null values and group by......................................................... 95
where clause and group by ..................................................... 96
group by and all....................................................................... 97
Using aggregates without group by......................................... 98
Selecting groups of data: the having clause .................................. 99
How the having, group by, and where clauses interact......... 101
Using having without group by .............................................. 104
Sorting query results: the order by clause.................................... 105
order by and group by ........................................................... 107
order by and group by used with select distinct .................... 107
Summarizing groups of data: the compute clause....................... 108
Row aggregates and compute .............................................. 111
Specifying more than one column after compute.................. 112
Using more than one compute clause................................... 113
Applying an aggregate to more than one column.................. 114
Using different aggregates in the same compute clause ...... 115
Grand values: compute without by........................................ 115
Combining queries: the union operator........................................ 117
Guidelines for union queries.................................................. 119
Using union with other Transact-SQL commands................. 121
CHAPTER 4 Joins: Retrieving Data from Several Tables............................. 123
How joins work ............................................................................. 124
Join syntax ............................................................................ 124
Joins and the relational model............................................... 125
How joins are structured .............................................................. 125
The from clause..................................................................... 127
The where clause .................................................................. 128
How joins are processed.............................................................. 130
Equijoins and natural joins ........................................................... 131
Joins with additional conditions.................................................... 132
Joins not based on equality.......................................................... 133
Self-joins and correlation names.................................................. 134
The not-equal join ........................................................................ 135
Not-equal joins and subqueries............................................. 137
Joining more than two tables ....................................................... 138
Outer joins.................................................................................... 140
Inner and outer tables ........................................................... 140
Outer join restrictions ............................................................ 141
Views used with outer joins ................................................... 142
剩余793页未读,继续阅读
资源评论
- eveningtime2012-06-27全英文的,看起来不大方便,10分贵了点
kikanjuu
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功