Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.
In this lesson, you learn how to add a NOT NULL constraint on a column.
Every product in the Products table must have an associated product ID. Therefore, for each row in the Products table, the ID column must contain a value.
You can ensure that each row in the column contains a value for the ID column by defining the column as NOT NULL.
By default, columns allow NULLs, but you should explicitly declare columns NOT NULL unless there is a good reason to allow NULLs. See NULL value.
Open the Tables folder.
Select the Products table in the left pane, and then click the Columns tab in the right pane.
Select the ProductID column.
From the File menu, choose Properties to open the Column property sheet.
On the Constraints tab, select Values Cannot be NULL.
This lesson and the previous lesson introduced the basic concepts you need to know to create database tables. You can practice what you have learned by adding some more tables to your database. These tables are used in the subsequent lesson in this chapter.
Add the following tables to your database:
Customers Add a table named Customers, with the following columns:
ID An identification number for each customer. This column has integer data type, and is the primary key. Make this an autoincrement column.
CompanyName The company name. This column is a char data type, with a maximum length of 35 characters.
SalesOrders Add a table named SalesOrders, with the following columns:
ID An identification number for each sales order. This column has integer data type, and is the primary key. Make this an autoincrement column.
OrderDate The date on which the order was placed. This column has date data type.
CustomerID The identification number of the customer who placed the sales order. This column has integer data type.
SalesOrderItems Add a table named SalesOrderItems with the following columns:
ID The identification number of the sales order of which the item is a part. This column has integer data type, and should be identified as a primary key column.
LineID An identification number for each sales order. This column has integer data type, and should be identified as a primary key column.
ProductID The identification number for the product being ordered. This column has integer data type.
You have now created four tables in your database. The tables are not yet related in any way. In the next lesson, you define foreign keys to relate the tables to one another.