12.07.2015 Views

Oracle SQL Developer

Oracle SQL Developer

Oracle SQL Developer

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Managing TablesIn most cases, you should only need columns of NUMBER, VARCHAR2, and DATE datatypes when creating a definition of a table.When defining numeric data, you can use the precision option to set the maximumnumber of digits in the number, and the scale option to define how many of the digitsare to the right of the decimal point. For example, a field to hold monetary valuesmight be defined as NUMBER(12,2), providing ten digits for the primary unit ofcurrency (dollars, pounds, marks, and so on) and two digits for the secondary unit(cents, pennies, pfennigs, and so on).To define a VARCHAR2 field for character data, you must include the size value. Set thesize to the maximum number of bytes (or, optionally, characters) to be stored in thecolumn. A column to hold postal codes for different countries, for example, might berestricted to 12 bytes by defining it as VARCHAR2(12).DATE columns are automatically formatted by <strong>Oracle</strong> to include a date and timecomponent. Although both the date and time are stored in a date column, by default,the date portion is automatically displayed for you, when retrieving date data.However, <strong>Oracle</strong> Database enables you great flexibility in how you can display yourdates and times.4.2.2 Column Default ValuesSee Also: <strong>Oracle</strong> Database <strong>SQL</strong> Reference for a complete list of<strong>Oracle</strong>’s built-in data types.Default values are values that are automatically stored into the column whenever anew row is inserted without a value being provided for the column. When you definea column with a default value, any new rows inserted into the table store the defaultvalue unless the row contains an alternate value for the column. Assign default valuesto columns that contain a typical value. For example, in the departments table, ifmost departments are located at one site, then the default value for the location_idcolumn can be set to this value, such as 1700.Default values can help avoid errors where there is a number, such as zero, thatapplies to a column that has no entry. For example, a default value of zero can simplifytesting, by changing a test like this:IF salary >= 0 AND salary < 50000to the simpler form:IF salary < 50000Depending upon your business rules, you might use default values to represent zeroor FALSE, or leave the default values as NULL to signify an unknown value.Default values can be defined using any literal, or almost any expression includingSYSDATE, which is a <strong>SQL</strong> function that returns the current date.4.2.3 Ensuring Data Integrity With ConstraintsYou can define integrity constraints to enforce business rules on data in your tables.Business rules specify conditions and relationships that must always be true, or mustalways be false.When an integrity constraint applies to a table, all data in the table must conform tothe corresponding rule. When you issue a <strong>SQL</strong> statement that inserts or modifies datain the table, <strong>Oracle</strong> Database ensures that the new data satisfies the integrityconstraint, without the need to do any checking within your program.Database Objects: Usage Information 4-3

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!