![]() |
SQL Data Definitions![]() ![]() ![]() ![]() ![]()
The Data Definition Commands of SQL*Plus control the creation, modification and removal of database objects. The first step is establishing a database is to create one or more tables to hold you area. Therefore table can be created by using the CREATE TABLE statements. The general syntax of this statement is CREATE TABLE tablename (column1 datatype(size) default < expr > [CONSTRAINT constraint name) [colunm constraint][enabl/disable], column2 datatype... The table name must be a legal SQL*Plus name and it must not conflict with the name of any of your existing tables An < expr > expression is a combination of one or more values, operators, and SQL functions that.,, evaluates to a value. Column_constraint defines an integrity constraint as part of the column definition. The constraints are as follows <b>DEFAULT</b> specifies a value to be assigned to the column. The datatype of the expression, must match the datatype of the column.<br> <b>NULL</b> specifies that a column can contain null values<br> SQL > CREATE TABLE EMP 2 (EMPNO NUMBER(4) NOT NULL, ENAME CHAR(12) NOT NULL, 3 JOB CHAR(10), JOIN DT DATE NOT NULL, DEPTNO NUMBER(4) NOT NULL); Table created. Now if you want to know how the columns have been defined type as shown below: SQL> DESCRIBE EMP This lists the columns and their definitions for the EMT table. Once a table has been created there may be a need to change the format of an
existing table ALTER TABLE command with modify can be used to increase the maximum
width of a CHAR or NUMBER field. The General format is as: [ENABLE/DISABLE CONSTRAINT constraint name]; To all the job column width upto 12 characters, enter. SQL > ALTER TABLE EMP MODIFY (JOB CHAR(10)); Table altered. You can change a column from NOT NULL to NULL by adding the NULL clause to the end of the column specifications as: ALTER TABLE <table name> MODIFY(column name > < data type > NULL); To add a new column to a table, you can use the ALTER TABLE command with an ADD clause. The general format of the command statement is as ALTER TABLE <table name> [ADD (< column_definitions >)[ENABLE/DISABLE]]; To add more than one column, use commas within the parentheses to separate each column. The rules for adding a column to a table: 1. You may add a column at any time if NOT NULL isn't specified. a) Add the column without NOT NULL specified. b) Fill every row in that column with data. c) Modify the column to be NOT NULL. 3. You can change its data type. 4. You can decrease a CHAR column's width. 5. You can decrease the number of digits in a NUMBER column. To remove a table from your database use DROP TABLE <table name> [CASCADE CONSTRAINTS]: CASCADE CONSTRAINTS drops all referential integrity constraints that refer to primary and unique keys in the dropped table. To insert data's into the already created table we use INSERT command. The format is INSERT INTO < table name > VALUES(< a list of data values >): To enter data in the EMP table type SQL> INSERT INTO EMP 2 VALUES (23,'KHANNA, MANAGER,'12 JUN 95',50000,3); 1 row created. If there are several fields which are null in your table, then SQL provides you with a short cut instead of specifying null for each blank column, list only the columns and values that you want to enter.
|
|
Domain NamesSQL Database Management Systems Relational Database Management System Properties of RDBMS Client Server Computing Oracle Relational Database Database Structure and Space Management SQL Data Types How to Use Data Types? What is Operators and Conditions Character OperatorsOperator Precedence Data Retrieval Using SQL Plus SQL Data Definitions Data Retrieval Using Select SQL Operator Precedence Selecting Rows and Columns The Group by Clause
Having Clause Union, Union all, Intersact and Minus Commands Playing with Numbers Date Functions Example of Date Arithmetic Working with Null Values
Joining Tables and Subqueries Views Synonyms Indexes Clusters Sequences Formatting Query Results with SQL Plus Data Integrity The Optimizer How Oracle Optimizes SQL Statements Evaluating Expression and ConditionsOptimization Hints PL-SQL PL-SQL Architecture Error Reporting Functions Character Functions Composite Data Types PL-SQL Structures How to use PL-SQL Structures Normalization Operator Precedence Cursor Error Handling Database Triggers Types of Triggers Locking Sub Programs Packages New and Improved Data Types Improved Select Statement Advanced Quering Improved Scalability Improved Performance Via Partitioning Object Relational Features Heterogeneous Data Access Improved Security Administration New Data Types Improved Select Statement Changes to the Select Statement Improved Scalability Data Partitioning Oriented Toward Objects Character Functions Creating Object Types Created Nested Tables Oracle8 and Distributed Database Oracle8 Database Management and Security Distributed Database Invoking Export Invoking ImportWeb DesignWeb HostingE Commerce |
| Home | Web Hosting | Web Design | Sitemap |
| Copyright (C) 2007. Web Domain design hosting. All rights reserved. |