13.07.2015 Views

SAS/ACCESS 9.2 for Relational Databases: Reference, Fourth Edition

SAS/ACCESS 9.2 for Relational Databases: Reference, Fourth Edition

SAS/ACCESS 9.2 for Relational Databases: Reference, Fourth Edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

How <strong>SAS</strong>/<strong>ACCESS</strong> Works 4 How the SQL Pass-Through Facility Works 63DBMS and then doing the processing in <strong>SAS</strong>). For example, an important use of thisfeature is the handling of PROC SQL queries that access DBMS data. Here is how itworks:1 PROC SQL examines each query to determine whether it might be profitable tosend all or part of the query to the DBMS <strong>for</strong> processing.2 A special query textualizer in PROC SQL translates queries (or query fragments)into DBMS-specific SQL syntax.3 The query textualizer submits the translated query to the <strong>SAS</strong>/<strong>ACCESS</strong> engine <strong>for</strong>approval.4 If <strong>SAS</strong>/<strong>ACCESS</strong> approves the translation, it sends an approval message to PROCSQL. The DBMS processes the query or query fragment and returns the results to<strong>SAS</strong>. Any queries or query fragments that cannot be passed to the DBMS areprocessed in <strong>SAS</strong>.See the chapter on per<strong>for</strong>mance considerations <strong>for</strong> detailed in<strong>for</strong>mation about tasks that<strong>SAS</strong>/<strong>ACCESS</strong> can pass to the DBMS.How the SQL Pass-Through Facility WorksWhen you read and update DBMS data with the SQL pass-through facility,<strong>SAS</strong>/<strong>ACCESS</strong> passes SQL statements directly to the DBMS <strong>for</strong> processing. Here arethe steps:1 Invoke PROC SQL and submit a PROC SQL CONNECT statement that includes aDBMS name and the appropriate connection options to establish a connection witha specified database.2 Use a CONNECTION TO component in a PROC SQL SELECT statement to readdata from a DBMS table or view.In the SELECT statement (that is, the PROC SQL query) that you write, usethe SQL that is native to your DBMS. <strong>SAS</strong>/<strong>ACCESS</strong> passes the SQL statementsdirectly to the DBMS <strong>for</strong> processing. If the SQL syntax that you enter is correct,the DBMS processes the statement and returns any results to <strong>SAS</strong>. If the DBMSdoes not recognize the syntax that you enter, it returns an error that appears inthe <strong>SAS</strong> log. The SELECT statement can be stored as a PROC SQL view. Here isan example.proc sql;connect to oracle (user=scott password=tiger);create view budget2000 as select amount_b,amount_sfrom connection to oracle(select Budgeted, Spent from annual_budget);quit;3 Use a PROC SQL EXECUTE statement to pass any dynamic, non-query SQLstatements (such as INSERT, DELETE, and UPDATE) to the database.As with the CONNECTION TO component, all EXECUTE statements arepassed to the DBMS exactly as you submit them. INSERT statements mustcontain literal values. For example:proc sql;connect to oracle(user=scott password=tiger);execute (create view whotookorders as select ordernum, takenby,firstname, lastname,phone from orders, employeeswhere orders.takenby=employees.empid) by oracle;execute (grant select on whotookorders to testuser) by oracle;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!