0% found this document useful (0 votes)
65 views10 pages

Archu

The document discusses Oracle database concepts related to creating, altering, and manipulating tables. It describes how to create tables using the CREATE TABLE statement by specifying the table name, columns, data types, and constraints. It also covers altering existing tables using the ALTER TABLE statement to add, modify, or drop columns and constraints. Additional topics covered include creating tables from existing tables, dropping tables, renaming tables, and inserting data using DML statements.

Uploaded by

Aabha Duggal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views10 pages

Archu

The document discusses Oracle database concepts related to creating, altering, and manipulating tables. It describes how to create tables using the CREATE TABLE statement by specifying the table name, columns, data types, and constraints. It also covers altering existing tables using the ALTER TABLE statement to add, modify, or drop columns and constraints. Additional topics covered include creating tables from existing tables, dropping tables, renaming tables, and inserting data using DML statements.

Uploaded by

Aabha Duggal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 10

Create: - In order to store and manage data, it is necessary to create tables.

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.

Data type:- it represents the data type of

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.

Default<expression>:-it specifies the value to be assigned to a column


if a subsequent INSERT statement omits a value for the column.

Column constraints:-the constraints are the rules that must be satisfied


for the value in the column to be valid. Column .constraints are applied only to individual column.

Table constraint:-the constraints that we apply to group of one columns.


at table level, one can define any constraints except NOTNULL.

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>] );

Create table from an existing table:- It is possible to create


tables from the existing tables. It is useful when you want to select the data out of the table for temporary modification or you want to create a table similar to the existing table and fill it with similar data. This can be done using the CREATE TABLE <tablename> AS SELECT statement. The syntax is, CREATE TABLE<tablename> [(<columnname1>, <columnname2>.)] AS SELECT STATEMENT; where <columnname1>,<columnname2> are used to specify different column names to be associates with the values returned by the

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.

Drop table:- Sometimes it is necessary to remove table from a database


completely that is no longer needed. It can be done by using DROP TABLE command. The DROP TABLE command removes a table from the database. All the tables row, indexes and privileges will also be removed. The syntax for dropping a table is:Drop table<tablename> [CASCADE CONSTRAINTS];

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:-

INSERT UPDATE SELECT DELETE

INSERT Statements:-the insert statement is used to add a new

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>]);

You might also like