Download Wiley Beginning T-SQL with Microsoft SQL Server 2005 and 2008
Transcript
Chapter 1: Introducing T-SQL and Data Management Systems SQL Server supports additional data types, listed in the following table, that can be used in queries and programming objects, but they are not used to define columns. Data Type Description cursor The cursor data type is used to point to an instance of a cursor. table The table data type is used to store an in-memory rowset for processing. It was developed primarily for use with the table-valued functions that were introduced in SQL Server 2000. Nullability All rows from the same table have the same set of columns. However, not all columns will necessarily have values in them. For example, a new employee is hired, but he has not been assigned an extension yet. In this case, the extension column may not have any data in it. Instead, it may contain null, which means the value for that column was not initialized. Note that a null value for a string column is different from an empty string. An empty string is defined; a null is not. You should always consider a null as an unknown value. When you design your tables, you need to decide whether to allow a null condition to exist in your columns. Nulls can be allowed or disallowed on a column-by-column basis, so your employee table design could look like that shown in Figure 1-6. Figure 1-6 Relationships Relational databases are all about relations. To manage these relations, you use common keys. For example, your employees sell products to customers. This process involves multiple entities: ❑ The employee ❑ The product ❑ The customer ❑ The sale To identify which employee sold which product to which customer, you need some way to link together all the entities. Typically, these links are managed through the use of keys — primary keys in the parent table and foreign keys in the child table. 14