View is a syntax or script of query oracle syntax stored in database.
Basic syntax is :
CREATE or REPLACE VIEW view_name AS select column1,column2,... from table_name;
example :
CREATE or REPLACE VIEW v_customer AS select id_custmer,name from customer;
Modify Table Structure
Oracle basic syntax to modify table structure
Syntax 1
add a column into existing table
ALTER TABLE table_name
ADD column_name datatype;
example :
ALTER TABLE customer
ADD phone_number varchar(20);
Syntax 2
modify a data type of a field of existing table
ALTER TABLE table_name
MODIFY (column_name datatype);
example :
ALTER TABLE customer
MODIFY (name varchar(100));
Syntax 1
add a column into existing table
ALTER TABLE table_name
ADD column_name datatype;
example :
ALTER TABLE customer
ADD phone_number varchar(20);
Syntax 2
modify a data type of a field of existing table
ALTER TABLE table_name
MODIFY (column_name datatype);
example :
ALTER TABLE customer
MODIFY (name varchar(100));
create new table
Syntax 1
creating new table
----------------------------
CREATE TABLE table_name (
field1 datatype,
field2 datatype,
...);
example :
CREATE TABLE customer (
id number,
name varchar2(50));
Syntax 2
creating table from other existing table,
the structure of new table copied from source table.
----------------------------
CREATE TABLE table_name as select * from existing_table;
example :
CREATE TABLE customer2 as select * from customer;
creating new table
----------------------------
CREATE TABLE table_name (
field1 datatype,
field2 datatype,
...);
example :
CREATE TABLE customer (
id number,
name varchar2(50));
Syntax 2
creating table from other existing table,
the structure of new table copied from source table.
----------------------------
CREATE TABLE table_name as select * from existing_table;
example :
CREATE TABLE customer2 as select * from customer;
Label:
CREATE
Add column into existing table
Syntax 1
To add a column into an existing table :
ALTER TABLE table_name ADD column_name column-definition;
Contoh :
ALTER TABLE customers ADD name varchar2(50);
Syntax above adding column name into customers table with data type varchar2 dan length 50.
-------------------------------------------------
Syntax 2
To add columns into existing table:
ALTER TABLE table_name
ADD (
column_1 column-definition,
column_2 column-definition,
...
column_n column_definition );
Contoh:
ALTER TABLE customers
ADD ( name varchar2(50),
address varchar2(100),
country varchar2(45) );
Syntaxs above adding three fields name, address, and country into customers table.
To add a column into an existing table :
ALTER TABLE table_name ADD column_name column-definition;
Contoh :
ALTER TABLE customers ADD name varchar2(50);
Syntax above adding column name into customers table with data type varchar2 dan length 50.
-------------------------------------------------
Syntax 2
To add columns into existing table:
ALTER TABLE table_name
ADD (
column_1 column-definition,
column_2 column-definition,
...
column_n column_definition );
Contoh:
ALTER TABLE customers
ADD ( name varchar2(50),
address varchar2(100),
country varchar2(45) );
Syntaxs above adding three fields name, address, and country into customers table.
Label:
alter
Rename table name
Basic syntax for renaming table name
ALTER TABLE table_name RENAME TO new_table_name;
example :
ALTER TABLE suppliers RENAME TO customers;
this script will change table name from "table_name" to "new_table_name"
ALTER TABLE table_name RENAME TO new_table_name;
example :
ALTER TABLE suppliers RENAME TO customers;
this script will change table name from "table_name" to "new_table_name"
Label:
alter
Subscribe to:
Posts (Atom)