Some Basic SQLs in Oracle

— Find Tables in a Schema

— for SH schema

SELECT owner, table_name
FROM all_tables
where OWNER = ‘SH’;

— for HR Schema

SELECT owner, table_name
FROM all_tables
where OWNER = ‘HR’;


— Create table based on another table

DROP TABLE MyCustomer;

— Create the structure but no data

create table MyCustomer AS

Select Cust_ID, Cust_First_Name, Cust_Last_Name   

FROM sh.Customers

where ROWNUM < 0;

SELECT *

FROM MyCustomer;


DROP TABLE MyCustomer;

— Create both structure and bring data

create table MyCustomer AS

Select Cust_ID, Cust_First_Name, Cust_Last_Name   

FROM sh.Customers;

SELECT *

FROM MyCustomer;

BRING DATA FROM ANOTHER TABLE

— REMOVE ALL DATA FROM TABLE MyCustomer

TRUNCATE TABLE MyCustomer;

SELECT *

FROM MyCustomer;

— BRING DATA FROM ANOTHER TABLE

INSERT INTO MyCustomer

SELECT Cust_ID, Cust_First_Name, Cust_Last_Name

FROM SH.CUSTOMERS

FETCH FIRST 10 ROWS ONLY;

— SHOW INSERTED DATA

SELECT *

FROM MyCustomer;