English Query

download English Query

of 20

Transcript of English Query

  • 8/10/2019 English Query

    1/20

    Applications use two components to access a database:

    API

    A database API defines how to code an application to connect to a database and passcommands to the database. An object model API is usually language independent anddefines a set of objects, properties, and interfaces, while a C or Microsoft Visual asic

    API defines a set of functions for applications written in C, C!!, or Visual asic. "atabase language

    A database language defines the synta# of the commands sent to the database. $hecommands sent through the API allow the application to access and modify data. $heyalso allow the application to create and modify objects in the database. All commandsare subject to the permissions granted to the user.

    $his section discusses:

    $he database language supported by Microsoft %&' %er(er, $ransact)%&'.

    $he APIs supported by %&' %er(er and the issues to consider when choosing which API

    to use in an application.

    Transact-SQL

    $he database language supported by %&' %er(er is $ransact)%&'. $ransact)%&' complieswith the *ntry 'e(el of the %&')+ standard, but also supports se(eral features from theIntermediate and -ull 'e(els. It also supports some powerful e#tensions to the %&')+standard. -or more information, see $ransact)%&'/ in Microsoft SQL Server Transact-SQLand Utilities Reference.

    $he 0"C specification defined e#tensions to the %&' defined in the %&')+ standard.$hese 0"C %&' e#tensions are also supported by 0'* ". $ransact)%&' supports the0"C e#tensions from applications using the Microsoft Acti(e1 "ata 0bjects 2A"03, 0'*", or 0"C APIs, or the APIs that map o(er 0"C.

    APIs Supported by SQL Server

    %&' %er(er supports a number of APIs for building general)purpose database applications:

    0pen APIs with publicly defined specifications supported by se(eral database (endors:

    Acti(e1 "ata 0bjects 2A"03

    0'* "

    0pen "atabase Connecti(ity 20"C3 and the object APIs built o(er 0"C: 4emote

    "ata 0bjects 24"03 and "ata Access 0bjects 2"A03

    *mbedded %&' for C 2*%&'3

    $he legacy ")'ibrary API de(eloped specifically to be used with earlier (ersions of %&'

    %er(er that predate the %&')+ standard.

    Choosing an API

    $he general)purpose APIs recommended for use in new applications using Microsoft %&'%er(er 5.6 are:

    Microsoft Acti(e1 "ata 0bjects 2A"03 for most database applications. A"0 supports

    rapid de(elopment of robust applications and has access to most %&' %er(er features.$he %&' %er(er features needed by most applications are supported by A"0 whenusing the Microsoft 0'* " Pro(ider for %&' %er(er.

    0'* " for C0M)based tools and utilities, or C0M)based system le(el de(elopment

    needing either top performance or access to %&' %er(er features not e#posed throughA"0. $he 0'* " Pro(ider for %&' %er(er uses pro(ider)specific properties, interfaces,and methods to e#pose %&' %er(er features not co(ered by the 0'* " specification.Most of these pro(ider)specific features are not e#posed through A"0.

  • 8/10/2019 English Query

    2/20

    0"C for the same class of applications as are listed abo(e for 0'* ", but which are

    not based on C0M.

    $here are se(eral factors to consider when selecting which general)purpose APIs to use in a%&' %er(er application:

    Maturity of the API specification:

    *#isting*#isting API specifications are mature, stable specifications. %upplementaryinformation about the API is readily a(ailable in third)party boo7s and classes. $hereis an e#isting pool of programmers familiar with the API.

    *merging

    *merging API specifications are recent and may be e(ol(ing rapidly. %upplementaryinformation about the latest (ersion of the API may be scarce. $here are relati(elyfew programmers a(ailable who ha(e used the API, although programmers familiarwith a similar API can be retrained 8uic7ly.

    'egacy

    'egacy API specifications are stable but unchanging. $hey may not support newfeatures, and are li7ely to be discontinued at a future date. Information about the API

    is readily a(ailable, but the pool of programmers familiar with the API may beshrin7ing.

    0(erhead:

    9ati(e APIs

    9ati(e APIs are low)le(el APIs implemented with pro(iders or dri(ers thatcommunicate directly to %&' %er(er using the $abular "ata %tream 2$"%3 protocol.$hey are relati(ely comple# APIs, but offer the best performance because they ha(ethe least o(erhead.

    0bject Model APIs

    0bject model APIs use a relati(ely simple object model to encapsulate a nati(e API.$hey are less efficient than nati(e APIs because they must map their objects to theunderlying nati(e API, but the performance is acceptable for almost all applications.

    Applications using an object model API are simple to program and maintain. $heobject model API may not support all of the features of the underlying nati(e API.

    osted APIs

    osted APIs also encapsulate a nati(e API, but do not use an object model. $heefficiency, ease)of)use, and feature)set issues for hosted APIs are similar to thosefor object model APIs.

    "egree of de(eloper control.

    APIs (ary in their o(erall feature set. %imple APIs li7e A"0 are easy to learn, program,and maintain, but they do not support all of the capabilities of the more comple# APIssuch as 0'* " and 0"C. ;ou can ta7e ad(antage of the ease)of)use ad(antages ofthe APIs such as A"0, 4"0, and *%&' if they pro(ide the functionality the applicationneeds.

    Access to %&' %er(er features.

    %ome APIs ha(e limitations on the numbers or types of %&' %er(er features they canuse.

    Access to Microsoft %&' %er(er 0'AP %er(ices features.

    0'AP %er(ices, A"0 M", and 0'* " for 0'AP offer support for online analyticalprocessing. $hese ser(ices can be integrated with A"0 and 0'* " applications usingthe 0'* " Pro(ider for %&' %er(er.

  • 8/10/2019 English Query

    3/20

    Programming language and tool support for the API.

    $he following table maps the general)purpose database APIs supported by %&' %er(er tothe issues listed earlier.

    API Maturity

    Overhead

    Degr

    eeofdevelopercontrol

    SQL

    Server!"featuresupport

    OL

    APServicesfeaturesupport

    La

    nguagesupport

    A"0

    *mergin

    g

    0bjectModel

    o(er0'*"

    Moderate

    Most

    ;es MicrosoftVis

    ualasicMicrosoftVisualC!!Microsoft

    Visual

    0'*"

    *merging

    9ati(e

    igh

    All ;es VisualC!!

    0"C

    *#isting

    9ati(e

    igh

    All 9o VisualC!!

    4"0

    *#isting

    0bjectModelo(er0"C

    Moderate

    Most

    9o VisualasicVisual

    " 'e 0bj 'o 'im 9o Vis

  • 8/10/2019 English Query

    4/20

    A0

    gacy

    ectModelo(er0"C

    w ited ualasicVisualC!!

    *%&'

    'egacy

    ostedo(er")'ibrary

    'ow

    'imited

    9o VisualC!!C00'

    "

    )'ibraryforC

    'ega

    cy

    9ati(e

    igh

    'imited

    9o Visual

    C!!

    Additional APIs

    %&' %er(er also supports a number of interfaces that allow applications to ma7e full use ofall %&' %er(er features:

    %&' "istributed Management 0bjects 2%&')"M0 API3

    A set of C0M interfaces for managing and administering %&' %er(er. 4eplication components 24eplication Component Programming API3

    A set of C0M interfaces for defining and managing replication between %&' %er(erdatabases. ;ou can also replicate data from heterogeneous databases to %&' %er(er.

    "ata $ransformation %er(ices 2"ata $ransformation %er(ices API3

    A set of C0M interfaces 2based on 0'* "3 for defining and e#ecuting comple# datatransformations between 0'* " data pro(iders.

    0pen "ata %er(ices 20pen "ata %er(ices API3

    A C API for writing %&' %er(er e#tended stored procedures.

    See Also

    In Other #olu$es

    0(er(iew of uilding %&' %er(er Applications/ in Microsoft SQL Server BuildingApplications

    %&' %er(er and A"0

    Microsoft Acti(e1 "ata 0bjects are a set of Automation objects that consume the 0'* "API and allow applications to consume data from 0'* " data sources. $his includes datastored in many different formats, not just %&' databases. $he Acti(e1 "ata 0bject 2A"03

    API can be used from applications written in any Automation)enabled language, such as

  • 8/10/2019 English Query

    5/20

    Microsoft Visual asic, Microsoft Visual C!!, Microsoft Visual

    A"0 applications access data through 0'* " pro(iders. Microsoft %&' %er(er (ersion 5.6introduces a nati(e Microsoft 0'* " Pro(ider for %&' %er(er that can be used by A"0applications to access the data in %&' %er(er. In earlier (ersions of %&' %er(er, A"0applications had to use the 0'* " Pro(ider for 0"C layered o(er the Microsoft %&'

    %er(er 0"C dri(er. >hile A"0 applications can still use the 0'* " Pro(ider for 0"Cwith the %&' %er(er 0"C dri(er, it is more efficient to only use the 0'* " Pro(ider for%&' %er(er.

    A"0 is the API most recommended for general purpose data access from %&' %er(er. A"0:

    Is easy to learn and program.

    as the feature set needed by most general)purpose applications.

    Allows programmers to produce robust applications 8uic7ly with good performance.

    $he core capabilities of the 0'* " specification pro(ides all the data access functionalityneeded by most applications. In addition, 0'* " allows indi(idual pro(iders to definepro(ider)specific mechanisms to support additional features of the data engine accessed bythe pro(ider. A"0 e#poses the core capabilities of 0'* ", but does not e#pose pro(ider)specific features. A"0 applications cannot access a few %&' %er(er features e#posed

    through pro(ider)specific features of the 0'* " Pro(ider for %&' %er(er, such as theI%o&set'astLoadbul7 copy methods, %&' %er(er)specific e#tended diagnostic information,and auto)fetch cursors.

    A"0 has e(ol(ed from the earlier, 0"C)based 4emote "ata 0bjects 24"03 and "ataAccess 0bjects 2"A03 APIs. 4"0 and "A0 applications can be con(erted to A"0, and4"0 and "A0 application programmers 8uic7ly learn A"0. A"0 is used e#tensi(ely in

    Acti(e %er(er Pages 2A%P3.

    See Also

    In This #olu$e

    Programming A"0

    In Other #olu$es

    %&' %er(er and A"0/ in Microsoft SQL Server Building Applications

    %&' %er(er and 0'* "

    0'* " is an API that allows C0M applications to consume data from 0'* " datasources. 0'* " data sources include data stored in many different formats, not just %&'databases. An application uses an 0'* " pro(ider to access an 0'* " data source. An0'* " pro(ider is a C0M component that accepts calls to the 0'* " API and doeswhate(er is necessary to process that re8uest against the data source.

    Microsoft %&' %er(er (ersion 5.6 introduces a nati(e Microsoft 0'* " Pro(ider for %&'%er(er that can be used by 0'* " applications to access the data in %&' %er(er. $he 0'*" Pro(ider for %&' %er(er complies with the 0'* " .6 specification. *ach 0'* "pro(ider supports a command language? the 0'* " Pro(ider for %&' %er(er accepts thecommand synta# specified as "@I"B%&'. "@I"B%&' synta# is primarily %&')+

    synta# with 0"C escape se8uences.In earlier (ersions of %&' %er(er, 0'* " applications had to use the 0'* " Pro(ider for0"C layered o(er the Microsoft %&' %er(er 0"C dri(er. >hile 0'* " applications canstill use the 0'* " Pro(ider for 0"C with the %&' %er(er 0"C dri(er, it is more efficientto use only the 0'* " Pro(ider for %&' %er(er.

    0'* " is the API recommended for tools, utilities, or system le(el de(elopment needingeither top performance or access to %&' %er(er features not e#posed through A"0. $hecore capabilities of the 0'* " specification pro(ides all the data access functionalityneeded by most applications. In addition, 0'* " allows indi(idual pro(iders to define

  • 8/10/2019 English Query

    6/20

    pro(ider)specific mechanisms to support additional features of the data engine accessed bythe pro(ider. A"0 applications cannot access some %&' %er(er features e#posed throughpro(ider)specific features of the 0'* " Pro(ider for %&' %er(er, so applications needing touse the pro(ider)specific features of the 0'* " Pro(ider for %&' %er(er must use the 0'*" API. $hese features include:

    An I%o&set'astLoadinterface to the %&' %er(er bul7 copy component.

    An ISQLServer(rrorInfo interface to get %&' %er(er)specific information frommessages and errors.

    A 'I9*"%*4V*4% rowset that e#poses catalog information from the lin7ed ser(ers

    used in %&' %er(er distributed 8ueries.

    Various pro(ider)specific properties to control %&' %er(er)specific beha(iors.

    See Also

    In Other #olu$es

    %&' %er(er and 0'* "/ in Microsoft SQL Server Building Applications

    %&' %er(er and 0"C

    0pen "atabase Connecti(ity 20"C3 is a Call)'e(el Interface 2C'I3 that allows C and C!!

    applications to access data from 0"C data sources. A C'I is an API consisting of functionsan application calls to obtain a set of ser(ices. 0"C data sources include data stored indifferent formats, not just %&' databases. An application uses an 0"C dri(er to access adata source. An 0"C dri(er is a "'' that accepts calls to the 0"C API functions anddoes whate(er is necessary to process that re8uest against the data source.

    0"C is aligned with these specifications and standards defining a C'I for data access:

    $he 1D0pen CA* %pecification "ata Management: %&' Call)'e(el Interface 2C'I3/

    I%0DI*C +65E)F:G++E2*3 Call)'e(el Interface 2%&'DC'I3

    0"C has been widely accepted by database programmers, and se(eral database (endorsor third)party companies supply 0"C dri(ers. %e(eral other Microsoft data access APIswere defined as simplified object models o(er 0"C:

    4emote "ata 0bjects 24"03

    "ata Access 0bjects 2"A03

    Microsoft -oundation Classes 2M-C3 "atabase Classes

    Microsoft %&' %er(er includes a nati(e Microsoft %&' %er(er 0"C dri(er that can be usedby 0"C applications to access the data in %&' %er(er. $he %&' %er(er 0"C "ri(ercomplies with 'e(el of the 0"C F.EG specification and e#poses all the features of %&'%er(er. In %&' %er(er (ersion 5.6 all of the %&' %er(er utilities e#cept is)luse the 0"C

    API and the %&' %er(er 0"C "ri(er.

    0"C can be used in tools, utilities, or system le(el de(elopment needing either topperformance or access to %&' %er(er features, and which are not C0M applications. 0"C,li7e 0'* ", allows indi(idual dri(ers to define dri(er)specific mechanisms to supportadditional features of the data engine accessed by the dri(er. $hese features include:

    A set of bul7 copy functions based on the earlier ")'ibrary bul7 copy functions. *#tensions to the 0"C diagnostic functions and records to get %&' %er(er)specific

    information from messages and errors.

    A set of functions that e#poses catalog information from the lin7ed ser(ers used in %&'

    %er(er distributed 8ueries.

    Various dri(er)specific attributes and connection string 7eywords to control %&' %er(er)

    specific beha(iors.

    See Also

  • 8/10/2019 English Query

    7/20

    In Other #olu$es

    %&' %er(er and 0"C/ in Microsoft SQL Server Building Applications

    %&')"M0 API

    %&' "istributed Management 0bjects 2%&')"M03 encapsulate the objects found inMicrosoft %&' %er(er databases. %&')"M0 allows applications written in languages that

    support 0'* Automation or C0M to administer all parts of a %&' %er(er installation. %&')"M0 is the API used by the %&' %er(er (ersion 5.6 %&' %er(er *nterprise Manager, soapplications using %&')"M0 can perform all functions performed by %&' %er(er *nterpriseManager.

    %&')"M0 is intended for any 0'* Automation or C0M application that needs to incorporate%&' %er(er administration. *#amples include:

    Applications that encapsulate %&' %er(er as their data store and want to shield users

    from as much %&' %er(er administration as possible.

    Applications that ha(e specialiHed administrati(e logic incorporated the application itself.

    Applications that want to integrate %&' %er(er administrati(e tas7s in their own user

    interface.

    See AlsoIn This #olu$e

    Programming A"0

    In Other #olu$es

    "e(eloping %&')"M0 Applications/ in Microsoft SQL Server Distributed ManagementObects

    %&' 9amespace API

    $he %&' 9amespace 2%&')9%3 API is a set of objects that encapsulate the %&' %er(er*nterprise Manager user interface. %&')9% allows applications written in languages thatsupport 0'* Automation or C0M to include parts of the %&' %er(er *nterprise Manageruser interface in their own user interface.

    sing %&')9%, an application can incorporate the following %&' %er(er *nterprise Managerelements into its user interface:

    >iHards

    "ialog bo#es 2including property dialog bo#es3

    >hen an application uses the %&')9% objects, %&' %er(er *nterprise Manager must beinstalled on any client that attempts to run the %&')9% application.

    See Also

    In This #olu$e

    Administration Architecture

    In Other #olu$es

    Programming %&')9% Applications/ in Microsoft SQL Server Building Applications

    4eplication Component Programming API

    Microsoft %&' %er(er (ersion 5.6 includes a set of replication objects in addition to thereplication objects found in %&')"M0. $hese objects include:

    $he 4eplication "istributor Interface, which allows you to programmatically implement

    and manage heterogeneous transactional replication, in conjunction with third)partyprograms that can perform change trac7ing at heterogeneous data sources.

  • 8/10/2019 English Query

    8/20

    Microsoft Acti(e1 controls that allow you to pro(ide the functionality of the "istribution

    Agent or the Merge Agent in custom programs.

    See Also

    In This #olu$e

    Administration Architecture

    In Other #olu$esProgramming 4eplication Acti(e1 Controls/ in Microsoft SQL Server Building Applications

    Programming $ransactional and %napshot 4eplication from eterogeneous "ata %ources/in Microsoft SQL Server Building Applications

    0(er(iew of 4eplication/ in Microsoft SQL Server Distributed Data Operations andReplication

    "e(eloping %&')"M0 Applications/ in Microsoft SQL Server Distributed ManagementObects

    "ata $ransformation %er(ices API

    $he "ata $ransformation %er(ices 2"$%3 API is a set of objects encapsulating ser(ices thatassist with building a data warehouse. "$% can be used in applications written in languages

    that support 0'* Automation or C0M. "$%: $ransfers data between heterogeneous 0'* " data sources.

    Performs customiHed transformations that can con(ert detailed online transaction

    processing 20'$P3 data to a summariHed form for easy analysis of trend information.

    See Also

    In Other #olu$es

    0(er(iew of "ata $ransformation %er(ices/ in Microsoft SQL Server Distributed DataOperations and Replication

    Programming "$% Applications/ in Microsoft SQL Server Building Applications

    %&' %er(er and *nglish &uery

    *nglish &uery pro(ides an 0'* Automation API that lets users resol(e natural language8uestions about the information in a Microsoft %&' %er(er database.

    @i(en a definition of the entities and relationships associated with a %&' %er(er database,*nglish &uery translates a natural)language 8uestion about data in the database to a set of%&' %*'*C$ statements that can then be e#ecuted against the %&' %er(er database to getthe answer.

    -or e#ample, gi(en a car sales database, an application can send *nglish &uery a stringcontaining the 8uestion, ow many blue -ords were sold in G++J/

    *nglish &uery returns to the application an %&' statement such as:

    SELECT COUNT(*)

    FROM CarSales

    WHERE Make = 'Ford'

    AND Color = 'Blue'

    AND DATEART(!!" SalesDa#e) = '$%%&'

    $he application can then e#ecute the %&' statement against the %&' %er(er database to geta number it can return to the user.

    *nglish &uery wor7s best with a normaliHed database. $here are two parts to using *nglish&uery in an application:

  • 8/10/2019 English Query

    9/20

    G. An administrator defines an *nglish &uery domain for the database and uses that tocompile what is called an *nglish &uery application file. $he *nglish &uery applicationfile is what defines the structure of the database to the *nglish &uery run)time engine.

    An *nglish &uery domain contains:

    "efinitions of entities, which are usually associated with tables and columns of the

    database.

    "efinitions of the relationships between the entities.

    . $he domain is defined with a domain editor and tested with a test tool. $he result issa(ed as a domain project 2or K.e8p file3. $his file is compiled to form the *nglish &ueryapplication file 2K.e8d3.

    *nglish &uery is an 0'* Automation ser(er that can be called from any 0'* Automationapplication. $he 0'* Automation ser(er, or run)time engine, e#poses an object model API.

    An 0'* Automation application uses the API to load the *nglish &uery application file andthen send the run)time engine natural)language 8uestions. $he run)time engine usuallyreturns an %&' statement or batch that will retrie(e the needed information from the %&'%er(er database. %ometimes the run)time engine can pro(ide the answer directly, re8uestclarification, or return an error.

  • 8/10/2019 English Query

    10/20

    See AlsoIn This #olu$e

    Installing Microsoft *nglish &uery

    0pen "ata %er(ices API

    $he 0pen "ata %er(ices API is a ser(er)based API specific to Microsoft %&' %er(er. It canbe used to produce two types of applications:

    *#tended stored procedures

    An e#tended stored procedure is a C or C!! "'' that can be called from $ransact)%&'using the same synta# as calling a $ransact)%&' stored procedure. *#tended storedprocedures are a way to e#tend the capabilities of $ransact)%&' to include anyresources or ser(ices a(ailable to Microsoft >inF applications.

    @ateways

    @ateways are ser(er applications that allow applications written to access %&' %er(er towor7 with other databases. $he need for gateway applications has largely been madeobsolete by newer technologies such as %&' %er(er distributed 8ueries, >indows 9$Component %er(ices, and general database APIs such as A"0 and 0'* ".

    See Also

    In Other #olu$es

    Programming 0pen "ata %er(ices/ in %&' %er(er oo7s 0nline

    %&' %er(er and *mbedded %&'

    *mbedded %&' 2*%&'3 is a %&')+ standard API for %&' database access. *%&' re8uires

    a two step compilation process:

    A precompiler translates *mbedded %&' statements into commands in the programming

    language used to write the application. $he generated statements are specific to thedatabase that supplied the precompiler, so while the original source is generic to *%&',the generated statements and the final e#ecutable file are specific to one database(endor.

    $he source generated by the precompiler is then compiled using the compiler for the

    application programming language.

  • 8/10/2019 English Query

    11/20

    *mbedded %&' has a simpler synta# than C0M APIs such as 0'* " or Call 'e(elInterfaces such as 0"C, so it is easier to learn and program. It is less fle#ible than 0'* "or 0"C, where well)written applications can switch from one "M% to another by simplyswitching dri(ers or pro(iders. 0'* " and 0"C are also better at dealing withen(ironments where the %&' statements are not 7nown when the application is compiled,such as when de(eloping ad hoc 8uery tools.

    Microsoft %&' %er(er pro(ides an *mbedded %&' precompiler for C applications. $he %&'%er(er precompiler translates *mbedded %&' statements as calls to the appropriate ")'ibrary API functions. $he Microsoft implementation of *%&' has the same restrictions as")'ibrary applications.

    %&' %er(er is designed such that it can support C00' *mbedded)%&' applicationscompiled with third)party *mbedded %&' precompilers that support Microsoft %&' %er(er.

    See Also

    In Other #olu$es

    Programming *mbedded %&' for C/ in %&' %er(er oo7s 0nline

    ")'ibrary API

    ")'ibrary is a Call 'e(el Interface that allows C applications to access Microsoft %&'

    %er(er. Microsoft also pro(ides a closely matched API that pro(ides access to the ")'ibraryfunctions from Microsoft Visual asic applications. ")'ibrary for Visual asic supports asubset of the functions in ")'ibrary for C. ")'ibrary was the original API that allowedapplications to access %&' %er(er, and remains specific to %&' %er(er.

    $he ")'ibrary API has not been enhanced beyond the le(el of %&' %er(er .E. All ")'ibrary applications can wor7 with %&' %er(er 5.6, but only as .E le(el clients. 9ew featuresintroduced in %&' %er(er 5.6 are not supported for ")'ibrary applications.

    %&' %er(er 5.6 does not include a programming en(ironment for ")'ibrary for Visualasic. *#isting ")'ibrary for Visual asic applications can run against %&' %er(er 5.6, butmust be maintained using the software de(elopment tools from %&' %er(er .E. Allde(elopment of new Visual asic applications that access %&' %er(er should use the Visualasic data APIs such as Acti(e1 "ata 0bjects 2A"03 and 4emote "ata 0bjects 24"03.

    See Also

    In This #olu$e

    ")'ibrary for C 4eference

    SQL Syntax Recommendations

    $he Microsoft %&' %er(er (ersion 5.6 $ransact)%&' (ersion complies with the *ntry le(el ofthe %&')+ standard, and supports many additional features from the Intermediate and -ullle(els of the standard.

    $he 0'* " and 0"C APIs were de(eloped with the understanding that applicationswould use:

    %&')+ synta# whene(er it pro(ides the functionality needed by the application.

    ecause the %&' dialects of most databases now comply with the *ntry le(el of %&')+

    and support many features in the Intermediate and -ull le(els, this means many 0'* "pro(iders and 0"C dri(ers can simply pass through most %&')+ synta# withoutha(ing to transform it to something accepted by the database.

    se the 0"C e#tensions to %&')+ whene(er they pro(ide functionality needed by the

    application that %&')+ does not support.

    se the nati(e %&' synta# of the database engine whene(er it pro(ides functionality

    needed by the application that %&')+ and the 0"C e#tensions do not support.

  • 8/10/2019 English Query

    12/20

    $his approach minimiHes the o(erhead of 0'* " pro(iders and 0"C dri(ers. $hepro(iders and dri(ers only ha(e to parse incoming %&' statements for 0"C escapese8uences or %&')+ synta# not accepted by the database. Any 0"C escape se8uencesand unsupported %&')+ synta# are transformed into the corresponding %&' synta#accepted by the database engine. All other %&' synta# is passed through to the databaseengine.

    %&' %er(er 5.6 applications using 0'* ", 0"C, or one of the other APIs thatencapsulate these two, should follow these guidelines and:

    se %&')+ synta# whene(er it pro(ides the functionality needed by the application.

    se 0"C escape se8uences when they pro(ide functionality needed by the application

    but not pro(ided by %&')+.

    se $ransact)%&' synta# when it pro(ides functionality needed by the application but

    not pro(ided by %&')+ or the 0"C escape se8uences.

    *sing SQL &ith D+-Library and ($bedded SQL

    ")'ibrary supports only $ransact)%&'. ")'ibrary does not support the 0"C escapese8uences.

    *%&'DC supports only the %&' synta# defined in *mbedded %&' for C and %&' %er(er.

    (nglish Query

    *nglish &uery ma7es a definition of the entities and relationships defined in a %&' %er(erdatabase. @i(en this definition, an application can use an 0'* Automation API to pass*nglish &uery a string containing a natural)language 8uestion about the data in thedatabase. *nglish &uery returns an %&' statement the application can use to e#tract thedata needed to answer the 8uestion.

    Many database administrators ha(e de(eloped database)dri(en >eb sites using Acti(e%er(er Pages 2A%P3, Microsoft Acti(e1 "ata 0bjects 2A"03, and %&' %er(er or anotherdatabase ser(er only to find it difficult for their users to search the database and report on it.

    It is easy enough to build a 8uery form that allows users to search based on one or twofields, but it is much more difficult to build form)based >eb pages that allow searches acrossmultiple tables and multiple fields. A more fle#ible search is difficult to implement 2there aremany problems beyond the user)interface and >eb)coding aspects, such as defining howthe (arious tables and fields are related to each other3 and e(en the best interface can bedifficult for the casual >eb (isitor to use and understand.

    Microsoft *nglish &uery, which was introduced in Microsoft %&' %er(er (ersion .E,*nterprise *dition, and has been impro(ed for %&' %er(er (ersion 5.6, addresses this issueby pro(iding users with the ability to use natural language when 8uerying e#isting database)dri(en >eb sites and applications.

    sing *nglish &uery to de(elop an initial natural)language search is easyLit is only a smallpart of the effort of building your o(erall applicationLand the de(elopment process is moreconceptual than traditional programming. In fact, the process can be mastered bynonprogrammers who ha(e some database bac7ground, for e#ample, databaseadministrators and >eb)content de(elopers who wor7 often with databases.

    *nglish &uery ships with an engine, a component object model 2C0M3 ser(er, that is used atrun time to con(ert a users *nglish language 8uestion to an %&' statement. *nglish &uery

  • 8/10/2019 English Query

    13/20

    also pro(ides sample A%Ps that you can embed in a >eb site to dri(e the engine, promptinga user for 8uestions, e#ecuting the engines returned %&' 8ueries, and displaying 8ueryresults to the user.

    $his chapter e#plains how to author an *nglish &uery domain and how to embed the domainand the *nglish &uery engine in your >eb site.

    Building with English QueryMicrosoft *nglish &uery can be embedded into any application that supports C0M. 0necommon scenario is to embed it in a >eb site built with A%P scripts.

    A typical >eb page can use the sample A%P scripts that come with *nglish &uery. -ore#ample, the user enters a 8uestion or clic7s Sa$ple )uestions ! ! ! for predefined8uestions that show the 7ind of information a(ailable. $he user clic7s *9$*4 to submit the8uestion to the *nglish &uery engine, which generates an %&' statement that is thensubmitted to %&' %er(er using A"0. $he returned recordset is then displayed in the lowerframe.

    Authoring an English Query Domain

    $he first step to building a Microsoft *nglish &uery application is to model the semantics ofyour problem domain, that is, you must specify how *nglish)language entities 2nouns3 andrelationships 2(erbs, adjecti(es, traits, and subsets3 map to tables, fields, and joins in yourdatabase. $o do this, use the *nglish &uery authoring tool, which appears in the Microsoft*nglish &uery program group after installation.

    To initiali,e your database structure

    -rom the 'ilemenu on the "atabase tab, clic7 e&, and then select Structure loaded

    fro$ database.

    $his initialiHes the database structure from your %&' %er(er schema, filling theDatabasetab with tables and fields.

    $his illustration shows the database structure of the sample %&' %er(er pubsdatabase.

  • 8/10/2019 English Query

    14/20

    If any tables in the database are missing primary 7eys, edit them and supply one or morefields as the primary 7ey. It is not necessary that the underlying database ha(e a primary7ey, but all tables must ha(e primary 7eys identified in the authoring tool for your applicationto build.

    If tables will be related to each other in 8ueries, then there should be joins indicated betweenthose tables. $he joins usually are retrie(ed from the foreign 7eys defined in your database.owe(er, if the necessary foreign 7eys are not present 2usually they are there to forcereferential integrity3, then you should add the joins manually inside the authoring tool.

    Creating *ntities

    9ow you are ready to start adding semantic entities. $his consists of defining the entities in

    your database and the tables or fields with which they are associated.

    To create an entity

    G. 0n the Se$anticstab, right)clic7 *ntities, and then clic7 Insert (ntity ! ! ! .

    . In the e& (ntitydialog bo#, under Se$antic Properties, in the .ords/phrasesidentifyingentitybo#, enter a description of the entity, for e#ample, authoror &riter. Inthe (ntity type bo#, enter a type.

    F. nder Database Properties, in the Tableor 'ieldsbo#es, identify which part of thedatabase represents the entity.

  • 8/10/2019 English Query

    15/20

    Major entities usually correspond to entire tables. If it is a major entity, then enter thefields that should be used to display the entity, such as na$eor address.

    $his illustration shows this process for the entity author/ in the pubsdatabase.

    Major entities ha(e two 7inds of minor entities associated with them: names and traits.9ames indicate how the entity is identified in 8uestions and statements. y clic7ingAutona$e for the author entity, you can create an entity that represents the name of the

    author entity, associated with the first and last name fields. ;ou can create such nameentities for major entities that are represented by entire tables so the user can identify thespecific entity in 8uestion.

    y clic7ing Autotrait, you can create traits for the entity: minor entities that the major entity!as" Clic7 Accept Allto create minor entities for all of the semantically meaningful fields, aswell as for trait relationships between the major entity and the newly created minor entities.

  • 8/10/2019 English Query

    16/20

    In general, you should create entities for all tables in the database. y using Autotrait, youcan create entities for all fields in the database.

    Creating 4elationships

    y establishing traits for the major entities, your model begins with se(eral relationships. Atthis point, you can as7 8uestions about things ha(ing traits, for e#ample, >hat authors ha(e

    city %eattleJ/, %how authors and their cities,/ >hat boo7 has the title $he usy *#ecuti(es"atabase @uideJ/, or >hat publishers ha(e countryDregion -ranceJ/ ut to as7 the reallyinteresting 8uestions, you must create relationships between major entities, for e#ample,authors write boo7s/ and publishers publish boo7s./

    To create a relationship bet&een $a0or entities

    G. 0n the Se$anticstab, right)clic7 %elationships, and then clic7 Insert %elationship ! ! !.

    . In thee& %elationshipdialog bo# on the (ntitiestab, clic7 Add (ntity ! ! ! .

    F. In the Select (ntities list, clic7 all entities that participate in the relationship.

    If the relationship occurs at a time or place, including the time or place entity helps *nglish&uery answer some 8uestions. $he entities associated with the relationship authors writeboo7s/ might appear as shown in this illustration.

    Phrasing

    9e#t, you can create phrasings for the relationship. Phrasing types include (erb phrasings2authors write boo7s/3, preposition phrasings 2publishers are in cities/3, adjecti(e phrasings2boo7s are popular/3, and subset phrasings 2some boo7s are bestsellers/3. Most traitphrasings 2boo7s ha(e royalties/3 and name phrasings 2author names are the names ofauthors/3 are created by Autotraitand Autona$e.

    $his illustration shows the #erb Phrasingdialog bo# defined for authors write boo7s./

  • 8/10/2019 English Query

    17/20

    To create phrasings for a relationship

    G. 0n the Se$antics tab, right)clic7 %elationships, and then clic7 Insert%elationships ! !! .

    . In thee& %elationships dialog bo#, on the Phrasings tab, clic7 Add ! ! ! .

    F. In the Select Phrasingdialog bo#, select a phrasing type.

    Ti$e and Location

    If a relationship occurs at a specific time or place, then it is helpful to anticipate some user8uestions and to supply the date or location entity on the Ti$e/Locationtab of the e&%elationshipdialog bo#.

    ;ou can create relationships for e(ery 7ind of 8uestion you want the user to as7. -ore#ample, if you want the model to support 8uestions about authors in cities, return to theauthors ha(e cities/ relationship and supply a new preposition phrasing that says authorsare in cities./

    $esting ;our Model

    At any time during the de(elopment process, you can test what you ha(e modeled byin(o7ing Test Applicationfrom the Toolsmenu. -or e#ample, with only the authors writeboo7s/ relationship entered, *nglish &uery can answer 8uestions such as >ho wrote themost boo7sJ/, >ho wrote 9et *ti8uetteJ/, and >hat boo7s did Anne 4inger writeJ/

  • 8/10/2019 English Query

    18/20

    To test your applicationG. 0n the Toolsmenu, clic7 Test Application ! ! ! .

    . In the Test Applicationdialog bo#, in the Questionbo#, enter your 8uery as an *nglishsentence, and then clic7 Sub$it.

    F. If you select (1ecute SQL, *nglish &uery submits the 8uery to %&' %er(er and displaysthe answer.

    N. If you thin7 the 8uestion is useful as a sample, then clic7 Add to Question 'ile.

    Another Toolsmenu item called %egression Teste#ecutes all 8ueries in the 8uestion fileand generates an output file. If you copy the output file to a reference file, then %egressionTest allows you to compare the results of the most recent output against the reference file.$his ensures that *nglish &uery can handle all 8uestions as you continue to enhance your*nglish &uery domain. $he 8uestion file 8uestions also can be used as a set of sample

    8uestions that can be displayed on a >eb page to gi(e users an idea of the a(ailableinformation.

    uilding and "eploying

    After you ha(e de(eloped and tested the model to your satisfaction inside the *nglish &ueryauthoring tool, you are ready to build the application. +uild Applicationon the Toolsmenucreates the *nglish &uery domain 2.e8d3 file. $he .e8d file and the *nglish &uery engine 2theC0M object called Mse8.%ession3 can be deployed inside any C0M)supporting application.

  • 8/10/2019 English Query

    19/20

    Adding English Query to Your e! Site

    An e#ample framewor7 for adding *nglish &uery to your >eb site is pro(ided in the%amplesDAsp subdirectory of the Microsoft *nglish &uery directory. If you are runningMicrosoft >indows 9$ %er(ers built)in >eb ser(er, Microsoft Internet Information %er(ices2II%3 (ersion N.6, and installing from your II% computer, you can deploy a >eb page that

    allows users to 8uery your *nglish &uery domain by choosing the %etupasp.(bs file. $his isa >indows %cripting ost 2>%3 script that copies the A%P files and your created .e8d file toa directory on the >eb ser(er, creates an II% (irtual directory for the *nglish &uery pages,and sets options in a Params.inc file to point A%P scripts to your database.

    If you are running II% F.6, perform the pre(ious steps manually 2the 4eadme.htm file alsodocuments the steps3.

    sing *nglish &uery in A%P Applications

    ;ou can also use the sample application to begin integrating *nglish &uery into other A%Papplications. -or e#ample, you might choose to ha(e an *nglish &uery te#t bo# a(ailable onyour search page or to supplement e#isting reporting mechanisms.

    $his code fragment 2a simplified (ersion of the A%P sample code3 shows the essence of howto con(ert the 8uestions supplied by users into %&'. ;ou embed code such as this in the

    A%P that processed the users 8uery.

    ' rea#e #e El+s ,uer! o-.e#

    Se# o-.E,Sess+o = Ser/er0Crea#eO-.e#(1Mse20Sess+o1)

    ' load #e do3a+

    o-.E,Sess+o04+#Do3a+ (1567u-s67u-s0e2d1)

    ' o/er# user8s 2ues#+o #o El+s ,uer! res7ose o-.e#

    Se# o-.E,Res7ose = o-.E,Sess+o0arseRe2ues#(Re2ues# (1User

    ,ues#+o1))

    ' de#er3+e 9a# k+d o: res7ose o-.e# +# +s

    Sele# Case o-.E,Res7ose0T!7e

    Case lCo33adRes7ose

    Se# o-.Co33ads = o-.E,Res7ose0Co33ads

    For +#Co33ad = ; To o-.Co33ads0Cou# < $

    Se# o-.Co33ad = o-.Co33ads(+#Co33ad) Sele# Case o-.Co33ad0C3d4D

    Case l,uer!C3d

    ' eeu#e #e re#ured S,L ad d+s7la! #o #e user

    DoS,LCo33ad o-.Co33ad

    Case lAs9erC3d

    ' .us# d+s7la! #e as9er

    Res7ose0Wr+#e o-.Co33ad0As9er

    Ed Sele#

    Ne#

    Case lUserClar+:!Res7ose

    DoClar+:+a#+o o-.E,Res7ose" s#r,ues#+o

    Case lErrorRes7ose

    Res7ose0Wr+#e o-.E,Res7ose0Desr+7#+o > 1?BR@1

    Ed Sele#

    Create an *nglish &uery object with Server!2reateOb0ect#Mse8.%ession/$. $o load yourdomain, call the InitDo$ainmethod with the name of the .e8d file. Call Parse%e)uest34 withthe users 8uestion and a %esponse object is returned. $he %esponseobject can be a2o$$and%esponse, which is a collection of commands that are either %&' commands ordirect answers. *ach %&' command should be e#ecuted against your %&' %er(er database,and you can display the result as a table on the >eb page. $he process of e#ecuting the

  • 8/10/2019 English Query

    20/20

    %&' command using A"0 and displaying the result in a table is embedded in theDoSQL2o$$andfunction 2a(ailable in %amplesDAspDCommon.inc3.

    If the command is an answer, it is displayed directly to the user. $he response might also bea re8uest for clarification. -or e#ample, the 8uestion might be >hat are all the compact carsin >ashingtonJ/ and the clarification 8uestion might as7 whether >ashington is a city or astate. $he Do2larification call 2also a(ailable in Common.inc3 encapsulates the code

    necessary to prompt the user to choose from possible (alues in the *serInputscollection onthe %esponseobject.