Datasheet
Then you would add the foreign key, in the form of another constraint:
ALTER TABLE [dbo].[Product] WITH CHECK ADD CONSTRAINT [FK_Product_ProductCategory]
FOREIGN KEY ([ProductCategoryId])
REFERENCES [dbo].[ProductCategory] ([ProductCategoryId])
GO
Here the FK_Product_ProductCategory foreign key is added, linking the
Product.ProductCategoryId column with the ProductCategory.ProductCategoryId column.
There are several
CREATE statements in the SQL vocabulary, each of which has a corresponding ALTER
statement and also a corresponding DROP statement. Dropping an object means deleting it from the
DBMS. This operation doesn’t use the
DELETE keyword, which is used for deleting data; mixing up these
commands is potentially disastrous.
Although this chapter introduces a number of commands, you are far more likely to carry out these
operations via a GUI for day-to-day use. That’s fine, because making even simple mistakes with queries
of this sort can cause irreparable damage.
The most useful thing about these statements so far is that they can be combined together into script
files. Script files can be extremely useful for automating lengthy tasks, and the first place you will see
one of these in action is in the next chapter. You will execute a SQL script file that creates the database
that you will be using for examples throughout the book. The script file contains a complete database,
including multiple tables, table data, and other database objects. If you were to add all of this by hand it
would take a long time indeed, but executing a script takes hardly any time at all.
XML
As noted earlier, XML is a text-based format for the storage of data. It consists of two features: data and
markup. Because it is “just” text, it can be read and understood on just about any computer system in
existence, and its well-defined format makes it easy to process. It is also possible to define vocabular-
ies — that is, systems of markup unique to an application or shared among many applications. As such,
XML has become the universal language of choice for the interchange of information between disparate
systems.
In the .NET Framework, XML is used extensively. For example, configuration files for all manner of
applications are written in XML, which makes it easy to edit configurations by hand or programmati-
cally using simple techniques. A rich set of types is defined by .NET to make it easy to manipulate XML
data in various ways. XML is also the basis of SOAP (Simple Object Access Protocol), the underlying
technology that makes web services both possible and platform-independent.
The rise of XML has continued unabatedly for several years, and knowledge of XML is now an essential
part of pretty much any area of computing. This applies to databases, too, and many DBMSes (including
SQL Server) now include tools for dealing with, consuming, and generating XML data.
The XML Format
This section cannot detail every aspect of the XML syntax, but it is a brief summary to reinforce the basic
concepts of XML. After all, the chances are that you will have come across XML before, and if you
haven’t, there are a huge number of excellent resources, in web and print form, to get you started.
30
Chapter 1
44063c01.qxd:WroxBeg 9/12/06 10:31 PM Page 30