Microsoft 9GD00001 Computer Accessories User Manual


 
Chapter 7: Working with Data 185
Adding Tables
The database itself will hold data for customers, orders, and order details that we introduced
in the preceding chapter. The data will be held in tables that we’ll create in this section. In
later sections, I’ll show you how to perform Create, Read, Update, and Delete (CRUD)
operations on this data. Right now, you’ll learn how to create the tables.
To create a table, right-click the Tables branch under the database in Server Explorer
and select Add New Table; you’ll see a Table Designer similar to Figure 7-3. Yours won’t
have the CustomerID or Name columns yet; that’s coming up next.
The Table Designer allows you to add columns and configure the data type (such as
integer, date, float, or character) and other details of each column and the table. Figure 7-3
shows a table with two columns, CustomerID of data type int and Name of data type
nvarchar(50). Ensure that Null is unchecked for each column to avoid errors in code that
doesn’t check for null later in this chapter.
NOTE
Databases, such as SQL Server, have their own type system, which doesn’t always
match the .NET type system perfectly. That said, there are types that match very well;
for instance, a SQL int is the same as a C# int or VB Integer. A SQL nvarchar(50)
can be matched with a C# string or VB String. However, the nvarchar is limited to
50 characters, or whatever length is specified in parentheses, but the C# string and VB
String don’t have a specified size. A full discussion of SQL types is out of scope, but you
should be aware that there are differences between SQL and .NET types.
Figure 7-3 The Customer table