?? ch23.htm
字號:
and how easy it is to develop and maintain these stored procedures by using Developer
Studio. You can even debug your SQL by using the Developer Studio debugger.</P>
<P>
<H2><A NAME="Heading12"></A>Working with Your Database</H2>
<P>The DataView gives you full control over not only the contents of your SQL database
but also its design. A raft of graphical tools makes it easy to see how the database
works or to change any aspect of it.</P>
<P>
<H3><A NAME="Heading13"></A>Database Designer</H3>
<P>Return to the DataView, right-click the authors table, and choose Design. With
the Database Designer, shown in Figure 23.29, you can change the key column, adjust
the width, apply constraints on valid values, and more.</P>
<P><A HREF="javascript:popUp('23uvc29.gif')"><B>FIG. 23.29</B></A><B> </B><I>The
Database Designer lets you change any aspect of your database's design.</I></P>
<P>For example, to open the property sheet shown in Figure 23.30, click the Properties
button at the far right of the Table toolbar while au_id is selected. The constraint
shown here means that au_id must be a 9-digit number. Clicking the Relationship tab,
shown in Figure 23.31, shows that au_id is used to connect the authors table to the
titleauthor table.</P>
<P><A HREF="javascript:popUp('23uvc30.gif')"><B>FIG. 23.30</B></A><B> </B><I>It's
simple to specify column constraints.</I></P>
<P><A HREF="javascript:popUp('23uvc31.gif')"><B>FIG. 23.31</B></A><B> </B><I>The
Relationships tab makes it simple to see how tables are related.</I></P>
<H3><I></I></H3>
<H3><A NAME="Heading14"></A>Database Diagrams</H3>
<P>One of the easiest ways to quickly present information to people is with a diagram.
Figure 23.32 shows a diagram that explains the relationships between the three tables
used throughout this chapter. To create the same diagram yourself, follow these steps:</P>
<DL>
<DT></DT>
<DD><B>1. </B>Right-click Database Diagrams in DataView and choose New Diagram.
<P>
<DT></DT>
<DD><B>2. </B>Click authors and drag it into the working area.
<P>
<DT></DT>
<DD><B>3. </B>Click titleauthor and drag it into the working area. Wait a moment
for a link between authors and titleauthor to appear.
<P>
<DT></DT>
<DD><B>4. </B>Click titles and drag it into the working area. Wait for the link to
appear.
<P>
<DT></DT>
<DD><B>5. </B>Rearrange the tables so that their keys are aligned as in Figure 23.32.
<P>
<DT></DT>
<DD><B>6. </B>Drag the links up or down until they run from one key to another, as
they do in Figure 23.32.
<P>
</DL>
<P><A HREF="javascript:popUp('23uvc32.gif')"><B>FIG. 23.32</B></A><B> </B><I>A picture
is worth a thousand words when it's time to explain your database design.</I></P>
<DL>
<DT><I></I></DT>
</DL>
<P>If you want, you can save this diagram in the database. Just click the Save button
on the standard toolbar and provide a name. The diagrams will be available to any
other developers who use the Enterprise Edition to access this database.</P>
<P>If you're a database developer, you probably can't wait to open your own database
in the Database Designer and set to work. Be sure to take advantage of the many features
on the Database Diagram toolbar. For example, you can add a note or explanation with
the New Text Annotation button; this note can be moved wherever you want. Four buttons
grouped together control how much detail is shown for each table. The first, Column
Properties, shows all the details that were in the table view. The second, Column
Names, is the default in the diagram view. Keys shows only those columns that are
keys, and Name Only shrinks the grid to a tiny column showing only the table's name.
This is useful for diagrams representing the relationships of many tables or of tables
from other projects.</P>
<P>To change any design decision about these tables, open the shortcut menu and choose
Column Properties; then edit these properties as you did in the Database Designer.
How's that for an easy way to design and administer a SQL database?</P>
<P>
<H2><A NAME="Heading15"></A>Understanding Microsoft Transaction Server</H2>
<P>Microsoft Transaction Server is a completely separate product that comes with
the Enterprise Edition of Visual C++ but is not integrated with it. MTS enables you
to use a collection of COM objects called <I>components</I> to securely execute distributed
transactions within enterprise-scale database applications. Applications that use
MTS can be written in any language that produces ActiveX applications, including
Visual C++, Visual J++, and Visual Basic.</P>
<P>To work with MTS, you must be comfortable doing under-the-hood ActiveX and COM
programming, working directly with interfaces. If you've always relied on MFC to
hide interfaces from you, you should probably read Chapter 21, "The Active Template
Library," to gain an introduction to the way that interfaces are used.</P>
<P>Like ODBC, you can use MTS with almost any kind of database, including ordinary
file systems. Certainly SQL databases work with MTS, but so do a huge variety of
other resource managers. This enables you access to the power of MTS without having
to change your database system at all.</P>
<P>An MTS component is a COM object. It can do any specific task within your system,
and often several components are involved in a given <I>transaction</I>. Components
are gathered together into packages, which are installed as a unit onto your system.</P>
<P>A <I>transaction</I> is a unit of work that should succeed or fail as a whole.
For example, if a customer is transferring money from one bank account to another,
the money should be withdrawn from one account and deposited to the other. It doesn't
make sense for one step in this process to fail and the other to proceed to completion.
This would either unfairly take money away from customers or unfairly give money
to customers. Database programmers have long realized this and have developed ways
of rolling back transactions that are partially completed when a step fails or of
checking conditions to ensure that all the steps will succeed before starting. However,
these techniques are much more difficult to implement in a large, distributed system--too
difficult to implement by hand.</P>
<P>For example, imagine that two systems are about to take money (say, $100) from
a customer's bank account. The first checks the balance, and there is enough money.
Both systems are connected through a network to the system that keeps the balance
for that account. The first system asks for the balance and receives the reply: $150.
Moments later, the second asks and is also told $150. The first confidently sends
the request for $100 and succeeds; only a fraction of a second later, the second
asks for $100 and fails. Any portions of a transaction involving this customer that
were already completed by the second system will now have to be rolled back. A transactional
system such as MTS makes this process much simpler for developers by providing system
services to support these tasks.</P>
<P>Sound good? Then install the product and get going in the online help. Two good
sample systems are included: a simple banking application and a game. You can also
check out Microsoft's Transaction Server Web site at <A target="_new" HREF="http://www.microsoft.com/transaction"><B>http://www.microsoft.com/transaction</B></A>.</P>
<P>
<H2><A NAME="Heading16"></A>Using Visual SourceSafe</H2>
<P>If you work as part of a team of developers, a revision control system isn't a
nicety--it's a necessity. For too many teams, the revision control system consists
of sticking your head into the hall and telling your fellow programmers that you
will be working on fooble.h and fooble.cpp for a while and to leave these alone.
Perhaps it's more about demanding to know who saved his changes to fooble.h over
your changes because you both had the file open at once, and somebody saved after
you did. There is a better way.</P>
<P>Revision control systems are not a new idea. They all implement these concepts:</P>
<UL>
<LI><I>Check out a file</I>--By bringing a copy of a file to your desktop from a
central library or repository, you mark the file as unavailable to others who might
want to change it. (Some systems allow changes to source files by several developers
at once and can later merge the changes.)
<P>
<LI><I>Check in a file</I>--When your changes are complete, you return the file to
the library. You provide a brief description of what you've done, and the RCS automatically
adds your name, the date, and other files affected by this change.
<P>
<LI><I>Merge changes</I>--Some RCS systems can accept check-ins by different developers
on the same file and will make sure that both sets of changes appear in the central
file.
<P>
<LI><I>Change tracking</I>--Some RCS systems can reconstruct earlier versions of
a file by working backwards through a change log.
<P>
<LI><I>History</I>--The information added at check-in can form a nice summary of
what was done to each file, when, and why.
</UL>
<P>Microsoft's Visual SourceSafe is a good revision control system that many developers
use to keep their code in order. What sets Visual SourceSafe apart from other RCS
systems? It's project oriented, it hooks into Visual C++ (through the new SCCI interface,
some other RCS systems can also hook in), and it comes with the Enterprise Edition
of Visual C++.</P>
<P>When you install Visual SourceSafe, choose a custom installation and select Enable
SourceSafe Integration. Doing this adds a cascading menu to Developer Studio's Project
menu, shown in Figure 23.33. To enable the items on the menu, you must add your project
to source control by choosing Add to Source Control and logging into Visual SourceSafe.</P>
<P><A HREF="javascript:popUp('23uvc33.gif')"><B>FIG. 23.33</B></A><B> </B><I>Installing
Visual SourceSafe adds a cascading menu to the Project menu.</I></P>
<P>The items on the menu are as follows:</P>
<UL>
<LI><I>Get Latest Version</I>--For selected files, replace your copies with newer
copies from the library.
<P>
<LI><I>Check Out</I>--Start to work on a file.
<P>
<LI><I>Check In</I>--Finish working on a file and make your changed versions available
to everyone.
<P>
<LI><I>Undo Check Out</I>--Give back a file without making any changes or an entry
in the history.
<P>
<LI><I>Add to Source Control</I>--Enable source control for this project.
<P>
<LI><I>Remove from Source Control</I>--Disable source control for this project.
<P>
<LI><I>Show History</I>--Display the changes made to selected files.
<P>
<LI><I>Show Differences</I>--Display the differences between old and new files.
<P>
<LI><I>SourceSafe Properties</I>--See information that SourceSafe keeps about your
files.
<P>
<LI><I>Share from SourceSafe</I>--Allow other developers to work on selected files.
<P>
<LI><I>Refresh Status</I>--Update your display with status changes made by other
developers.
<P>
<LI><I>SourceSafe</I>--Run Visual SourceSafe to see reports and summaries.
</UL>
<P>You must have an account and password set up in Visual SourceSafe before you can
put a project under source control and use these features. Run Visual SourceSafe
from this menu to perform any administrative tasks that haven't already been taken
care of for you.</P>
<P>Unless you are the only developer who will work on your project, you simply must
use a revision control system. Visual SourceSafe is good: It works from within Developer
Studio, and if you have the Enterprise Edition of Visual C++, it's free. What more
could you want? Install it, learn it, use it. You won't regret it.</P>
<BLOCKQUOTE>
<P>
<HR>
<strong>TIP:</strong> Revision control systems work on Web pages, database contents, documentation,
bug lists, and spreadsheets as well as they do on code and program files. After you
get in the habit and see the benefits, you won't stop.
<HR>
</P>
</BLOCKQUOTE>
<CENTER>
<P>
<HR>
<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> </P>
<P>© <A HREF="../copy.htm">Copyright</A>, Macmillan Computer Publishing. All
rights reserved.
</CENTER>
</BODY>
</HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -