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

Oracle SQL Commands Overview

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views3 pages

Oracle SQL Commands Overview

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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

Common questions

Powered by AI

The UPDATE command can modify multiple columns simultaneously by specifying each column and its new value in the SET clause of the UPDATE statement. For example, "UPDATE emp SET ename='raghu', city='tpt' WHERE mobile_number=9955886644" modifies both the name and the city of a record. However, this action carries risks such as inadvertently updating incorrect records if the WHERE clause is not precise, leading to data inconsistency or loss .

To ensure safe DELETE operations in a transactional database, one can employ strategies such as using specific conditions in the WHERE clause to target only the intended records, thus preventing accidental data loss. Incorporating transaction management, like BEGIN and COMMIT, allows rollback in case of errors. Implementing logging and auditing provides traceability of changes. Additionally, backups should be taken prior to large delete operations to facilitate data recovery if required .

Using the DROP TABLE command permanently deletes a table from the database, making data recovery challenging unless there is a backup. This command does not allow for a rollback, meaning once a table is dropped, all associated data and relationships are lost, potentially disrupting system dependencies like foreign key constraints. It is crucial to ensure that the table is no longer needed or suitably backed up before performing this action to prevent unintentional data loss .

DDL (Data Definition Language) and DML (Data Manipulation Language) serve distinct roles within a DBMS. DDL commands, such as CREATE, ALTER, and DROP, are used to define or modify the database schema, including structures like tables and relationships, thus shaping the database's form and constraints. DML commands, like INSERT, UPDATE, and DELETE, manage the data within these structures, allowing users to perform CRUD (Create, Read, Update, Delete) operations. Both are essential: DDL for setting up and maintaining the database's structure, and DML for data interaction and transformation .

Batch processing INSERT statements can significantly enhance performance by reducing the number of database calls, thus lowering overhead and network latency. This approach is beneficial for efficiently handling large data volumes. However, drawbacks include increased complexity in error handling, as identifying and addressing problems within a batch is less straightforward. Additionally, transactions may lock resources longer due to the more extensive data handled in a single execution .

Improper use of the RENAME TABLE command in a multi-user environment can lead to severe consequences such as application downtime or data inconsistency. If one user renames a table that other users or applications depend on, these dependencies break, leading to runtime errors. Additionally, if changes aren't immediately communicated or reflected in application code, this can cause widespread failure in database operations, undermining system integrity and operational continuity .

The ALTER TABLE command increases flexibility in managing table structures by allowing modifications such as adding or dropping columns, changing data types, and renaming columns or the table itself. Specific use cases include adding a new column to store additional data, changing a column’s data type to accommodate larger data (e.g., VARCHAR(20) to VARCHAR(50)), and renaming a column for clarity or convention alignment .

The CREATE TABLE command should be preferred over using an existing table when new, unrelated data structures are required, ensuring separation of concerns and reducing unintended side-effects on current data. It is essential in scenarios involving different logical entities or when system performance could benefit from partitioning. Also, if data constraints, indexing, or relationships differ from existing tables, a new table better encapsulates these specificities, aligning with normalization principles .

The ALTER TABLE command plays a critical role in maintaining database integrity and consistency by allowing modifications that adapt the schema to meet evolving requirements. It can enforce constraints (e.g., NOT NULL or UNIQUE), adjust data types for improved accuracy, and add indexes to aid in relational integrity. By enabling these strategic modifications, ALTER TABLE ensures that data adheres to the necessary rules and relational structure, preventing anomalies .

The primary difference between the TRUNCATE and DELETE operations in SQL is that TRUNCATE is used to remove all records from a table but does not allow for rollback, meaning the operation is not reversible once executed. TRUNCATE also resets any auto-increment counters linked to the table. On the other hand, DELETE is used to remove specific records from a table based on a condition and allows for rollback when used within a transaction, thus providing the possibility to undo the deletion if necessary .

You might also like