1484
Sybase ® Adaptive Server Enterprise Adaptive Server Enterprise 12 ID37419-01-1200-01 1999 10

Sybase® Adaptive Server ™ Enterprise - pudn.comread.pudn.com/downloads123/ebook/524271/sybase.pdf · Server Architecture Sybase User Workbench SybaseWare SyberAssist SyBooks System

Embed Size (px)

Citation preview

  • Sybase Adaptive Server Enterprise

    Adaptive Server Enterprise 12

    ID37419-01-1200-01

    1999 10

  • Enterprise Data Studios Publications

    Anneli Meyer Evelyn Wheeler

    ID 37419-01-1200-01

    Sybase Adaptive Server Enterprise 12 !"#$%&'()*+,-

    !./0$ 123456789:;?@A

    BCD$

    EFGHI%&JKLIMNOP4QROPSTUVWX (800) 685-8225YZ[\ (617) 229-9845$

    ]^K_OP`aJK3456b4/cd1Z[efOPSTUVgh$

    ]iKjOPkf Sybaselmnopqrsgh$

    tuvwx#yYz{78$

    Copyright 1989-2001 by Sybase, Inc.|}~$

    Sybase, Inc.~Uq-Wl]^BCZ$

    Sybase

    Sybase SYBASE Adaptive Server APT-FORMS Certified SYBASE Professional Certified SYBASE Professional Column DesignComponentPack Data Workbench First Impression InfoMakerObjectCyclePowerBuilderPowerDesignerPowersoftReplication ServerS-Designor SQL Advantage SQL Debug SQL SMART Transact-SQLVisual Components VisualWriterL VQL Sybase, Inc.s$

    Adaptable Windowing Environment Adaptive Component ArchitectureAdaptive Server Enterprise Monitor Adaptive Warehouse ADA WorkbenchAnswerBase Application Manager AppModeler APT-Build APT-EditAPT-Execute APT-Library APT-Translator APT Workbench Backup Server BayCam Bit-Wise ClearConnect Client-Library Client ServicesCodeBank Connection Manager DataArchitect Database AnalyzerDataExpress Data Pipeline DataServer DataWindow DB-LibrarydbQueue Developers Workbench DirectConnect Distribution AgentDistribution Director Embedded SQL EMS Enterprise Application ServerEnterprise Application Studio Enterprise Client/Server EnterpriseConnectEnterprise Data Studio Enterprise Manager Enterprise SQL Server ManagerEnterprise Work Architecture Enterprise Work Designer Enterprise Work ModelerEWAFormula OneGateway ManagerGeoPoint ImpactNowInformationConnect InstaHelp InternetBuilder iScript Jaguar CTSjConnect for JDBC KnowledgeBase Logical Memory ManagerMainframeConnectMaintenance ExpressMAPMDI Access ServerMDI Database Gatewaymedia.splashMetaBridgeMetaWorksMethodSet

  • MySupport Net-Gateway NetImpact Net-Library Next Generation Learning ObjectConnect OmniConnect OmniSQL Access ModuleOmniSQL Toolkit Open Client Open ClientConnect Open Client/ServerOpen Client/Server Interfaces Open Gateway Open Server Open ServerConnectOpen SolutionsOptima++ PB-Gen PC APT-Execute PC DB-Net PC Net Library Power++ Power AMC PowerBuilt PowerBuilt with PowerBuilder PowerDynamo PowerJ PowerScript PowerSitePowerSocketPowersoft PortfolioPowerStudioPower Through KnowledgePowerWare Desktop PowerWare Enterprise ProcessAnalyst Replication Agent Replication Driver Replication Server Manager Report-ExecuteReport WorkbenchResource ManagerRW-DisplayLibRW-LibrarySAFESDF Secure SQL Server Secure SQL Toolset Security Guardian SKILSsmart.partnerssmart.partssmart.scriptSQL Code CheckerSQL EditSQL Edit/TPUSQL ModelerSQL RemoteSQL ServerSQL Server/CFTSQL Server/DBM SQL Server Manager SQL Server SNMP SubAgent SQL StationSQL ToolsetSybase CentralSybase Client/Server InterfacesSybase Development FrameworkSybase Financial ServerSybase GatewaysSybase Learning Connection Sybase MPP Sybase SQL Desktop Sybase SQL Lifecycle Sybase SQL Workgroup Sybase Synergy Program Sybase Virtual Server Architecture Sybase User Workbench SybaseWare SyberAssistSyBooksSystem 10System 11System XISystemToolsTabular Data Stream The Enterprise Client/Server Company The Extensible Software PlatformThe Future Is Wide OpenThe Learning ConnectionThe Model for Client/Server Solutions The Online Information Center Translation ToolkitTurning Imagination Into Reality UltraLite UNIBOM Unilib UninullUnisep Unistring URK Runtime Kit for UniCode Viewer VisualSpellerVisualWriterWarehouseArchitectWarehouse StudioWarehouse WORKSWatcomWatcom SQLWatcom SQL ServerWeb.PBWeb.SQLWebSightsWebViewerWorkGroup SQL Server XA-Library XA-ServerL XP Server Sybase, Inc.s$

    %& A]^mnLvw4kmnss$

    ABCm DFARS 52.227-7013 H>? (c)(1)(ii)DODL FAR 52.227-19(a)-(d) k>?C$

    Sybase, Inc., 6475 Christie Avenue, Emeryville, CA 94608.

  • Adaptive Server Enterprise v

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii

    Adaptive Server Enterprise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviii

    1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1 !"#$%& . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2'()*+,-. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 . . . . . . . . . . . . . . . . . . . . . . . 1-4!"# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4$% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5

    /0123 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5$&' . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5$()*) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7

    4567895 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7+,)NULL-./0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7123456 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8

    :;"5

  • vi

    Adaptive Server Enterprise 12.0

    2. Transact-SQL> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1?0> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5789 group by:;NULL? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5@ * 78 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5AB7878> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8

    67> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10CD/0ED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12C:FD/0G:FD . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12C/0D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12HI/0JK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-13/0LM / NOPQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-13RSO/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-13TU12VW56 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14XYZ[SO/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-15RXYZ\YZSO/0 . . . . . . . . . . . . . . . . . . . . . . . . . . 2-15C]^/0XYZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16C_`/0 bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16

    @A> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16LMa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17

    B> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17CD=> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19EFG> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19Db>cZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20

    HI> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20

    "JK> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22abs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23acos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24ascii . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-25asin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27atan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-28atn2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-29avg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-30ceiling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-32char . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-34charindex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-36char_length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-38col_length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-40col_name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-42

  • Adaptive Server Enterprise vii

    Adaptive Server Enterprise 12.0

    compare . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-43convert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-45cos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-49cot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-50count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-51curunreservedpgs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-53data_pgs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-55datalength . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-57dateadd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-59datediff . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-61datename . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-63datepart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-65db_id . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-68db_name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-69degrees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-70difference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-71exp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-73floor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-74getdate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-76hextoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-77host_id . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-79host_name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-80index_col . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-81index_colorder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-83inttohex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-85isnull . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-86is_sec_service_on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-87lct_admin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-88license_enabled . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-91log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-93log10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-94lower . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-95ltrim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-96max . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-97min . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-99mut_excl_roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-101object_id . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-103object_name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-104patindex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-105

  • viii

    Adaptive Server Enterprise 12.0

    pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-108power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-109proc_role . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-110ptn_data_pgs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-112radians . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-114rand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-115replicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-117reserved_pgs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-118reverse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-120right . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-121role_contain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-123role_id . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-125role_name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-127round . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-128rowcnt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-130rtrim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-132show_role . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-133show_sec_services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-135sign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-136sin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-138sortkey . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-139soundex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-141space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-142sqrt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-143str . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-144stuff . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-146substring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-148sum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-150suser_id . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-152suser_name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-153syb_sendmsg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-154tan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-156textptr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-157textvalid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-159tsequal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-160upper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-162used_pgs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-163user . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-165user_id . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-166

  • Adaptive Server Enterprise ix

    Adaptive Server Enterprise 12.0

    user_name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-168valid_name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-169valid_user . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-171

    3. !"#$"123 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-1TUdDd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-1efdghd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2iTDjkl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3mniTD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3DbopiTD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4qriTD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5E*siTD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5

  • x

    Adaptive Server Enterprise 12.0

    4. %&'Transact-SQLRSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1

    SQL92RSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4TU SQL92VWE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-6

    5. SQLSTATE()*+XY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-1Z[ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2[ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-456 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6with check option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-7

    ,-./0123456718./9:

  • Adaptive Server Enterprise xi

    1 .............................................................................................xvi

    2 R

  • xii

    Adaptive Server Enterprise 12.0

    5-6 56 .............................................................................................5-5

    5-7 .........................................................................................................................5-6

    5-8 with check option ................................................................................................5-7

  • Adaptive Server Enterprise xxiii

    Adaptive Server Enterprise Sybase Adaptive Server Enterprise Transact-SQL

    !" Transact-SQL#$ %&'()*+,%)-./012)34567 SQLSTATE89:;?@A Transact-SQLBC:DEFGHI#$J>;67KL Transact-SQLMNOPQ

    R STUVMWX@A Transact-SQLYZ[\]^

    _ ST`abcdefgbchifgbc dbccfgbc[\]^Xbcj@A Transact-SQLMUV

    ST`a-[\]^`a-kfglmno)%&p)Aq]^67r]^ST dbccdb dbccalt%&pk-s]^tkuvwxyzl{+k|}

    ;

    yz

    1`aAq%&'( !" Adaptive ServerST`a%&'(Aq%&'(@AKUVAq%&'(

    2Transact-SQL,% ST Adaptive Server,%)%&'(,%),%)%,%),%)52,%)`a,%675,%[\]^

    3-./)0122 ST@ATransact-SQL]^

    4345 ST Transact-SQL SQL925]^

  • xxiv

    Adaptive Server Enterprise Adaptive Server Enterprise 12

    5SQLSTATE^ y Adaptive Server SQLSTATE7^]^

    Adaptive Server Enterprise

    Sybase Adaptive Server Enterprisey6

    y;yk]^

    ;WWW:lGCD:]^@AWebSyBooks

    Adaptive Server X Adaptive Server7r Sybase)bc

    Adaptive Server Enterprise Adaptive Server 12k>;)~HI>;`a;PQAc

    Transact-SQL User's Guide l Transact-SQL`%&p SybaseA%&pF`aAquyz pubs2 pubs3%&p

    STFmno%&p]^yFF){)Aq%&p`a%&p6752)

    Adaptive Server Enterprise yX Transact-SQLYZ),%)bc%&'(]^uyTransact-SQL345`a--

    Performance and Tuning Guide Adaptive Server6.;y6]^PQ;%&p}))~(%&p Adaptive Server)f}670L;PQ

    X@A !" !"`aAdaptive ServerAc isql bcp

    Error Messages and Troubleshooting Guide G89^Aq`a}G

    Component Integration Services User's Guide @AAdaptive Server$=mn>;c Sybase%&pSybase%&p

    Adaptive Server Enterprise Java Java'A~ Adaptive Server%&pk%&'(Aq,%

  • Adaptive Server Enterprise xxv

    Adaptive Server Enterprise 12

    Using Sybase Failover in a High Availability System A`ak@A Sybase Adaptive Server~mno

    #! Adaptive Server $%&'( /nFk)@A Adaptive Server DTM>;

    Adaptive Server DTM>;

    XA Interface Integration Guide for CICS, Encina, and TUXEDO b X/Open XAnFo@A Sybase DTM XA

    Adaptive Server Glossary Adaptive Serverk@A

    ?@A+BC

    @A Sybase Technical Library CD Technical Library WeblG]^

    Technical Library CD$STTechnical Library CDXy DynaTextoB?]^

    Technical Library[ykTechnical Library)*

    Technical Library Webyz Product ManualsTechnical Library CD HTMLB6@A0WeboBu Technical Documents Web6 !~ Tech Info Library") Solved Cases#Sybase/Powersoft$

    : Technical Library Web%& support.sybase.com'(Electronic Support Services )*+,)-Technical Library 0}

  • xxvi

    Adaptive Server Enterprise 12

    D>E

    6+k@A.

    SQL

    SQL//01234k'5%6789:?,;~?Mjas/HM4v@MjABvv=@MCDCE%

    - 1lkFM.

    1 1\E]"^_

    `a bZ

    L]^$selectsp_configure

    %L

    $

    master

    *$ select column_namefrom table_name where search_conditions

    eUq$ compute row_aggregate (column_name)

    Ne;

  • Adaptive Server Enterprise xxvii

    Adaptive Server Enterprise 12

    MG>YZX)*"G>

    sp_dropdevice [device_name]

    7Lv)*YZ

    select column_namefrom table_name where search_conditions

    Mk5YZ"HA35I;012~JKLIAG>AqST5

    Transact-SQLYZ>?G>

    select * from publishers

    MNO>?pub_id pub_name city state ------- ------------------- ----------- -----0736 New Age Books Boston MA 0877 Binnet & Hardley Washington DC 1389 Algodata Infosystems Berkeley CA

    (3 rows affected)

    k%>?JK5I,;O& Transact-SQL5W6PQJK? SELECT) Select select

    Adaptive ServerRL%&pL-S"TJKU Adaptive Serverb Adaptive ServerV'5W52JKXY]^Z[[ k 1952) kV\]52)

  • xxviii

    Adaptive Server Enterprise 12

    Adaptive ServerM@A^_-./'(

    ,F-GHI

    4v`a% SybasejbbcdeKfgh Sybase+ij`O@AjNkl_;G}cdh Sybase+ij`hXTm Sybase@noj`

    1 2\U^_^c123

    _ d

    expression 4%*

    logical expression TRUE FALSE UNKNOWN

    constant expression `5+3ABCDE

    float_expr

    integer_expr p

    numeric_expr

    char_expr

    binary_expression binary varbinary

  • Adaptive Server Enterprise 1-1

    1 1. !" Transact-SQL%&'(%&'()fgbc[%?6'()Jfgs/p7|}yz

    %&'(' 1-1

    qrfgJ 1-2

    s)6[%%&'( 1-4

    t(-./%&'( 1-5

    %&'(~%&'( 1-7

    0u 1-9

    vw%x%&'( 1-10

    yz%x%&'( 1-13

    money%&'( 1-15

    W{|%&'( 1-16

    W{%&'( 1-18

    52%&'( 1-23

    R%}%&'( 1-26

    b%&'( 1-29

    sysname%&'( 1-30

    text image%&'( 1-31

    Aq%&'( 1-36

    J

    Adaptive ServerSTl^`a%&'(Aq%&'(timestamp sysname- 1-1l Adaptive Server%&'('4'jk~Wk%l

    1 1-1\

    e

    ;

  • 1-2

    Adaptive Server Enterprise 12

    KLMNOP

    - 1-2l`aST%&'(7r5STlxqr4%&'(fgJ]^~'Adaptive ServerKJK52A`a%&'(%&'(AJK52Aq%&'( timestamp" !"#$%1 Adaptive ServerST%&'(_3456AYSrL

    money

    Client-Libraryk

    {yL {yL'(

    Le

    C CeC`

    [ / !L / "

    sysname h#

    textL image $%&'N 255(4R)C

    P#* #*+,-./0'

    IDENTITY1L2

    1 1-2\HI !"#$%&

    fdg ! #$Eh

    ijk

    tinyint

    smallint

    int integer

    03 255

    -215 (-32,768)3 215 -1 (32,767)

    -231 (-2,147,483,648)3231 -1 (2,147,483,647)

    1

    2

    4

    numeric (p, s)

    decimal (p, s) dec

    -10383 1038 -1

    -10383 1038 -1

    23 17

    23 17

    1 1-1\lmn

    e

  • Adaptive Server Enterprise 1-3

    Adaptive Server Enterprise 12

    opk

    float (precision)

    double precision

    real

    f4

    f4

    f4

    4 8

    8

    4

    money

    smallmoney

    money

    -214,748.36483 214,748.3647

    -922,337,203,685,477.58083922,337,203,685,477.5807

    4

    8

    @A / qr

    smalldatetime

    datetime

    19005 16 1{3 20795 66 6{

    17535 16 1{3 99995 126 31{

    4

    8

    EF

    char(n) character 7 255 n

    varchar(n) char[acter] varying 7 255 j>89:

    nchar(n) national char[acter] 7 255 n * @ @ncharsize

    nvarchar(n) nchar varying, national char[acter] varying

    7 255 n

    stu

    binary(n)

    varbinary(n)

    7 255(

    7 255(

    n

    j>89:

    v

    bit 0 1 11(|% 8

    "JK

    text 7 231 -1 (2,147,483,647)(

    ; 2K?

    image 7 231 -1 (2,147,483,647)(

    ; 2K?

    1 1-2\HI !"#$%&lmn

    fdg ! #$Eh

  • 1-4

    !"#$%&'(()*+ Adaptive Server Enterprise 12

    QRS TUV1

    B89~)?6[%s%&'(%&'(6`aST%&'(k7%&pkAq%&'(

    @A create table alter tableMks%&'(

    create table [[database.]owner.]table_name (column_name datatype [identity | not null | null] [, column_name datatype [identity | not null | null]]...)

    alter table [[database.]owner.]table_name add column_name datatype [identity | null [, column_name datatype [identity | null]...

    ?

    create table sales_daily (stor_id char(4)not null, ord_num numeric(10,0)identity, ord_amt money null)

    @A~Ffgbck+6s%&'(

    declare @variable_name datatype [, @variable_name datatype]...

    ?

    declare @hope money

    !"#

    @A~fgbck[%s%&'(

    create procedure [owner.]procedure_name [;number] [[(]@parameter_name datatype [= default] [output] [,@parameter_name datatype [= default] [output]]...[)]][with recompile] as SQL_statements

  • Adaptive Server Enterprise 1-5

    Adaptive Server Enterprise 12 ,-+./0()*+

    ?

    create procedure auname_sp @auname varchar(40) as select au_lname, title, au_ord from authors, titles, titleauthor where @auname = au_lname and authors.au_id = titleauthor.au_id and titles.title_id = titleauthor.title_id

    $%

    B_;s5%&'( Adaptive ServerX525~ varcharO& E2%55~ floatrX%55j~w%5

    b 231 - 1 -231{)_J%5~ integer

    J%b%qr5~ numeric

    E float

    WX

    BL_%&'(xtMW Adaptive Server89wNO%&'()v

    $&'

    4v`a%&'(j%&3f systypes`a-kAq%&'(lrX`a%&'(

    %&pk%&'(lG>]^NOuyz%&pkAq%&'(]^

    select name,hierarchyfrom systypesorder by hierarchy

  • 1-6

    ,-+./0()*+ Adaptive Server Enterprise 12

    name hierarchy----------------------------- ---------floatn 1float 2datetimn 3datetime 4real 5numericn 6numeric 7decimaln 8decimal 9moneyn 10money 11smallmoney 12smalldatetime 13intn 14int 15smallint 16tinyint 17bit 18varchar 19sysname 19nvarchar 19char 20nchar 20varbinary 21timestamp 21binary 22text 23image 24(28 rows affected)

    %&'(l@A_%&'(xX%MNOXxy-+%&'(

    >?k0 sales- qty0 roysched- royalty qty smallint~ 16 royalty intr~15tNO%&'( int

    smallint(qty) * int(royalty) = int

  • Adaptive Server Enterprise 1-7

    Adaptive Server Enterprise 12 123()*+456723()*+

    $()*)

    L numeric decimal%&'(;v04jv_ Adaptive Server%&'(OLv numericdecimalxMM

    n1v p10 s1D

    n2v p20 s2

    Adaptive ServerXwNOv0- 1-3X>

    YZJ[\]^ZJ

    1%&'(%&'(j1 Adaptive Server0FHI!/;r89Aconvert) inttohex hextoint,%w Adaptive ServerX%&'(]^[ 2Transact-SQL,% k%&'(,%

    +,) NULL-./0

    %&'(;fgxBUV%&'( NULLWAdaptive Server0r~%&'( Adaptive Server_Aq%&'(V

    1 1-3\wxywzi{":{

    yw i{ :{

    n1 + n2 max(s1, s2) + max(p1 -s1, p2 - s2) + 1 max(s1, s2)n1 - n2 max(s1, s2) + max(p1 -s1, p2 - s2) + 1 max(s1, s2)n1 * n2 s1 + s2 + (p1 - s1) + (p2 - s2) + 1 s1 + s2n1 / n2 max(s1 + p2 + 1, 6) + p1 - s1 + p2 max(s1 + p2 -s2 + 1, 6)

  • 1-8

    123()*+456723()*+ Adaptive Server Enterprise 12

    - 1-4lX~%&'(~I%&'( moneyn"34%&'(_;@AKUV)6[%

    123456

    arithabort)*lFM89WAdaptive ServerHv arithabort)*arithabort arith_overflow arithabort numeric_truncation"F_'(M89B6'?4v)*7A'v set arithabort on set arithabort offMHv)*

    G//%&'(bck arithabort arith_overflowF89v~H'(89\]~ arithabort arith_overflow on89vnO_ynFlH89 arithabort arith_overflow on_Fk6 YZD Adaptive Server_Fk89MM

    Ol arithabort arith_overflow off Adaptive Serverku89MFnFkrM

    arithabort numeric_truncationl/%&'(bckvw%x%&'(0~G/u0WNO;_"\]~ arithabort numeric_truncation onku89MFnFkrMO~ arithabort numeric_truncation off Adaptive ServerNO%F

    arithignore)*lF89 Adaptive ServerRG>^\] arithignore)*~ offH6@ Adaptive Serveru%5G>^O:PQ89Z@A set arithignore on

    1 1-4\|}{~67

    |}{ 678

    char varchar nchar nvarchar binary varbinarydatetime datetimn float floatn int smallintL tinyint intn decimal decimaln numeric numericnmoneyL smallmoney moneyn

  • Adaptive Server Enterprise 1-9

    Adaptive Server Enterprise 12 892:;

    arithabort arithignore 10.0 !"#$%&'()*+,-./012345678$

    _Z`a

    :; 5

  • 1-10

    ()*+ Adaptive Server Enterprise 12

    vw?->v%x:W@Avw%x%&'(Adaptive Server~%J%+%xjSTvw%x'(

    Adaptive ServerSTl_vw%x%&'(fg%intinteger") smallint tinyintZ:fg%5J)-%'(*+fgJ'(;X_- 1-5X>

    %%&~2%5O&:J%%5{+~ 0%%&'(6yJ% smallint integer%&'( 6) tinyint%&'( 6)

    - 1-6G>l%&'(~ integerIeDl isqlG>HI%x/

    1 1-5\

    #$#$Eh

    int[eger] -231L 231 - 1-2,147,483,648L 2,147,483,647BC$

    4

    smallint -215L 215 -1-32,768L 32,767BC$

    2

    tinyint 0L 255BC$-3D$

    1

    1 1-6\k

    k bk

    2 2+2 2-2 -22. 22.000 2

  • Adaptive Server Enterprise 1-11

    Adaptive Server Enterprise 12 ()*+

    - 1-7l integerIe

    Adaptive Server~J%%5STlvw%x%&'(numeric dec[imal]E numeric decimalkfg%&634{MMvw3fblvnumeric decimal%&'(vj0~ 0 numeric%&'(;

  • 1-12

    ()*+ Adaptive Server Enterprise 12

    decimal numeric%&~v )Dyv)J%%5O&O%xl~Xv0 Adaptive Server89^0~ 0vw%x'(G>W2J%

    - 1-8G>l%&'(~ numeric(5,3)IeDl isqlG>HI%x/

    - 1-9G>l%&'(~ numeric(5,3)Ie

    1 1-8\&k

    k bk

    12.345 12.345

    +12.345 12.345

    -12.345 -12.345

    12.345000 12.345

    12.1 12.100

    12 12.000

    1 1-9\&k

    k

    1,200 -3e$

    12- DekD =$

    12.345678 EHG c$

    :; 5

  • Adaptive Server Enterprise 1-13

    Adaptive Server Enterprise 12 ?@(>()*+

    @Ayz%x'( float) double precision realAIMMbck;%5WfJ tS!yz%x :@AHI%&'(B89FGK}

    WG>v%NOXfg%5_{;DXfg%5AqXO&%5_{%Xfg->yc

  • 1-14

    ?@(>()*+ Adaptive Server Enterprise 12

    - 1-10G>l4yz%x'(qrfgJZ isqlG>J% 6b%5&%5

    !

    yz%x%&~v)%%O&

    %v2%2%662J%R%}vl%kXR%}bb%

    %652e E BD89v%

    eX->x

    mantissa * 10EXPONENT

    ? 2.4E3-> 2.46 103 2400

    1 1-10\opk

    #$Eh

    float[(default precision)] default precision< 16 4default precision >= 16 8

    double precision 8

    real 4

    :; 5

  • Adaptive Server Enterprise 1-15

    Adaptive Server Enterprise 12 money()*+

    money

    @A money smallmoney%&'(fg%&B6HI'(Ar%} Adaptive Server2ST~B6 moneysmallmoney%&A moduloXMM67X,%

    %

    money smallmoneyjvw'bG>WK&~bJ%\]Os/4_bv

    "#

    - 1-11Nlmoney%&'(qrfg:

    &'!

    O& E2xG~ floatve~ money smallmoneyxfgW;uee~Iv

    O& money smallmoneyxW6 26_?2 ($))2 ()2 ()O:O&xZ2vek_:y

    1 1-11\money

    !#$Eh

    money J +922,337,203,685,477.5807L -922,337,203,685,477.5808

    8

    smallmoney J +214,748.3647L-214,748.3648

    4

    :; 5

  • 1-16

    ABC()*+ Adaptive Server Enterprise 12

    LC: Client-LibraryAc]^[/ "k-srk@AAq timestamp%&'(4VW Adaptive Server timestampv-; timestamp%&'(

    (

    timestampv1 Adaptive ServerST)Aq%&'(~ varbinary(8) NULLC: 85Wfg{~timestampAq%&'(X6B_;ArAq%&'(B_; sum avg,%k@A timestamp%&'(

    h SQL0 timestamp%&'(_ Transact-SQL timestamp%&'(_3fW{]^D_;=W{timestamp3fl'zX>R%}'(%&

    timestamp ------------------ 0x0001000000000e51

    )* timestamp+

    OBUVlvS~ timestamp2r%&'(Adaptive Server~ timestamp%&'(

    create table testing (c1 int, timestamp, c2 int)

    B6w? timestamp%&'(S~ timestamp

    create table testing (c1 int, timestamp timestamp, c2 int)

    7S!

    create table testing (c1 int, t_stamp timestamp,c2 int)

    B6UVvS~ timestamp~r%&'(HZreAqYtD_ Open Clientktsequal,%@A browse,%"

    create table testing (c1 int, timestamp datetime)

  • Adaptive Server Enterprise 1-17

    Adaptive Server Enterprise 12 ABC()*+

    :; 5

  • 1-18

    DEAB()*+ Adaptive Server Enterprise 12

    @A datetime smalldatetime%&'(fgLW{]^

    Adaptive ServerSTHI%&'(AfgR%}'(]^

    "#,-

    - 1-12Nl datetime smalldatetime%&'(qrfg:

    datetime smalldatetime

    datetime smalldatetime%&'(1v+67br W{+=B6]Q6]QW{77j]Q" datetime smalldatetimexj89A'xxz

    datetime63f 1753 1 1 9999 12 31{

    W{{ datetimex6vw1/300fgJ~ 85W45WAfg0 1900 1 1

    H6% 45WAfgW{

    smalldatetime63f 1900 1 1 2079 6 6

    rvw6vwfgJ~ 45W25WAfg0 1900 1 16% 25WAfg06%

    datetime. smalldatetime!/0123

    yz)D6As/O&

    B6v~ 4b) 6b 8b252O&6{@AL (/))52 (-)M (.)2

    1 1-12\e#$@A"qr Transact-SQL

    !#$Eh

    datetime 17535 16 1{\ 99995 126 31{ 8

    smalldatetime 19005 16 1{\ 20795 66 6{ 4

  • Adaptive Server Enterprise 1-19

    Adaptive Server Enterprise 12 DEAB()*+

    - ~252O&WXHAs/A52Z'v%5b) OO&s/89;ZcGu89

    - O&2WZ@A set dateformat)*X6OA52kv6b%5 Adaptive Server52G~yyyy-mm-dds/

    ~Is/6 2b%5 (yy) 50

    G~ 19yyIJ 50G~ 20yy

    B6~%56r~S!S7rEK;D6AK)JKJKt/O&

    O]Ql datetime smalldatetimex+ Adaptive Server@A\] 1900 1 1

    - 1-13lO& datetime smalldatetimex+W6s/

    1 1-13\datetime" smalldatetime@A3

    @A3 d

    -q 4 KLM yyyy${y0"#5N 16 1{$

    1947 19475 16 1{

    -q 6 KLM yymmdd$`O yy < 50/5N20yy$`O yy >= 50/5N19yy$

    450128

    520128

    20455 16 28{

    19525 16 28{

    -q 8 KLM yyyymmdd$ 19940415 19945 46 15{

    P 2 6N{L5N^QKRST

    d1eI

    $

    dateformatL language setU#-yV{yq

    W$ us_englishXY0W mdy$

    `O yy < 50/5NZKLM 20yy$`O yy >= 50/5NZKLM 19yy$

    4/15/944.15.944-15-9404.15/94

    o dateformatK[\ mdyB]>8^

    KLM 1994546 15{$

    P 2 6N 2 {L 4 5N^QKRSTed1

    eI

    $

    dateformatL language setU#-yV{yq

    W$ us_englishXY0W mdy$

    04/15.1994 o dateformat[\ mdy^KLM

    19945 46 15{$

  • 1-20

    DEAB()*+ Adaptive Server Enterprise 12

    datetime. smalldatetime!/4523

    datetime smalldatetimexW{=89X

    hours[:minutes[:seconds[:milliseconds]] [AM | PM]

    12AM-> 12PM->k

    W{x89yv7 AM PM0 AM PM; 12:30bR12:30:20.1 -> 12:30bR

    O]Ql datetime smalldatetimexW{+ Adaptive Server@A\]W{ 12:00:00:000AM

    datetime smalldatetime!/678

    datetime smalldatetimexG>s/Mon dd yyyy hh:mmAM PM "?Apr 15 1988 10:23PM :G>%%/6Z@Aconvert,%%&~52 Adaptive Server;&x

    6N_4

    `6Nb4]

    abcd

    4e$

    `O5N 4 /{yq4W

    $

    April 15, 19941994 15 apr1994 April 1515 APR 1994

    B]>8^K

    LM 19945 46 15{$

    `O-{/;

  • Adaptive Server Enterprise 1-21

    Adaptive Server Enterprise 12 DEAB()*+

    - 1-14l datetimee7rG>xI>?

    9:;?@/ datetime!

    @A like5h~/ O@AM2 (=)!w~) datetimexAdaptive Server~W{" 12:00:00:000AMI%x

    ?O%x9:20 #&S~ arrival_timee~Jan 1 1900 9:20AM OB@AM2He_F

    where arrival_time = "9:20" /* does not match */

    $A likeM2B6e

    where arrival_time like "%9:20%"

    @A likeW Adaptive ServerDE~ datetimes/,%~ varcharG>s/yzA -> 3v52)A-> 2v52)A-> 4v52)67AJWAM PM ->W{

    A like!wWB_;@AO& datetime smalldatetimex+WX;HAO&s/~0G>s/_yz%%X6B_;@A like /!w%%Bu@Al style 9 10967 convert,%

    OB@Al likeDb 1 9{v%xZ{#&vs6t datetimex varcharOJW%J 10NOJW{vs@M

    like May 2%

    May 2 {vs" 5 20 5 29

    X;_ 5 21 datetimexL like&~ varchartB9r&k#&'s@A likeWC:H(

    1 1-14\datetimebZ

    bk

    1947 Jan 1 1947 12:00AM

    450128 12:30:1PM Jan 28 2045 12:30PM

    12:30.1PM 450128 Jan 28 2045 12:30PM

    14:30.22 Jan 1 1900 2:30PM

    4am Jan 1 1900 4:00AM

  • 1-22

    DEAB()*+ Adaptive Server Enterprise 12

    A01

    B6@A*+,%L datetimex%~IMM[ 2Transact-SQL,% k,%

    :; 5

  • Adaptive Server Enterprise 1-23

    Adaptive Server Enterprise 12 FG()*+

    52%&'(Afg5))%5252L*us_englishH'5W52@A%&'(char(n)%&'( varchar(n)L*H5W52@A%&'( nchar(n)%&'( nvarchar(n)52%&'(6fg 255v52Lb255v5252@A text%&'(text image%&'( k"

    B

    @A n~%&'( char(n) nchar(n)52JeA+,-e_ setYZ string_rtruncation)*~on"xf*+~

    @A n~%&'( varchar(n) nvarchar(n)52k%&./+fgJO&%&6[%k%&34{++_,0X525~%&'(

    &CAfg{61?Lr%- 1-15Nl_52%&'(fg:

    1 1-15\EF

    #$ #$Eh

    char(n) (j k#9:`lm|neopq$

    n

    nchar(n) (j k#9: n * @ @ncharsize

    varchar(n) (j 4*9:`$

    j

    nvarchar(n) (j 4*9: j* @ @ncharsize

  • 1-24

    FG()*+ Adaptive Server Enterprise 12

    CDE%+B

    @A char_length52,% datalength`a,%w

    char_length~%&'(l.r+k52%

    datalength~fgk%&l.r+5W%

    s charx~W SQL Server*+rfg~ varchar

    FG

    5289A'xxxO@Al set quoted_identifier onZ'xA52R Adaptive Serverr~012

    x5252A'xrx'x5252Axrx?

    George said,"There must be a better way.""Isn't there a better way?"

    Bu6)-rL:52kyz4vxO&vx?

    "George said, ""There must be a better way.""Isnt there a better way?

    O:@v52234Z O&5L (\)

    AHI

    >?UVlvS~ spaces-sW652

    create table spaces (cnot char(5) not null, cnull char(5) null, vnot varchar(5) not null, vnull varchar(5) null, explanation varchar(25) not null) insert spaces values ("a", "b", "c", "d", "pads char-not-null only") insert spaces values ("1 ", "2 ", "3 ", "4 ", "truncates trailing blanks") insert spaces values (" e", " f", " g", " h", "leading blanks, no change")

  • Adaptive Server Enterprise 1-25

    Adaptive Server Enterprise 12 FG()*+

    insert spaces values (" w ", " x ", " y ", " z ", "truncates trailing blanks") insert spaces values ("", "", "", "", "empty string equals space" ) select "[" + cnot + "]", "[" + cnull + "]", "[" + vnot + "]", "[" + vnull + "]", explanation from spaces

    explanation ------- ------- ------- ------- -------------------- [a ] [b] [c] [d] pads char-not-null only [1 ] [2] [3] [4] truncates trailing blanks [ e] [ f] [ g] [ h] leading blanks, no change [ w ] [ x] [ y] [ z] truncates trailing blanks [ ] [ ] [ ] [ ] empty string equals space

    (5 rows affected)

    >?7l%&'('(8AwF+Tm/

    char not null nchar not null6,0vchar null~ varchar; nchar null~ nvarchar

    +_PQ

    l char nchar not null+

    52 ("")'vsF char nchar not nullkNOvm

    AFG

    B6@A like5!w52652Fr**+52,%1%5=52@A convert,%r~vwyz%x%&'(6AMM

    :; 5

  • 1-26

    HIJ()*+ Adaptive Server Enterprise 12

    @AR%}%&'( binary(n) varbinary(n)A9%}/2fg 2555WBR%}%&"

    JK/ Binary VarbinaryLM

    R%}%&6520x B6yz%5 A FJK5)

    @A n65W~'b@A\] 15W45Wfg 2vR%}bOO&lv n%xAdaptive Server_G>8]^e~

    LrkXejI%&;@AR%}'( binary(n)

    L%&;@AR%}'(varbinary(n)

    1 binarykeA,06. (n)tK;C:CA& varbinarykefg{r:1

    N imageCOPO 255FQ/LM

    @A image%&'(R%}%&J~ 2,147,483,6475W"fg+%B_; image%&'(A6fgbck[%]^[text image%&'( W

    RST/A

    X binary not nulljA,;v1x89~tX varbinary%& binary nullkj

    >?A binary varbinary%&'({+67 NULL NOT NULLUVlv-s{+kj#&l%&

  • Adaptive Server Enterprise 1-27

    Adaptive Server Enterprise 12 HIJ()*+

    create table zeros (bnot binary(5) not null, bnull binary(5) null, vnot varbinary(5) not null, vnull varbinary(5) null)

    insert zeros values (0x12345000, 0x12345000, 0x12345000, 0x12345000)insert zeros values (0x123, 0x123, 0x123, 0x123)

    select * from zeros

    bnot bnull vnot vnull ------------ --------- ---------- --------- 0x1234500000 0x123450 0x123450 0x123450 0x0123000000 0x0123 0x0123 0x0123

    ~4vfg5W3fl 2vR%}bX6 Adaptive Server=R%}ey>%v%50x 52O0x ?%v%5 Adaptive Server@B]Ql 0BA 0

    O&x0x00 0x0 60x00 //fgR%}binary null) image varbinary"kR%}(binary not null)k%xA 0,0;.mv

    insert zeros values (0x0, 0x0,0x0, 0x0)

    select * from zeros where bnot = 0x00

    bnot bnull vnot vnull ---------- ------ ----- ------------0x0000000000 0x00 0x00 0x00

    OO&%x_yz0x Adaptive Server@%x~vASCIIxLr%?

    create table sample (col_a binary(8))

    insert sample values ('002710000000ae1b')

    select * from sample

    col_a ------------------ 0x3030323731303030

  • 1-28

    HIJ()*+ Adaptive Server Enterprise 12

    UV>W

    O&~vxws/UBX@Atp7R%}%&M;_MN_NO

    B_; sum avg,%k@AR%}%&'(

    L9%}52%{)@Ainttohex hextoint,%;_B,%]^[ 2Transact-SQL,% k%&'(,%

    :; 5

  • Adaptive Server Enterprise 1-29

    Adaptive Server Enterprise 12 K()*+

    bit%&'(AyC / @ / R'(%&syscolumns`a-k status~ bit%&'(>lDEb

    N bit+

    bit3f 0 16 0 1r%xBHI%xG~ 1

    fgJ~ 15W-kv bit%&'(F5Wk? 7 bitCA 1v5W; 9 bit:CA 2v5W

    XY

    %&'(~ bit_;~ NULLDrk_;wx

    :; 5

  • 1-30

    sysname()*+ Adaptive Server Enterprise 12

    sysname

    sysnameAq%&'( Adaptive Server`a-k@A~

    varchar(30) "not null"

    ZC sysname

    B_;v)[%6s~ sysname'(6Asysname'(UVAq%&'(,B6AHAq%&'()[%6l

    :; 5

  • Adaptive Server Enterprise 1-31

    Adaptive Server Enterprise 12 text image()*+

    text image

    text63f 2,147,483,647 (231 - 1)5W52

    image63f 2,147,483,647 (231 - 1)5W9%}/%&

    ( text. image+

    B6*r@A create table alter tableM text image text image%&'(_yzKxfs/

    column_name {text | image} [null]

    ?L6vx text (blurb) pubs2%&p;6Ark7 blurbs- create tableM

    create table blurbs(au_id id not null,copy text null)

    :6v image pubs2%&pkUV au_pix-

    create table au_pix(au_id char(11) not null,pic image null,format_type char(11) null,bytesize int null,pixwidth_hor char(14) null,pixwidth_vert char(14) null)

    Adaptive Server[\ text image

    Adaptive Server text image%&fg%v-k--r+G4v text image#6fg 18005W%&_-kyl text image-kX text image%&jfg'v#k

    N]^/_`abcde

    B6A sp_placeobject text image%_HIJ

  • 1-32

    text image()*+ Adaptive Server Enterprise 12

    Tfg

    J 2555W?%v9%}b imagexA ,0#&0xaaabb ~0x0aaabb "

    9:;< 255=>?=1@ imageA1BC

    3hi/jkJlm

    B6@A alter tableYZ partition)*Ly text image-%TL-%T~-krUV'#)*PQ text imagefg/

    K#&vx text image_BB~4v text image%&xv%u-kUVvK text image%&bL

    ?6MUV- testtextb#&vxB blurbFvLDv2K%

    create table texttest (title_id varchar(6), blurb text null, pub_id char(4))

    insert texttest values ("BU7832", "Straight Talk About Computers is an annotated analysis of what computers can do for you:a no-hype guide for the critical user.", "1389")

    6M~ imagexUVv-L image%B

    create table imagetest (image_id varchar(6), imagecol image null, graphic_id char(4))

    insert imagetest values ("94732", 0x0000008300000000000100000000013c, "1389")

  • Adaptive Server Enterprise 1-33

    Adaptive Server Enterprise 12 text image()*+

    DEF textAGGHI>& imageAJKLMN0xO

    A Client-Libraryc#& text image%&]^[ Client-Library/C Reference Manual

    nopqH!rsQtH5

    ~lW] text imagefg{Zr~xf@A #& (insert)x#&vx_B text imaget_UVL 2K5Wfg{?6M%x#&UV testtext- title_idpub_idk_B blurb

    insert texttest(title_id, pub_id) values ("BU7832", "1389")

    text imageMNvxByv%xb~_r%

    u sysindexesvwxy

    4v text image- sysindexeskjv'STHI]^ sysindexesk name@Atablename -' indidB~ 255HISTlfg]^

    B6 sysindexes-HI]^?Ol pubs2%&pk blurbs-X@A%%e

    select name, data_pgs(object_id("blurbs"), ioampg)from sysindexeswhere name = "tblurbs"

    name------------------------------ ----------- tblurbs 7

    1 1-16\"JK#$

    ) (

    ioampg "r%stqus"

    first "r%es"

    root "rs"

    segment v}e

  • 1-34

    text image()*+ Adaptive Server Enterprise 12

    ZC readtext writetext

    B;

  • Adaptive Server Enterprise 1-35

    Adaptive Server Enterprise 12 text image()*+

    ~ text image

    B6@A convert,%G/? textx~ char varcharimagex~ binary varbinary52R%}%&'(:}~ 2555WOx\]30v5W"_/

    text/=?@

    @A patindex,%!w text)varchar chark~/FABb2U89b/ !wvv52"

    B6@A like5!w/>?1 blurbs-copyk)-l4vy/Net Etiquette text%&x

    select copy from blurb where copy like "%Net Etiquette%"

    K text image%&LD?01l4t text image%&-_;yX text image%&~NULLOHL_B

    @ @textobjid DK @ @textptr}$

    @ @textsize set textsizeo="#-P select~T text imageN9:( $^032K$ @ @textsizeNN 231 - 1 2,147,483,647$

    @ @textts P @ @textptr}%$

    :; 5

  • 1-36

    LM()*+ Adaptive Server Enterprise 12

    Aq%&'(V`a%&'( sysnameHAq%&'(UVlAq%&'(B6@A)[%61Aq%&'(;UVLHAq%&'(3)\]x)'( IDENTITYVAq%&'(X`a%&'(\]x'(

    r model)*C

    Aq%&'(89:@A4v%&pkUVmodel%&pkUVA'(UV4v%&pWHI'(0ArkyzAWW- tempdb"

    )*C(/

    Adaptive ServerB`a%&'(A sp_addtype`abcUVAq%&'(B_;Aq%&'( pubs2%&pk timestamp tid%&'("UVAq%&'(

    sysname%&'(3v?X, sysnameAq%&'(B6AVAq%&'(

    Aq%&'(%&pLrS!TJKD89YZ0123

    B6A sp_bindrule3[Aq%&'(Asp_bindefault[\]x

    \]Aq%&'(;VLlAq%&'('( IDENTITYVB6k'( IDENTITYV

    C(/

    @A sp_renameYSAq%&'(

    C(/

    @A sp_droptypeAq%&'(%&pk\

  • Adaptive Server Enterprise 1-37

    Adaptive Server Enterprise 12 LM()*+

    PQRSTU&V)*WXY

    vwJW/

    @A sp_help`abcG>`a%&'(Aq%&'(V]^6A sp_help G>-k4%&'())v0

    :; 5

  • 1-38

    LM()*+ Adaptive Server Enterprise 12

  • Adaptive Server Enterprise 2-1

    2 Transact-SQL+ 2. !" Transact-SQL,%HI,%A%&pk]^ select-k where@Mk676@A-./?j6@AHI,%KAfgbcc+

    - 2-1 Transact-SQL,%_'(,%]^'(

    - 2-25)lHI,%

    1 2-1\Transact-SQL>

    > (

    jI EB]O HI.i$

    x! / '("#$

    {y 4 datetimeL smalldatetime]{yq$

    /$$

    y1 fy1'($

    CL.$

    h# '($

    %L 78 textL image /$$

    1 2-2\Transact-SQL>)1

    > k

    abs $

    acos "#:$

    ascii e ASCIIq$

    asin "#:$

    atan "#:$

    atn2 "#L:$

  • 2-2 Transact-SQL

    N(*+ Adaptive Server Enterprise 12

    avg jI -$

    ceiling N7"#$

    char 7$

    charindex \$

    char_length $

    col_length h# #*9:$

    col_name h# "# IDL ID$

    convert !]^ datetime"#$

    cos "#:$

    cot "#:$

    count jI -'$

    curunreservedpgs h# "# 4s$

    data_pgs h# "#}s$

    datalength h# "#j9:($

    dateadd {y r"#{yI#5:L]^{yq{y$

    datediff {y C{y$

    datename {y datetime "#q$

    datepart {y datetime "#q$

    db_id h# "# IDe$

    db_name h# "# IDe$

    degrees "#:N:$

    difference C soundex$

    exp e"#$

    floor 7"#N$

    getdate {y o=h#{yL$

    hextoint f"#C7$

    host_id h# OP ID$

    host_name h# OPo=$

    index_col h# "# }$

    1 2-2\Transact-SQL>)1lmn

    > k

  • Adaptive Server Enterprise 2-3

    Adaptive Server Enterprise 12 N(*+

    inttohex f"#7C$

    isnull h# o expression1NULL expression2 "#$

    is_sec_service_on y1 yST10$

    lct_admin h# m$

    license_enabled h# 13410$

    log "#>$

    log10 "# 10$

    lower "#7Nc$

    isnull ='"#$

    max jI N$

    min jI $

    mut_excl_roles h# C1$

    object_id h# "# ID$

    object_name h# "# ID$

    patindex %L

    "#ei \$

    pi 3.1415926535897936$

    power "##$

    proc_role h# P.c 1P- 0$

    ptn_data_pgs h# qs$

    radians "#:N:$

    rand 0L 1A"#$

    replicate "#B#$

    reserved_pgs h# qu"#}s$

    reverse ]"#$

    right E3"#Uq$

    role_contain h# o role2 role1 1$

    role_id h# "#]h# ID$

    role_name h# "#]h# ID$

    round "#3# $

    1 2-2\Transact-SQL>)1lmn

    > k

  • 2-4 Transact-SQL

    N(*+ Adaptive Server Enterprise 12

    6W!"HI,%'(r+5)ST,%

    rowcnt h# "# .4$

    rtrim '"#$

    show_role h# o=+$

    show_sec_services y1 Po=+yST$

    sign "#e+1 0 -1D$

    sin "#:$

    soundex Y 4q$

    space P"#('$

    sqrt "#$

    str "#7$

    stuff "#B]!$

    substring ! "#$

    sum jI L$

    suser_id h# STP sysloginsh# IDe$

    suser_name h# o=STP"#STP IDP$

    tan "#:$

    textptr %L "r"# texts"$

    textvalid %L "r"# text" 1 0$

    tsequal h# timestampB`O.K .@c-Z4]x$

    upper "#7Nc$

    used_pgs h# "#]j}s$

    user h# o=STP$

    user_id h# "#Po=P IDe$

    user_name h# "#Po=P $

    valid_name h# "#- 0D 0$

    valid_user h# o"# IDD Adaptive Serverd\ P 1$

    1 2-2\Transact-SQL>)1lmn

    > k

  • Adaptive Server Enterprise 2-5

    Adaptive Server Enterprise 12 O-N(

    bX

    ,%=]:xHIxNOkG>~,%yz

    avg

    count

    max

    min

    sum

    ,%A select- selectM@ having@MK_;A where@M

    k4vj0-tvX@A_bvk-% (12)

    ,%A char%&'(xW\.X+Hx/?~ varchar

    789 group by:; NULL?

    ,%AMkx]:xO ansinull)*~ off\]"^,%xW_Oansinull~ on^,%xW6SQLSTATE

    Warning- null value eliminated in set function set

    @ * 78

    ,%Av-kXtW='vxH06,%A-./kxX@A group by / having@M"tW~4v=vxH`6,%NOG>~

  • 2-6 Transact-SQL

    O-N( Adaptive Server Enterprise 12

    6`6ab06k?

    select type, avg(price), avg(avg(price)) from titlesgroup by type

    type ------------ ------------ ------------ UNDECIDED NULL 15.23 business 13.73 15.23 mod_cook 11.49 15.23 popular_comp 21.48 15.23 psychology 13.50 15.23 trad_cook 15.96 15.23

    (6 rows affected)

    group by@MA`6?k~ avg(price)"06avg(avg(price)) titles-k'(Mcdscx

    0 SQLkO select_listyz^X select_listj89,%AHI7XHIj89b group by-k Transact-SQL2H}

    >? 1G>v0} selectM>? 2G>*A select- (title_id)M~lG>uAl order byHI' 6A having@MxA

    1. select type, avg(price), avg(advance) from titlesgroup by type

    type ------------ ------------ ------------ UNDECIDED NULL NULL business 13.73 6,281.25 mod_cook 11.49 7,500.00 popular_comp 21.48 7,500.00 psychology 13.50 4,255.00 trad_cook 15.96 6,333.33 (6 rows affected)

    2. select type, title_id, avg(price), avg(advance) from titles group by type order by type

  • Adaptive Server Enterprise 2-7

    Adaptive Server Enterprise 12 O-N(

    type title_id ----------- -------- ---------- --------- UNDECIDED MC3026 NULL NULL business BU1032 13.73 6,281.25 business BU1111 13.73 6,281.25 business BU2075 13.73 6,281.25 business BU7832 13.73 6,281.25 mod_cook MC2222 11.49 7,500.00 mod_cook MC3021 11.49 7,500.00 popular_comp PC1035 21.48 7,500.00 popular_comp PC8888 21.48 7,500.00 popular_comp PC9999 21.48 7,500.00 psychology PS1372 13.50 4,255.00 psychology PS2091 13.50 4,255.00 psychology PS2106 13.50 4,255.00 psychology PS3333 13.50 4,255.00 psychology PS7777 13.50 4,255.00 trad_cook TC3218 15.96 6,333.33 trad_cook TC4203 15.96 6,333.33 trad_cook TC7777 15.96 6,333.33

    group by6@ASr-./0}S

    "

    group bykx'vk

    selectMk compute@M@A=]:x@A6bvYZew]:>? 3lH>;3. select type, title_id, price, advance

    from titleswhere type = "psychology" order by type compute sum(price), sum(advance) by type

    type title_id price advance ----------- ------- ---------- ---------psychology PS1372 21.59 7,000.00 psychology PS2091 10.95 2,275.00 psychology PS2106 7.00 6,000.00 psychology PS3333 19.99 2,000.00 psychology PS7777 7.99 4,000.00 sum sum ------- ---------- 67.52 21,275.00

    Z>? 3 compute>?>? 1 2"G>

    ,%_;Afg- sysprocesses syslocks"

    O0 select@Mkyzl,%0

  • 2-8 Transact-SQL

    O-N( Adaptive Server Enterprise 12

    AB7878>

    ,%=]:xHIxNOkG>~h

    :,%A@A6

    Start of select statement

    compute row_aggregate(column_name) [, row_aggregate(column_name)]... [by column_name [, column_name]...]

    rk

    column_nameS89AJzrzvw%x)yz%x6 sum7 avg@A

    v compute@M6,%Aij@Av,%WC@Av compute@M

    by ->~@kMx: by*xV=xO@A by89@A order by

    by v~v@k4vAv,%v*

    @A6bvYZew]:;,%~-kX)4v=vxHI]:xG>~

    6>?lHI

    select type, sum(price), sum(advance) from titleswhere type like "%cook" group by type

    type ---------- ---------- ---------------- mod_cook 22.98 15,000.00 trad_cook 47.89 19,000.00 (2 rows affected)

    select type, price, advance from titleswhere type like "%cook" order by type compute sum(price), sum(advance) by type

  • Adaptive Server Enterprise 2-9

    Adaptive Server Enterprise 12 O-N(

    type price advance ---------- ---------- ---------------- mod_cook 2.99 15,000.00 mod_cook 19.99 0.00 sum sum ---------- ---------------- 22.98 15,000.00 type price advance ---------- ---------- ---------------- trad_cook 11.95 4,000.00 trad_cook 14.99 8,000.00 trad_cook 20.95 7,000.00 sum sum ---------- ---------------- 47.89 19,000.00 (7 rows affected)

    type price advance ---------- ---------- ---------------- mod_cook 2.99 15,000.00 mod_cook 19.99 0.00

    Compute Result: ---------------------- ----------------- 22.98 15,000.00 type price advance ---------- ---------- ---------------- trad_cook 11.95 4,000.00 trad_cook 14.99 8,000.00 trad_cook 20.95 7,000.00

    Compute Result: ---------------------- ----------------- 47.89 19,000.00 (7 rows affected)

    compute@Mk89F select-k

    O ansinull)*~ off\]"^xW_O ansinull~ on^xW6 SQLSTATE

    Warning- null value eliminated in set function set

    1y computeM=y]:NO_fg%&pk"-t_;Mk select intoA compute@M

  • 2-10 Transact-SQL

    ()*+45N( Adaptive Server Enterprise 12

    [\

    %&'(,%-./%&'(V~%&'(D~%& / W{]^G>s/%&'(,%yz

    convert()

    inttohex()

    hextoint()

    %&'(,%A select-) where@M67@A-./r?

    Adaptive Server0~I%&'(HI!~,-./?O& char-./ datetime-./& smallint-./ int-./&_ char-./Adaptive Server0%&'(~%&'(

    89@A*+%&'(,%G/?Zr%&'(?%5-./ 89r~52-./

    L~I%&'( Adaptive Server_/G/?r~r%&'(?_; smallint%&~datetime_; datetime%&~ smallint%_u89^

  • Adaptive Server Enterprise 2-11

    Adaptive Server Enterprise 12 ()*+45N(

    - 2-3%&'(R6/G/?7RV_

    1 2-3\3*3"67

    tinyi

    nt

    smal

    lint

    int

    deci

    mal

    num

    eric

    real

    float

    char

    ncha

    r

    varc

    har

    text

    smal

    lmon

    ey

    mon

    ey

    bit

    smal

    ldat

    etim

    e

    date

    time

    bina

    ry

    varb

    inar

    y

    imag

    e

    tinyint - I I I I I I E E U I I I U U I I U

    smallint I - I I I I I E E U I I I U U I I U

    int I I - I I I I E E U I I I U U I I U

    decimal I I I I/E I/E I I E E U I I I U U I I U

    numeric I I I I/E I/E I I E E U I I I U U I I U

    real I I I I I - I E E U I I I U U I I U

    float I I I I I I - E E U I I I U U I I U

    char nchar E E E E E E E I I E E E E I I I I E

    varchar nvarchar E E E E E E E I I E E E E I I I I E

    text U U U U U U U E E U U U U U U U U U

    smallmoney I I I I I I I I I U - I I U U I I U

    money I I I I I I I I I U I - I U U I I U

    bit I I I I I I I I I U I I - U U I I U

    smalldatetime U U U U U U U E E U U U U - I I I U

    datetime U U U U U U U E E U U U U I - I I U

    binary I I I I I I I I I U I I I I I - I E

    varbinary I I I I I I I I I U I I I I I I - E

    image U U U U U U U U U U U U U U U E E U

    S\

    E 367I 3t67367>67I/E #Ui{-:{ arithabort numeric_truncation8 onq367>t367

    U 67 ~6767td

  • 2-12 Transact-SQL

    ()*+45N( Adaptive Server Enterprise 12

    CD/0ED

    652%&~52'(?) / W{)vw%xyz%x'(" S89{+1L'(52= +PQ,;Oyvv+char-./~ datetime-./ SQL Server+~\] datetimexJan 1, 1900

    %&y52W896u89I52>?

    %%&kJ%

    %&k

    vw / yz%x%&bl%&k5)

    / W{%&k9mS

    C:FD/0G:FD

    5W52K'5W52WO52x'5W52~+

    text6G/?~ char+ nchar) varchar nvarcharcharacter%&'(255v5W"}Ox\]30v5W"

    C/0D

    vwyz%x%&6~52'(O'(nopv52{_89?6q 5v5252~'52'(

    select convert(char(1), 12.34)Insufficient result space for explicit conversionof NUMERIC value 2.34 to a CHAR field.

    floatWZ[XY\ XY]^_` 25a

  • Adaptive Server Enterprise 2-13

    Adaptive Server Enterprise 12 ()*+45N(

    HI/0JK

    money smallmoney'(J%fg 4v%5b~lG>K&yrb (.01)%&~'(W&vJ%b

    O;'(%%&YZ&3O'(J%b_vw%x%&&'(0? $4.50~%= 5

    select convert(int, $4.50)

    ----------- 5

    ~ money smallmoney%&'b";_s'b"?%x 5~us_englishk 5;_ 5"x

    /0LM / NOPQ

    61~%&~ datetime smalldatetime_wSu89%&'(qr%&uM

    89

    datetimex~ smalldatetimeWK&y

    RSO/0

    %&6%5'(~%5'(O'(v0_6p%&vw%x89

    ?Ox%5x[%STC:%*+,%x%5x_b Adaptive Server_/?J%+%5;v089^?LJ%+%5 Adaptive Server89 241O2br%&'(89 257

    @A arithabort arithignore)*w Adaptive ServerF%5;u89

    arithabort arithignoreTU 10.0bcd !"#$%&'()*+,-./0123Vef67

  • 2-14 Transact-SQL

    ()*+45N( Adaptive Server Enterprise 12

    TU12VW56

    Adaptive Serverq%5x6W89'(J%b%npNOWM89HI89bcyz

    G//?~v0vw'(

    G//? / W{'(qr%&

    @A hextointfg 4v5W9%}52

    _/uG/kM89j}@A arithabort arith_overflow)*w Adaptive ServerFHI89\]~ arithabort arith_overflow on89vnO_ynFlH89 arithabort arith_overflow on_Fk6 YZDAdaptive Server_Fk89MMO arithabort arith_overflow off Adaptive Serverku89MFnFkrM6@A@@error{6eMNO

    @A arithignore arith_overflow)*w Adaptive ServerRHI89G>^\]~ off89vWG>^O arithignore arith_overflow onUHI89^6]Q)5arith_overflow;_uPQ

    G/u0WNO;_?O float) numeric decimal'(G/?~ integerAdaptive Servert~B:@NO=~%;J%X%5

    /~ numeric decimal'(W0u089@A arithabort numeric_truncation)*wH89c\]~ arithabort numeric_truncation onku89MFnFkrMO arithabort numeric_truncation off Adaptive ServerNO%F

  • Adaptive Server Enterprise 2-15

    Adaptive Server Enterprise 12 ()*+45N(

    ghi SQL92jklm

    - arithabort arith_overflow off- arithabort numeric_truncation on- arithignore off

    convert(),%[%rqrW,%m89H89u

    XYZ[SO/0

    binary varbinary'(fg9%}/%&H%&1 v0x 67%55)52=

    _6_/GH52?52x0000100 5W 0:MN-> 65536;5W 0_:MN-> 256

    R%}'(6G/?)@A convert,%/?~%'(O%&L'(no\.r0x vA,0Onr

    convert,%/%&'(_6_/LR%}%&xt_;_NO@Ahextoint,%9%}52~%;@Ainttohex,%%~9%}x

    RXYZ\YZSO/0

    binary varbinary%&52k0x b->binary'(00 ->%01 ->% binaryvarbinary'(~ numeric decimalWn8:0x b00 01 xRw

    ?:6 binary%&~ numericselect convert(numeric(38, 18),0x000000000000000006b14bd1e6eea0000000000000000000000000000000)

    ----------123.456000

  • 2-16 Transact-SQL

    DEN( Adaptive Server Enterprise 12

    ? numeric%& binaryselect convert(binary,convert(numeric(38, 18), 123.456))

    -------------------------------------------------------------- 0x000000000000000006b14bd1e6eea0000000000000000000000000000000

    C]^/0XYZ

    6@A convert,% image~ binary varbinaryH binary%&'(255v5W"}Ox\]30v52"

    C_`/0 bit

    vwyz%x'(6/?~ bit'(52'(C:G/ convert,%

    X-./89yz%5b)J%)267xr52fu89

    0x bit~ 0r%5x bit~ 1

    cd

    ,%F%&'(~ datetime smalldatetimex

    ,%yz

    dateadd

    datediff

    datename

    datepart

    getdate

    ,%A select- where@M

    datetime%&'(;A 1753 1 1datetimex89A'xxxLy@A char)nchar)varchar nvarcharAdaptive Server1s/]^[%&'(,% 1`aAq%&'( kW{%&'(

    8:?&52x datetimexW" Adaptive Server052 datetimex{%

  • Adaptive Server Enterprise 2-17

    Adaptive Server Enterprise 12 (PN(

    LMa

    6) Adaptive Server1EK67xyz

    OO& 2b 2025 " >=50~z{50 ->1950 "

    6vMO%5->|OM'v%5b->v%5b->r_v%5b->|?12:30:20:1 -> 12:30R|12:30:20.1 -> 12:30R Adaptive Server6A datetime%&W&x

    e

    %,%%%&MkXCx%,%S_5

    4,%u/?~'([%?yz%x'(,%u%'( Adaptive Server0[%~XC'(

    %,%yz

    abs

    acos

    asin

    atan

    atn2

    ceiling

    @A, k

    year yy 1753 - 9999 smalldatetime 2079

    quarter qq 1 - 4 month mm 1 - 12 week wk 1 - 54 day dd 1 - 31 dayofyear dy 1 - 366 weekday dw 1 - 7{ hour hh 0 - 23 minute mi 0 - 59 second ss 0 - 59 millisecond ms 0 - 999

  • 2-18 Transact-SQL

    (PN( Adaptive Server Enterprise 12

    cos

    cot

    degrees

    exp

    floor

    log

    log10

    pi

    power

    radians

    rand

    round

    sign

    sin

    sqrt

    tan

    ~FHI,%m89qr89STl89}~Aq6b (set) arithabort arithignore)*wFm89

    arithabort arith_overflowF89v~\]~ arithabort arith_overflow onvnk89FO arithabort arith_overflow off Adaptive Serverku89MFnFkrM

    arithabort numeric_truncationvw%x'(/%&'(bcku0~G/u0WNO;_"\]~ arithabort numeric_truncation onku89MFnFkrMO arithabort numeric_truncation off Adaptive ServerNO%F

    \] arithignore arith_overflow)*~ offH@Adaptive Serveru%5jG>^arithignore)*~ onPQ89

  • Adaptive Server Enterprise 2-19

    Adaptive Server Enterprise 12 QR;N(

    arithabort arithignoreTU 10.0bcd !"#$%&'()*+,-./012345678$

    fga

    {,%h{]^

    {,%yz

    is_sec_service_on

    show_sec_services

    '"h

    52,%LR%}%&)52-./%M52,%yz

    ascii

    char

    charindex

    char_length

    difference

    lower

    ltrim

    patindex

    replicate

    reverse

    right

    rtrim

    soundex

    space

    str

    stuff

    substring

    upper

  • 2-20 Transact-SQL

    STN( Adaptive Server Enterprise 12

    52,%6abD6A select-) where@M@A-./?O6A52,%A'xx6x52,%S_5

    452,%u/?~'([%?yz%x-./,%u%-./ Adaptive Server0[%~XC'(

    Db>cZ

    52,%NO_ 255v52

    set string_rtruncation~ onWO insert update52AqF89_bG>52W SQL Server_O89?

    select replicate("a", 250) + replicate("B", 250)

    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaBBBBB

    `a,%%&pk]^`a,%yz

    col_length

    col_name

    curunreservedpgs

    data_pgs

    datalength

    db_id

    db_name

    host_id

    host_name

    index_col

    isnull

  • Adaptive Server Enterprise 2-21

    Adaptive Server Enterprise 12 STN(

    lct_admin

    mut_excl_roles

    object_id

    object_name

    proc_role

    ptn_data_pgs

    reserved_pgs

    role_contain

    role_id

    role_name

    rowcnt

    show_role

    suser_id

    suser_name

    tsequal

    used_pgs

    user

    user_id

    user_name

    valid_name

    valid_user

    `a,%A select-) where@M67@A-./?

    O`a,%[%)[%HA %&p)|MN)mnoAq%&pAq

  • 2-22 Transact-SQL

    UVN( Adaptive Server Enterprise 12

    ij

    *,%L text image %&%M*,%yz

    textptr

    textvalid

    **+,%S_5@A set textsize)*} selectMXew text image%&6

    patindex,%A text imageA*,%

    @A datalength,%U text imagek%&

    text image_;

    Afgbc[%

    ARSfgbcx

    A+6

    A order by) compute group by@M

    Awx

    A where@M5 like

    A

    ATo

  • Adaptive Server Enterprise 2-23

    Adaptive Server Enterprise 12 abs

    abs

    -./Lx

    abs(numeric_expression)

    numeric_expression %&'(~vw%x)yz%x)/~HI'('(")6-./

    7

    1. select abs(-1)

    ----------- 1

    -1Lx

    abs%,%-./LxNOh%5-./V'(Dv0

    %,%]^[ 2-17#%,%

    X

    Aqj6 abs

    :; 5 ceiling floor round sign

  • 2-24 Transact-SQL

    acos Adaptive Server Enterprise 12

    acos

    6->"

    acos(cosine)

    cosine ->~ float) real) double precision'(/~HI'(%&'("S)66

    7

    1. select acos(0.52)

    -------------------- 1.023945

    ~ 0.52

    acos%,%~x6->"

    %,%]^[ 2-17#%,%

    X

    Aqj6 acos

    :; 5 cos degrees radians

  • Adaptive Server Enterprise 2-25

    Adaptive Server Enterprise 12 ascii

    ascii

    -./kv52 ASCII

    ascii(char_expr)

    char_expr '(~ char) varchar) nchar nvarchar52(S)66-./

    7

    1. select au_lname, ascii(au_lname) from authorswhere ascii(au_lname) < 70

    au_lname------------------------------ -----------Bennet 66Blotchet-Halls 66Carson 67DeFrance 68Dull 68

    O ASCIIJ 707kD5) ASCII

    ascii52,%-./kv52 ASCII

    O char_expr NULL NULL

    52,%]^[ 2-19#52,%

    :; 5

  • 2-26 Transact-SQL

    ascii Adaptive Server Enterprise 12

    X

    Aqj6 ascii

    > char

  • Adaptive Server Enterprise 2-27

    Adaptive Server Enterprise 12 asin

    asin

    6->"

    asin(sine)

    sine ->~ float) real) double precision'(/~HI'(%&'("S)66

    7

    1. select asin(0.52)

    -------------------- 0.546851

    asin%,%~x6->"

    %,%]^[ 2-17#%,%

    X

    Aqj6 asin

    :; 5 degrees radians sin

  • 2-28 Transact-SQL

    atan Adaptive Server Enterprise 12

    atan

    6->"

    atan(tangent)

    tangent ->~ float)real)double precision'(/~HI'(%&'("S)66

    7

    1. select atan(0.50)

    -------------------- 0.463648

    atan%,%~x6->"

    %,%]^[ 2-17#%,%

    X

    Aqj6 atan

    :; 5 atn2 degrees radians tan

  • Adaptive Server Enterprise 2-29

    Adaptive Server Enterprise 12 atn2

    atn2

    6->"

    atn2(sine, cosine)

    sine ->~ float) real) double precision'(/~HI'(%&'("S)66

    cosine ->~ float) real) double precision'(/~HI'(%&'("S)66

    7

    1. select atn2(.50, .48)

    -------------------- 0.805803

    atn2%,%6->"

    %,%]^[ 2-17#%,%

    X

    Aqj6 atn2

    :; 5 atan degrees radians tan

  • 2-30 Transact-SQL

    avg Adaptive Server Enterprise 12

    avg

    X_"x%5c

    avg([all | distinct] expression)

    all LXxA avg all\][%

    distinct A avg xdistinct)[%

    expression 6S)6),%)1MM2bM2S)6,%6@h@A-./S]^[ 3-./)0122 k-./

    7

    1. select avg(advance), sum(total_sales) from titles where type = "business"

    ------------------------ ----------- 6,281.25 30788

    Mc67X'4vH,%j~ewX='v]:x

    2. select type, avg(advance), sum(total_sales) from titles group by type

    type------------ ------------------------ -----------UNDECIDED NULL NULLbusiness 6,281.25 30788mod_cook 7,500.00 24278popular_comp 7,500.00 12875psychology 4,255.00 9939trad_cook 6,333.33 19566

    A group by@MW,%~4;v-"='vx6M=4]:x

  • Adaptive Server Enterprise 2-31

    Adaptive Server Enterprise 12 avg

    3. select pub_id, sum(advance), avg(price) from titles group by pub_id having sum(advance) > $25000 and avg(price) > $15

    7 titles-DyzIb $25,000Dcds $157X/=

    pub_id------ -------------------- --------------------0877 41,000.00 15.411389 30,000.00 18.98

    avg,%kXxcavg;A%5%)"%&'(McWPQx

    ,%]^[ 2-5#,%

    A averageM%%&cxW@%&'(smallint tinyint Adaptive ServerNOv intx~ DB-LibrarycF89cNOX6s~'( int

    _;LR%}%&'(@A avg()

    X

    Aqj6 avg

    :; 5 maxmin

  • 2-32 Transact-SQL

    ceiling Adaptive Server Enterprise 12

    ceiling

    xJ%

    ceiling(value)

    value %&'(~vw%x)yz%x)/~HI'(%5'(")6-./

    7

    1. select ceiling(123.45)

    124

    2. select ceiling(-123.45)

    -123

    3. select ceiling(1.2345E2)

    24.000000

    4. select ceiling(-1.2345E2)

    -123.000000

    5. select ceiling($123.45)

    124.00

    6. select discount, ceiling(discount) from salesdetail where title_id = "PS3333"

    discount-------------------- --------------------

    45.000000 45.00000046.700000 47.00000046.700000 47.00000050.000000 50.000000

  • Adaptive Server Enterprise 2-33

    Adaptive Server Enterprise 12 ceiling

    ceiling%,%xJ%x%&'(hXSTx

    L numeric decimalxNOvhXSTx;0~

    %,%]^[ 2-17#%,%

    X

    Aqj6 ceiling

    :; 5 abs floor round sign

  • 2-34 Transact-SQL

    char Adaptive Server Enterprise 12

    char

    %x52

    char(integer_expr)

    integer_expr 0 255{%tinyint) smallintint"S)66-./

    7

    1. select char(42)

    - *

    2. select xxx = char(65)

    xxx--- A

    char52,%'5W%x~52xchar~ ascii%@A"

    char char%&'(OXxv5W52v5W^52;

    O char_expr NULL NULL

    52,%]^[ 2-19#52,%

    C char8

    6@A char()xA tab;Os/char(10)~ char(9)~ tab

  • Adaptive Server Enterprise 2-35

    Adaptive Server Enterprise 12 char

    ?

    /* just a space */select title_id + " " + title from titles where title_id = "T67061"/* a return */select title_id + char(10) + title from titles where title_id = "T67061"/* a tab */select title_id + char(9) + title from titles where title_id = "T67061"

    ------------------------------------------------------------------------T67061 Programming with Curses------------------------------------------------------------------------T67061

    Programming with Curses------------------------------------------------------------------------T67061 Programming with Curses

    X

    Aqj6 char

    :; 5 ascii str

  • 2-36 Transact-SQL

    charindex Adaptive Server Enterprise 12

    charindex

    ->-./Bb%

    charindex(expression1, expression2)

    expression R%}52'(S)66-./6 char) varchar) nchar nvarchar%& binary varbinary

    7

    1. select charindex("wonderful", notes) from titles where title_id = "TC3218"

    -----------46

    52-./Wonderful titles- notesBb

    charindex52,% expression2k!wDFexpression1->rBb%O2expression1 charindex 0

    O expression1y2charindexK5

    O char_expr NULL NULL

    52,%]^[ 2-19#52,%

    :; 5

  • Adaptive Server Enterprise 2-37

    Adaptive Server Enterprise 12 charindex

    X

    Aqj6 charindex

    > patindex

  • 2-38 Transact-SQL

    char_length Adaptive Server Enterprise 12

    char_length

    -./k52%6

    char_length(char_expr)

    char_expr '(~ char+ varchar+ nchar nvarchar52(S)66-./

    7

    1. select char_length(notes) from titleswhere title_id = "PC9999"

    -----------39

    2. declare @var1 varchar(20), @var2 varchar(20), @char char(20)select @var1 = "abcd", @var2 = "abcd ",

    @char = "abcd"select char_length(@var1), char_length(@var2), char_length(@char)

    ----------- ----------- ----------- 4 8 20

    char_length52,%v%6->52-./xk52%6

    L6char_length52%6;_6"_;\.6kyG/+L5526char_length_\.+-./[>? 2"

    L5W52-./k52%6J5W%6@A datalengthw5W%6

    O char_expr NULL char_length NULL

    52,%]^[ 2-19#52,%

  • Adaptive Server Enterprise 2-39

    Adaptive Server Enterprise 12 char_length

    X

    Aqj6 char_length

    :; 5 datalength

  • 2-40 Transact-SQL

    col_length Adaptive Server Enterprise 12

    col_length

    col_length(object_name, column_name)

    object_name %&pL-))bc)To)\]x3"S!S6{Syz%&pSX7S"89Axrx

    column_name S

    7

    1. select x = col_length("titles", "title")

    x---- 80

    titles-k titlex NOkST0}

    col_length`a,%

    `a,%]^[ 2-20#`a,%

    :4Xfg%&@A datalength

    L text image col_length 16H#binary(16)L

    :; 5

  • Adaptive Server Enterprise 2-41

    Adaptive Server Enterprise 12 col_length

    X

    Aqj6 col_length

    > datalength

  • 2-42 Transact-SQL

    col_name Adaptive Server Enterprise 12

    col_name

    - ID IDS!

    col_name(object_id, column_id[, database_id])

    object_id %5-./->-)r%&pLL IDKfg sysobjects idk,

    column_id %5-./-> IDKfgsyscolumns colidk

    database_id %5-./->%&p IDKfgsysdatabases db_idk

    7

    1. select col_name(208003772, 2)

    ------------------------------ title

    col_name`a,%S!

    `a,%]^[ 2-20#`a,%

    X

    Aqj6 col_name

    :; 5 db_id object_id

  • Adaptive Server Enterprise 2-43

    Adaptive Server Enterprise 12 compare

    compare

    A

  • 2-44 Transact-SQL

    compare Adaptive Server Enterprise 12

    compare,%_t~52hys52;Adaptive Servert~tcompare@A sortkey,%=A&'tC~52)yvs52yvs52&k_

    O char_expression1 char_expression2~ NULLNO~NULL

    O2 collation_namexcompareHUR%}'

    O2 collation_IDx compareHUR%}'

    X

    Aqj6 compare

    :; 5 sortkey

  • Adaptive Server Enterprise 2-45

    Adaptive Server Enterprise 12 convert

    convert

    ~%&'(r datetimeG>s/x

    convert (datatype [(length) | (precision[, scale])] [null | not null], expression [, style])

    datatype :-./=`a%&'(? char(10)+varbinary(50) int"_;@AAq%&'(

    O%&pkA Java datatype; %&pkJava-SQL'

    length )[%A char)nchar)varchar)nvarchar)binary varbinary%&'(OB_ST Adaptive Server52'(%& 30v52R%}'(%& 305W52R%}%&6255v5W

    precision numeric decimal%&'(kbv%L-. %&'(v%kR%}bv%OB_STv Adaptive ServerL numeric decimal%&'(@A\]v 18

    scale numeric decimal%&'(kJ%b%OB_ST0 Adaptive Server@A\]0 0

    null | not null NO-./~OB_ST null not nullNOh-./~

    expression %&'(%&s/~%&'(%&s/x

    O%&pkA Java expression6:~Java-SQL'x

  • 2-46 Transact-SQL

    convert Adaptive Server Enterprise 12

    style A%&G>s/O money smallmoney%&~52'(HA style 14 3b%G>v

    O datetime smalldatetime%&~52'(@A- 2-4k/dG>s/xG> 2b% (yy)L 4b% (yyyy)A 100@Ak{kx

    \]xstyle 0 100" style 9 109z{ (yyyy)O smalldatetime~ char varcharyz/HIbG>

    7

    1. select title, convert(char(12), total_sales) from titles

    2. select title, total_sales from titles where convert(char(20), total_sales) like "1%"

    1 2-4\@A / qrb3

    (yy)

    (yyyy)

    0 100 mon dd yyyy hh:miAM PM

    1 101 mm/dd/yy

    2 102 yy.mm.dd

    3 103 dd/mm/yy

    4 104 dd.mm.yy

    5 105 dd-mm-yy

    6 106 dd mon yy

    7 107 mon dd, yy

    8 108 hh:mm:ss

    9 109 mon dd yyyy hh:mi:ss:mmmAMPM

    10 110 mm-dd-yy

    11 111 yy/mm/dd

    12 112 yymmdd

  • Adaptive Server Enterprise 2-47

    Adaptive Server Enterprise 12 convert

    3. select convert(char(12), getdate(), 3)

    ~/3 dd/mm/yy4. select convert(varchar(12), pubdate, 3) from titles

    Ox pubdate~89@A varchar;_ charR8

    5. select convert(integer, 0x00000100)

    520x00000100 x%NO_;

    6. select convert (binary, 10)

    b/ SybaseR%}'(7. select convert(bit, $1.11)

    1 $1.11xb528. select title, convert (char(100) not null,

    total_sales) into #tempsales from titles

    A%&'(~ char(100) total_salesUV #tempsalesD_x@ titles.total_sales~x #tempsales@A_x #tempsales.total_salesUV

    convert%&'(,%~G>%&'({ / W{7%&s/

    %&'(]^[ 2-10#%&'(,%

    convert()[%,%qrW,%m89H89u

    @A null not nulle0~r@Aselect intoUVv-,-kVF%&'(~[>? 8"

    6@A convert image~ binary varbinaryH binary%&'(255v5W"}Ox\]30v52"

  • 2-48 Transact-SQL

    convert Adaptive Server Enterprise 12

    Java/~

    O%&pkA Java@A convertV%&'(

    - JavaL'(~ SQL%&'(

    - SQL%&'(~ Java'(

    - O-./'"dW%&'(e0'@'' Adaptive Server Java-SQL'~ Adaptive Serverr Java-SQL'

    NOh %&pj

    :[%&'(-lGp7 Java'%&'([ Adaptive Server Enterprise Java

    X

    Aqj6 convert

    :; 5 hextoint inttohex

  • Adaptive Server Enterprise 2-49

    Adaptive Server Enterprise 12 cos

    cos

    cos(angle)

    angle yz%x'(float) real double precision"S)66-./

    7

    1. select cos(44)

    0.999843

    cos%,%6->"

    %,%]^[ 2-17#%,%

    X

    Aqj6 cos

    :; 5 acos degrees radians sin

  • 2-50 Transact-SQL

    cot Adaptive Server Enterprise 12

    cot

    cot(angle)

    angle yz%x'(float) real double precision"S)66-./

    7

    1. select cot(90)

    -------------------- -0.501203

    cos%,%6->"

    %,%]^[ 2-17#%,%

    X

    Aqj6 cot

    :; 5 degrees radians tan

  • Adaptive Server Enterprise 2-51

    Adaptive Server Enterprise 12 count

    count

    _"x%6X)%6

    count([all | distinct] expression)

    all LXxA count all\][%

    distinct A count xdistinct)[%

    expression 6S)6),%)1MM2bM2S)6,%6@h@A-./S]^[ 3-./)0122 k-./

    7

    1. select count(distinct city) from authors

    7_%6

    2. select type from titles group by type having count(*) > 1

    titles-k'(y_y'(

    count,%kx%6,%]^[ 2-5#,%

    distinct countDx%6l textimage countAX%&'(%%WPQx

  • 2-52 Transact-SQL

    count Adaptive Server Enterprise 12

    L-)yxyxcount(column_name)x~ 0

    count(*)%count(*)_[%D_; distinct@A_RxXc%

    v-W select listkyz count(*) 6=NOk%Oe0Mv-kh0 %@A count(column_name)

    count()@kA%fe?

    select * from tab where 0 < (select count(*) from tab2 where ...)

    ,;~ count()LX x%%exists in1?NO?

    select * from tab where exists(select * from tab2 where ...)

    X

    Aqj6 count

    :; 5

  • Adaptive Server Enterprise 2-53

    Adaptive Server Enterprise 12 curunreservedpgs

    curunreservedpgs

    TkA#%

    curunreservedpgs(dbid, lstart,unreservedpgs)

    dbid %&p IDKfg sysdatabases db_idk

    lstart :r#Tk#

    unreservedpgs dbtable LXZ%&pW\]x

    7

    1. select db_name(dbid), d.name,curunreservedpgs(dbid, lstart, unreservedpgs)from sysusages u, sysdevices dwhere d.low = u.size + vstart -1and d.status &2 = 2

    master master 184master master 832 tempdb master 464 tempdb master 1016 tempdb master 768 model master 632 sybsystemprocs master 1024 pubs2 master 248

    %&pS!)JS4vJTk34#%

    2. select curunreservedpgs (dbid, sysusages.lstart, 0)

    G> sysusages.lstartAB dbidA#%

  • 2-54 Transact-SQL

    curunreservedpgs Adaptive Server Enterprise 12

    curunreservedpgs`a,%TkA#%`a,%]^[ 2-20#`a,%

    O%&pA*fkUxO@A%&psysusages unreservedpgskUx

    X

    Aqj6 curunreservedpgs

    :; 5 db_id lct_admin

  • Adaptive Server Enterprise 2-55

    Adaptive Server Enterprise 12 data_pgs

    data_pgs

    -wxXA#%

    data_pgs(object_id,{data_oam_pg_id | index_oam_pg_id})

    object_id -)r%&pLL IDKfgsysobjects idk,

    data_oam_pg_id %& OAM## IDfg sysindexesdoampgk

    index_oam_pg_id wx OAM## IDfg sysindexesioampgk

    7

    1. select sysobjects.name,Pages = data_pgs(sysindexes.id, doampg)from sysindexes, sysobjectswhere sysindexes.id = sysobjects.id and sysindexes.id > 100 and (indid = 1 or indid = 0)

    Aq-rL ID 100"XA%% indid~ 0->2kwx- indid~ 1->kwx-t?_yzkwx

    2. select sysobjects.name,Pages = data_pgs(sysindexes.id, ioampg)from sysindexes, sysobjectswhere sysindexes.id = sysobjects.id and sysindexes.id > 100

    and (indid > 1)

    Aq-rL ID 100")kwx#XA%%

  • 2-56 Transact-SQL

    data_pgs Adaptive Server Enterprise 12

    data_pgs`a,%- (doampg)wx (ioampg)XA#%L sysindexes-W89@AH,%`a,%]^[ 2-20#`a,%

    data_pgsA %&pkL

    NO_yzA*+N##:[-)kwx*+N##%O@A used_pgs

    /%

    An (syslogs)WrNO;_vw 16#

    OFdata_pgs 0;_89

    - sysobjectsk_f object_id

    - control_page_id_V object_idX-

    - object_id~ -1

    - page_id~ -1

    X

    Aqj6 data_pgs

    ZC/

    sysindexes) syspartitions

    :; 5 object_id rowcnt used_pgs

    HI sp_spaceused

  • Adaptive Server Enterprise 2-57

    Adaptive Server Enterprise 12 datalength

    datalength