?? ch23.htm
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function popUp(pPage) {
var fullURL = document.location;
var textURL = fullURL.toString();
var URLlen = textURL.length;
var lenMinusPage = textURL.lastIndexOf("/");
lenMinusPage += 1;
var fullPath = textURL.substring(0,lenMinusPage);
popUpWin = window.open('','popWin','resizable=yes,scrollbars=no,width=525,height=394');
figDoc= popUpWin.document;
zhtm= '<HTML><HEAD><TITLE>' + pPage + '</TITLE>';
zhtm += '<link rel="stylesheet" href="/includes/stylesheets/ebooks.css"></head>';
zhtm += '<BODY bgcolor="#FFFFFF">';
zhtm += '<IMG SRC="' + fullPath + pPage + '">';
zhtm += '<P><B>' + pPage + '</B>';
zhtm += '</BODY></HTML>';
window.popUpWin.document.write(zhtm);
window.popUpWin.document.close();
// Johnny Jackson 4/28/98
}
//-->
</SCRIPT>
<link rel="stylesheet" href="/includes/stylesheets/ebooks.css">
<TITLE>Special Edition Using Visual C++ 6 -- Ch 23 -- SQL and the Enterprise Edition</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
<CENTER>
<H1><IMG SRC="../button/que.gif" WIDTH="171" HEIGHT="66" ALIGN="BOTTOM" BORDER="0"><BR>
Special Edition Using Visual C++ 6</H1>
</CENTER>
<CENTER>
<P><A HREF="../ch22/ch22.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"
ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch24/ch24.htm"><IMG
SRC="../button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"
BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../button/contents.gif" WIDTH="128"
HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A>
<HR>
</CENTER>
<CENTER>
<H1>- 23 -</H1>
</CENTER>
<CENTER>
<H1>SQL and the Enterprise Edition</H1>
</CENTER>
<UL>
<LI><A HREF="#Heading1">What's in the Enterprise Edition?</A>
<LI><A HREF="#Heading2">Understanding SQL</A>
<LI><A HREF="#Heading3">Working with SQL Databases from C++</A>
<LI><A HREF="#Heading4">Exploring the Publishing Application</A>
<UL>
<LI><A HREF="#Heading5">Setting Up the Data Source</A>
<LI><A HREF="#Heading6">Building the Application Shell</A>
<LI><A HREF="#Heading7">Making a Data Connection</A>
<LI><A HREF="#Heading8">Working with Query Designer</A>
<LI><A HREF="#Heading9">Stored Procedures</A>
<LI><A HREF="#Heading10">Writing a New Stored Procedure</A>
<LI><A HREF="#Heading11">Connecting the Stored Procedure to C++ Code</A>
</UL>
<LI><A HREF="#Heading12">Working with Your Database</A>
<UL>
<LI><A HREF="#Heading13">Database Designer</A>
<LI><A HREF="#Heading14">Database Diagrams</A>
</UL>
<LI><A HREF="#Heading15">Understanding Microsoft Transaction Server</A>
<LI><A HREF="#Heading16">Using Visual SourceSafe</A>
</UL>
<P>
<HR SIZE="4">
<CENTER>
<H1></H1>
</CENTER>
<H2><A NAME="Heading1"></A>What's in the Enterprise Edition?</H2>
<P>The Enterprise Edition of Visual C++ was developed for those of you who are integrating
SQL databases and C++ programs, especially if you use stored procedures. It's sold
as a separate edition of the product: You can buy a copy of the Enterprise Edition
instead of the Professional Edition. If you already own a Professional or Subscription
Edition, you can upgrade to the Enterprise Edition for a reduced price.</P>
<P>The Enterprise Edition of Visual C++ includes several extra features within Visual
Studio:</P>
<UL>
<LI>SQL debugging
<P>
<LI>Extended Stored Procedure Wizard
<P>
<LI>OLE DB support for AS 400 access
</UL>
<P>Also, a number of separate development tools are included:</P>
<UL>
<LI>Visual SourceSafe
<P>
<LI>SQL Server 6.5 (Developer Edition, SP 3)
<P>
<LI>Visual Modeler
<P>
<LI>Microsoft Transaction Server
<P>
<LI>Internet Information Server 4.0
</UL>
<P>If you do database programming, if you develop large projects and produce object
model diagrams, and if you work in teams and need to prevent revision collision,
you need the features of the Enterprise Edition.</P>
<P>
<H2><A NAME="Heading2"></A>Understanding SQL</H2>
<P>Structured Query Language (SQL) is a way to access databases, interactively or
in a program, that is designed to read as though it were English. Most SQL statements
are <I>queries</I>--requests for information from one or more databases--but it's
also possible to use SQL to add, delete, and change information. As mentioned in
Chapter 22, "Database Access," SQL is an enormous topic. This section reviews
the most important SQL commands so that even if you haven't used it before, you can
understand these examples and see how powerful these tools can be.</P>
<P>SQL is used to access a relational database, which contains several tables. A
table is made up of rows, and a row is made up of columns. Table 23.1 lists some
names used in database research or in some other kinds of databases for tables, rows,
and columns.</P>
<P>
<H4>Table 23.1  Database Terminology</H4>
<P>
<TABLE BORDER="1">
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT"><B>SQL</B></TD>
<TD ALIGN="LEFT"><B>Also Known As</B></TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">Table</TD>
<TD ALIGN="LEFT">Entity</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">Row</TD>
<TD ALIGN="LEFT">Record, Tuple</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">Column</TD>
<TD ALIGN="LEFT">Field, Attribute</TD>
</TR>
</TABLE>
</P>
<P>Here's a sample SQL statement:</P>
<P>
<PRE>SELECT au_fname, au_lname FROM authors
</PRE>
<P>It produces a list of authors' first and last names from a table called authors.
(This table is included in the sample pubs database that comes with SQL Server, which
you will be using in this chapter.) Here's a far more complicated SQL statement:</P>
<P>
<PRE>SELECT item, SUM(amount) total, AVG(amount) average FROM ledger
WHERE action = `PAID'
GROUP BY item
having AVG(amount) > (SELECT avg(amount) FROM ledger
WHERE action = `PAID')
</PRE>
<P>A SQL statement is put together from keywords, table names, and column names.
The keywords include the following:</P>
<UL>
<LI>SELECT returns the specific column of the database. Secondary keywords including
FROM, WHERE, LIKE, NULL, and ORDER BY restrict the search to certain records within
each table.
<P>
<LI>DELETE removes records. The secondary keyword WHERE specifies which records to
delete.
<P>
<LI>UPDATE changes the value of columns (specified with SET) in records specified
with WHERE. It can be combined with a SELECT statement.
<P>
<LI>INSERT inserts a new record into the database.
<P>
<LI>COMMIT saves any changes you have made to the database.
<P>
<LI>ROLLBACK undoes all your changes back to the most recent COMMIT.
<P>
<LI>EXEC calls a stored procedure.
</UL>
<P>Like C++, SQL supports two kinds of comments:</P>
<P>
<PRE>/* This comment has begin and end symbols */
-- This is a from-here-to-end-of-line comment
</PRE>
<H2><A NAME="Heading3"></A>Working with SQL Databases from C++</H2>
<P>As you saw in Chapter 22, "Database Access," an ODBC program using CDatabase
and CRecordset can already access a SQL Server database or any database that supports
SQL queries. What's more, with the ExecuteSQL function of CDatabase, you can execute
any line of SQL from within your program. Most of the time, the line of SQL that
you execute is a <I>stored</I> <I>procedure</I>--a collection of SQL statements stored
with the database and designed to be executed on-the-fly by the database server.</P>
<P>There are lots of reasons not to hard-code your SQL into your C++ program. The
three most compelling are</P>
<UL>
<LI>Reuse
<P>
<LI>Skill separation
<P>
<LI>Maintainability
</UL>
<P>Many programmers accessing a SQL database from a C++ application are building
on the work of other developers who have been building the database and its stored
procedures for years. Copying those procedures into your code would be foolish indeed.
Calling them from within your code lets you build slick user interfaces, simplify
Internet access, or take advantage of the speed of C++, while retaining all the power
of the stored procedures previously written.</P>
<P>Highly skilled professionals are always in demand, and sometimes the demand exceeds
the supply. Many companies find it hard to recruit solid C++ programmers and equally
as hard to recruit experienced database administrators who can learn the structure
of a database and write in SQL. Imagine how difficult it would be to find a single
individual who can do both--almost as difficult as having two developers work on
the parts of the program that called SQL from C++. A much better approach is to have
the C++ programmer call well-documented SQL stored procedures and the SQL developer
build those stored procedures and keep the database running smoothly.</P>
<P>Separating the C++ and SQL parts of your application has another benefit: Changes
to one might not affect the other. For example, a minor C++ change that doesn't involve
the SQL will compile and link more quickly because the C++ part of the application
is a little smaller without the SQL statements in it. Also, changes to the SQL stored
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -