Labels

2017 absence absence management Account accounting AIM aliases AME and API application application utilities lookups approval assignments ATO Australia Bank bi publisher budget business business groups CAGR candidates cartisian product case CEMLI Center Stage channels Classification competency concurrent Configuration configuration profile constants contextualization conversion correction cost costing coverage area customization data database date DateTracked deductions define design develop DFF diagnostics document earnings ebs EIT Element employee enhancements erp excel expression extension failure Fastformula FBT Flexfield FND fndload foreign key forms Formula fringe benefit FRM-40654 from FTE Functions fund fusion GL global transfer grade help hierarchy HR HRMS human resource management system implementation income information interfaces internet interview job join key flexfield KFF KPI language learning leave legal employer legislation links lists localization location management New Year obia obiee OLF onboarding oracle oracle applications oracle descriptive flex field oracle descriptive flexfield oracle ebs oracle erp oracle fusion HCM oracle hrms oracle hrms interview questions oracle hrms modules oracle hrms modules list oracle hrms organization oracle hrms table oracle hrms tables oracle hrms tutorial oracle irecruitment oracle legal entities oracle lookups oracle organization hierarchy oracle payroll oracle payroll interview questions oracle payroll tables oracle self service order by Organization organization type otbi package package body package specification patch payg Payment payroll people group perform person personalisation phase pl/sql position primary key process profile programs project qualifier Query question questions Recruiting Center Recruitment regex regular expression reporting tool reports requests requirement requisition resume retropay RICE salary schema security profile select SIT smartorg sql statutory stores STP Super Superannuation system systems Table Taleo taleo 15B Taleo Recruitment tax termination test testing trunc update user group user management user type value set variables View Views Web ADI webadi where work relationship

Tuesday, 10 November 2015

Oracle SQL Statement Types and Usage - Part I

Let me introduce SQL by statements type, here statements defines set of commands. Generally statements can fall under the following category
  • Data definition Language (DDL)
  • Data Retrieval or Query Language (DQL or DRL)
  • Data Manipulation Language (DML)
  • Data Control Language (DCL)
  • Transaction Control Language (TCL)

DDL commands are used to define the data base objects. The following commands are used to define data base objects.

  • create
  • alter
  • truncate
  • rename
  • drop

CREATE
create command defines a new database object, such as a database, user, table, view, trigger, index, macro, stored procedure, user-defined type, user-defined function, or user-defined macro, depending on the object of the CREATE request.

Syntax:
CREATE TABLE table_name
(column_1 column-definition,
column_2 column-definition,

column_n column_definition);

Examples:
CREATE TABLE DEPT
(DEPTNO NUMBER(2),
DNAME VARCHAR2(14),
LOC VARCHAR2(13) );

=======================

ALTER
ALTER statement to add a column, modify a column, drop a column, rename a column or rename a table.

Syntax for Single Column Addition:
ALTER TABLE table_name
ADD column_name column-definition;

Example of Single Column Addition:
alter table dept add dept_type varchar2(10);
alter table emp add end_date date;

Syntax for Multiple Column Addition:
ALTER TABLE table_name
ADD (column_1 column-definition,
column_2 column-definition,

column_n column_definition);

Example of Multiple Column Addition:
alter table add(dob date,
gender varchar2(10));

Syntax for Single Column Modification:
ALTER TABLE table_name
MODIFY column_name column_type;

Example of Single Column Modification:
alter table dept modify dept_type varchar2(10) not null;

Syntax for Multiple Column Modification:
ALTER TABLE table_name
MODIFY (column_1 column_type,
column_2 column_type,

column_n column_type);

Example of Multiple Column Modification:
alter table modify(dob date NOT NULL,
gender varchar2(6));

Note : We can’t modify any column if table contains data, means if you want to increase range of data then table should be empty.

Syntax for dropping a column from an existing table:
ALTER TABLE table_name
DROP COLUMN column_name;

Example of drop a column in an existing table:
ALTER TABLE emp
DROP COLUMN DOB;

Syntax for renaming a column in an existing table:
ALTER TABLE table_name
RENAME COLUMN old_name to new_name;

Example of rename a column in an existing table:
ALTER TABLE emp
RENAME COLUMN dob to date_of_birth;

Syntax to rename a table:
ALTER TABLE table_name
RENAME TO new_table_name;

Example of rename a table:
ALTER TABLE emp
RENAME TO employee;

=======================

TRUNCATE
By using this command, we can delete data of the table but definition of the object will remain same.

Syntax:
truncate table table_name;
Example:
truncate table emp;

=======================

DROP
By using this command we can delete table permanently from database.

Syntax:
drop table table_name;
Example:
drop table emp;

No comments:

Post a Comment