0% found this document useful (0 votes)
55 views3 pages

Oracle SQL Notes

A database is a collection of tables that store data. A DBMS (database management system) is software that allows users to store and access data in databases. SQL commands are used to manage databases and include DDL commands like CREATE, ALTER, DROP and RENAME for defining and modifying database objects, and DML commands like INSERT, UPDATE, and DELETE for manipulating the data. For example, the CREATE TABLE statement is used to create a new table, INSERT adds new records to tables, and UPDATE modifies existing records in tables.

Uploaded by

gadhireddy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
55 views3 pages

Oracle SQL Notes

A database is a collection of tables that store data. A DBMS (database management system) is software that allows users to store and access data in databases. SQL commands are used to manage databases and include DDL commands like CREATE, ALTER, DROP and RENAME for defining and modifying database objects, and DML commands like INSERT, UPDATE, and DELETE for manipulating the data. For example, the CREATE TABLE statement is used to create a new table, INSERT adds new records to tables, and UPDATE modifies existing records in tables.

Uploaded by

gadhireddy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 3

ORACLE SQL

INTRODUCTION
Database
 A database is the place of storage of the data in the form of tables
 Data means information which is very useful. A database is also collection of 1 or
more tables.
DBMS
 DBMS – stands for Database Management System
 DBMS is a database s/w which allows us to store the data in the form of tables.
SQL COMMANDS
1) Data Definition Language (DDL) Command:
a) Create
b) Alter
c) Drop
d) Rename
e) Truncate
a) create
Create table:-
The CREATE TABLE statement is used to create a new table in the database.
Syntax
CREATE TABLE tablename (
Column1 datatype, Column2 datatype, Column3 datatype,
);
example:
CREATE TABLE employee (
employee_id NUMBER PRIMARY KEY,
first_name VARCHAR2(20),
last_name VARCHAR2(20)
);

b) Alter
ALTER TABLE:-
The ALTER TABLE statement is used such as adding and removing columns or renaming the
columns modify columns, drop columns table.

 Syntax Add:-
ALTER TABLE tablename ADD Columnname Datatype;

example:
ALTER TABLE customer ADD customer_type VARCHAR(20);

 Syntax Drop:-
ALTER TABLE tablename DROP column Columnname;
example:
ALTER TABLE customer DROP customer_type;
 Syntax Modifying:-
ALTER TABLE tablename MODIFY column_name Datatype;
example:
ALTER TABLE customer MODIFY customer_type varchar2(7);
Modify Multiple columns in table
Syntax
ALTER TABLE table_name
MODIFY (column_1 column_type,
column_2 column_type,
...
column_n column_type);
example:
ALTER TABLE customers
MODIFY (customer_name varchar2(100) NOT NULL,
city varchar2(75) DEFAULT 'Seattle' NOT NULL);
Rename column in table
 Syntax Rename:-
ALTER TABLE table_name RENAME COLUMN old_name TO new_name;
example:
ALTER TABLE customers RENAME COLUMN customer_name TO cname;
Rename table
Syntax
ALTER TABLE table_name RENAME TO new_table_name;
example:
ALTER TABLE customers RENAME TO contacts;
c) Drop
The Oracle DROP TABLE statement allows you to remove or delete a table from the Oracle
database.
Syntax
Drop TABLE table_name;
example:
Drop TABLE customers;
d) Rename
Syntax
RENAME TABLE table-Name TO new-Table-Name;
example:
RENAME TABLE customers To cus;
e) Truncate
The TRUNCATE TABLE statement is used to remove all records from a table structure will
remains for future use . If you truncate a table, the TRUNCATE TABLE statement can not be
rolled back.
Syntax
TRUNCATE TABLE table-Name;
example:
TRUNCATE TABLE emp;

2) Data Manipulation Language (DML) command:-


a) Insert
b) Update
c) Delete
d) Merge
a) Insert
In Oracle, INSERT statement is used to add a single record or multiple records into the table.
Method1:-
Syntax
INSERT INTO table (column1, column2, ... column_n )
VALUES (expression1, expression2, ... expression_n );
example:
INSERT INTO emp (emp_id, emp_name, emp_phno )
VALUES (223344, ‘ashokkumar’,9581842222);
Method2:-
Syntax
INSERT INTO table _name VALUES (expression1, expression2, ... expression_n );
example:
INSERT INTO emp VALUES (223344, ‘ashokkumar’,9581842222);

b) Update
The update statement is used to modify the existing records in a table.
Syntax
Update table_name set column name=new values where column=old value;
Update table_name set column1=new value,column2=new value where column2=old
value2;
example:
Update emp set ename=’raghu’,city=’tpt’ where mobile_number=9955886644;

c) Delete
The delete statement is used to delete existing records into table

Method1:-
Syntax
Delete from table_name where condition;
example:
Delete from emp where empid=555555;

Method2:-
Syntax

You might also like