There lot variety ddl statements across rdbms vendors
118 | Figure 4-25 |
|
Databases Demystified |
---|
The CREATE TABLE Statement
TABLE statement adds a new table to the database. Here is an example using the EMPLOYEES table:
119 |
---|
JOB_ID VARCHAR2(10) NOT NULL, SALARY NUMBER(8,2) NULL, COMMISSION_PCT NUMBER(2,2) NULL, MANAGER_ID NUMBER(6) NULL, DEPARTMENT_ID NUMBER(4) NULL) ;
Note that a comma-separated list of columns is provided, along with the data type and NULL or NOT NULL specification for each. You may recall that data types were discussed in Chapter 2 and that there is a wide variation in supported data types across RDBMS vendors. The data types shown here apply to Oracle. Be careful with NULL and NOT NULL specifications. In most RDBMSs, including Oracle, NULL is the de-fault. However, in others, such as Sybase and Microsoft SQL Server, NOT NULL is the default. It is therefore safer, but of course more work, to always specify either NULL or NOT NULL. Incidentally, most RDBMSs require that primary key columns be specified as NOT NULL. You’ll see how to create a primary key constraint on the EMPLOYEE_ID column of this table in the “Primary Key Constraints” section a little further along in this chapter.
Because the implementation of constraints is the way we enforce business rules in the database, we will take a closer look at them here. In Oracle, it is important to name the constraints because the names appear in any error messages generated when constraint violations take place.