Viewing the Structure of a Table


You use the DESCRIBE command to view the structure of a table. You can save some typing by shortening the DESCRIBE command to DESC ( DESC[RIBE] ). Knowing the structure of a table is useful because you can use the information to formulate a SQL statement. For example, you can figure out the columns you want to query in a SELECT statement.

Note  

You typically omit the semicolon character (;) when issuing SQL*Plus commands.

The following example uses the DESCRIBE command to view the structure of the customers table; notice that the semicolon character (;) is omitted from the end of the command:

 SQL>  DESCRIBE customers  Name Null? Type  --------------------- -------- --------------  CUSTOMER_ID NOT NULL NUMBER(38)  FIRST_NAME NOT NULL VARCHAR2(10)  LAST_NAME NOT NULL VARCHAR2(10)  DOB DATE  PHONE VARCHAR2(12) 

As you can see from this example, the output from the DESCRIBE command has three columns that show the structure of the database table:

  • Name    Lists the names of the columns contained in the table. In the example, you can see the customers table has five columns: customer_id , first_name , last_name , dob , and phone .

  • Null?    Indicates whether the column can store null values. If NOT NULL , the column cannot store nulls. If blank, the column can store null values. In the example, you can see the customer_id , first_name , and last_name columns cannot store null values, but the dob and phone columns can store null values.

  • Type    Indicates the type of the column. In the example, you can see the type of the customer_id column is NUMBER(38) and the type of the first_name is VARCHAR2(10) .

The next example uses the shortened DESC command to view the structure of the products table:

 SQL>  DESC products  Name Null? Type  --------------------- -------- --------------  PRODUCT_ID NOT NULL NUMBER(38)  PRODUCT_TYPE_ID NUMBER(38)  NAME NOT NULL VARCHAR2(30)  DESCRIPTION VARCHAR2(50)  PRICE NUMBER(5,2) 



Oracle Database 10g SQL
Oracle Database 10g SQL (Osborne ORACLE Press Series)
ISBN: 0072229810
EAN: 2147483647
Year: 2004
Pages: 217

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net