Archu
Archu
In
oracle, tables are created using CREATE TABLE command which in one of the important DDL statement. The CREATE TABLE command specifies the name of the table, name of the columns in the table as well as the data types and if required constraints associated with each column of the table. In create command various variables are defined as follows:-
Schema:-this represents a schema name or the user name to which the table
belongs. If it is omitted then oracle creates the table in users own schema.
Table name:-this represents the name of the table to be created. Column_name1:- through column_namen represents the name of the
columns to be created in the table.
each column. When a data type is assigned to a column it must have a length and scale, depending on which data type is being specified.
The syntax for creating a table is CREATE TABLE [Schema.]<table_name> ( <column_name1><data_type> [DEFAULT<expression>] [<column constraints>] [, <column_name2><data_type> [DEFAULT<expression>] [<column constraints>]] [,] [, <column_namen><data_type> [DEFAULT<expression>] [<column constraints>]] [, <table constraints>] );
subquery. These column specification are optional. If you dont specify it, then all the columns specified in the select statement would be returned.
Alter:-the alter table statement helps the designer to make a necessary changes
to the existing table instead of creating the table from the scratch. the syntax is:-
Alter table<tablename> Add (column_specification|constraint _specification Column_specification|constraint specification); Where table name corresponds to the name of the table, colomn_specification corresponds to the valid specification for a column and a constraint specification corresponds to valid constraints specification.
Modify columns:- the alter table statement also offers the ability to
modify columns/constraints in the existing table without impacting any other data in the table. Using alter table statement we can increase or decrease the column
widths, changing a column from mandatory to optional (not null to null ) and vice versa. The syntax is: ALTER TABLE<tablename> MODIFY (column_specification| constraint_specification., Column_specification|constraint_specication);
Drop column: - we can not only modify columns that exist in our table but
we can also drop them entirely if it is no longer required. When a constraint is dropped, any associated index with that constraint is also dropped. The syntax for dropping a column is:ALTER TABLE<TABLENAME>DROP COLUMN<COLUMNNAME>; This syntax is valid if you want to drop one column at a time.
Renaming tables:- Oracle provides the facility to change the name of the
table by using a ALTER TABLE statement when you rename the table. Oracle automatically updates foreign keys, in the data dictionary but it doesnt update a stored code modules, stored queries, client applications. The syntax for renaming the table is:ALTER TABLE<old_tablename> RENAME TO <new _tablename>; OR RENAME <old_tablename> to <new_tablename>;
DML Statements:- DML statements are used to work with the data
in tables. When you are connected to most multi-user databases (whether in a client program or by a connection from a Web page script), you are in effect working with a private copy of your tables that cant be seen by anyone else until you are finished (or tell the system that you are finished). You have already seen the SELECT statement; it is considered to be part of DML even though it just retrieves data rather than modifying it. The dml statement are categorized into four basic statements:-
row to a table. to insert a new row into a table, the table must be in your own schema or you must have privilege on the table. only one row is inserted at a time. we can insert literal values, expressions contains operators and functions, null values etc only. the syntax is:Insert into <table_name> [(<columnname1>[,<columnname2>]..[,<columnnamen>])] Values (<columnvalue1>[,<columnvalue2>][,<columnvaluen>]);