SQL Commands
SQL Commands
Example
ALTER TABLE
ALTER TABLE table_name ADD column_name datatype or ALTER TABLE table_name DROP COLUMN column_name
AS (alias)
SELECT column_name AS column_alias FROM table_name or SELECT column_name FROM table_name AS table_alias SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2
BETWEEN
CREATE USER database_name identified by Grant conect to user CREATE TABLE table_name ( column_name1 data_type, column_name2 data_type, column_name2 data_type,
or
CREATE UNIQUE INDEX index_name ON table_name (column_name) CREATE VIEW CREATE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition DELETE DELETE FROM table_name WHERE some_column=some_value or
DELETE FROM table_name (Note: Deletes the entire table!!) DELETE * FROM table_name (Note: Deletes the entire table!!) DROP user user_name DROP INDEX table_name.index_name
DROP TABLE table_name SELECT column_name, aggregate_function(column_n FROM table_name WHERE column_name operator value GROUP BY column_name
HAVING
SELECT column_name, aggregate_function(column_n FROM table_name WHERE column_name operator value GROUP BY column_name HAVING aggregate_function(column_n SELECT column_name(s) FROM table_name WHERE column_name IN (value1,value2,..)
IN
INSERT INTO
INSERT INTO table_name VALUES (value1, value2, value3,....) or INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,....) SELECT column_name(s) FROM table_name1 INNER JOIN table_name2 ON table_name1.column_name= SELECT column_name(s)
INNER JOIN
LEFT JOIN
LEFT JOIN FROM table_name1 LEFT JOIN table_name2 ON table_name1.column_name= SELECT column_name(s) FROM table_name1 RIGHT JOIN table_name2 ON table_name1.column_name= SELECT column_name(s) FROM table_name1 FULL JOIN table_name2 ON table_name1.column_name= SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern SELECT column_name(s) FROM table_name ORDER BY column_name [ASC|DESC] SELECT column_name(s) FROM table_name SELECT * SELECT * FROM table_name SELECT DISTINCT SELECT DISTINCT column_name(s) FROM table_name SELECT INTO SELECT * INTO new_table_name [IN externaldatabase] FROM old_table_name or
RIGHT JOIN
FULL JOIN
LIKE
ORDER BY
SELECT
SELECT column_name(s) INTO new_table_name [IN externaldatabase] FROM old_table_name TRUNCATE TABLE UNION TRUNCATE TABLE table_name SELECT column_name(s) FROM table_name1 UNION SELECT column_name(s) FROM table_name2 SELECT column_name(s) FROM table_name1 UNION ALL SELECT column_name(s) FROM table_name2 UPDATE table_name SET column1=value, column2=value,... WHERE some_column=some_value SELECT column_name(s) FROM table_name WHERE column_name operator value CREATE SEQUENCE abc SELECT squence.NEXTVAL FROM DUAL; SELECT sqquence.CURRVAL FROM DUAL; CREATE OR REPLACE PROCEDURE proc_backup IS CREATE OR REPLACE PROCEDURE procedure_name BEGIN insert into emp_backup select * from emp; IS EXEC procedure_name EXEC proc_backup; DESC table_name DESC EMP; show user Commit Rollback SHOW ERR show compilation error after compiling a procedure.
UNION ALL
UPDATE
WHERE
Sequence
Example
ROCEDURE proc_backup IS
DESC EMP;
DESC EMP;
Description
Description of data dictionary tables and views ALL_COL_COMMENT Comments on columns of accessible tables S and views
ALL_CONSTRAINTS
ALL_CONS_COLUMN Information about accessible columns in S constraint definitions Current errors on stored objects that user is ALL_ERRORS allowed to create
ALL_INDEXES
ALL_IND_COLUMNS
Description of LOBs contained in tables accessible to the user ALL_OBJECTS Objects accessible to the user Description of all object tables accessible to ALL_OBJECT_TABLES the user Description of SEQUENCEs accessible to the ALL_SEQUENCES user Current source on stored objects that user is ALL_SOURCE allowed to create ALL_SYNONYMS All synonyms accessible to the user Description of relational tables accessible to ALL_TABLES the user ALL_LOBS ALL_TAB_COLUMNS Columns of user's tables, views and clusters
Columns of user's tables, views and clusters Comments on tables and views accessible to the user Triggers accessible to the current user Column usage in user's triggers or in triggers on user's tables
ALL_UPDATABLE_CO Description of all updatable columns LUMNS ALL_USERS ALL_VIEWS Information about all users of the database Description of views accessible to the user
DATABASE_COMPATI Database compatible parameter set via BLE_LEVEL init.ora DBA_DB_LINKS All database links in the database Current errors on all stored objects in the DBA_ERRORS database DBA_OBJECTS All objects in the database DBA_ROLES All Roles which exist in the database DBA_ROLE_PRIVS Roles granted to users and roles DBA_SOURCE DBA_TABLESPACES DBA_TAB_PRIVS DBA_TRIGGERS DBA_USERS DBA_VIEWS DICT_COLUMNS Source of all stored objects in the database Description of all tablespaces All grants on objects in the database All triggers in the database Information about all users of the database Description of all views in the database
Description of columns in data dictionary tables and views GLOBAL_NAME global database name PRODUCT_COMPON version and status information for ENT_VERSION component products ROLE_TAB_PRIVS Table privileges granted to roles SESSION_PRIVS SESSION_ROLES Privileges which the user currently has set Roles which the user currently has enabled.
SYSTEM_PRIVILEGE_ Description table for privilege type codes. MAP Maps privilege type numbers to type names TABLE_PRIVILEGES Grants on objects for which the user is the grantor, grantee, owner, or an enabled role or PUBLIC is the grantee
Create primary key on a table . Find from system table name of the primary key. Find from system tables name of the columan on which key exists. Make a query to show all key names, key type and columan names on which key exists. Do simailar thing for indexe. find the 3rd highest salary Find name , id of employee whose JOB =salesman but gets higher salary than avergae salary of JOB =manager.
insert all data of emp table into emp_backup table; do the same thing again; then write query to delete the duplicate rows fr Grant select priviledge on a table to another user. From another user login, check if table appears in ALL_TABLES list of not. Find the procedures on which you have execute access. What is subquery ? What is co-related subquery? What is cartesian prodcut? Select top three highest paid people in each depart.
How to find connect string from sql? Find the oracle home Find connect string
connect.GIF