Basic sql(oracle) queries

916 views

Published on

Some Basic sql(oracle) queries for beginners

Published in: Education, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
916
On SlideShare
0
From Embeds
0
Number of Embeds
654
Actions
Shares
0
Downloads
15
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Basic sql(oracle) queries

  1. 1. SQL(Oracle) QueriesDDL (Data definition language)TABLECreate table CREATE TABLE <table_name>(< column_name1><datatype> [<constraint>],< column_name2><datatype> *<constraint>+,…);Show tables list Select * from TAB;Describe table(table structure) DESCRIBE<table_name>;Delete/Drop table DROP TABLE<table_name>;Rename table RENAME <old_table_name>TO<new_table_name>;Add a column ALTER TABLE <table name>ADD <new_column_name><datatype> [<constraint>];Rename a column ALTER TABLE <table name>RENAME COLUMN<old_column_name>TO<new_column_name>;Delete a column ALTER TABLE <table name>DROP <column_name>;Modify datatype orsizeALTER TABLE <table name>MODIFY <column_name><datatype> [<constraint>];COLUMNCONSTRAINTSConstraintsAdd constraint Drop constraintNot null ALTER TABLE <table name>MODIFY <column_name>CONSTRAINT <constraint_name>NOT NULL;;ALTER TABLE <table name> MODIFY<column_name> NULL;Unique ALTER TABLE <table name>ADD CONSTRAINT <constraint_name>UNIQUE (<column_name>);ALTER TABLE <table name>DROPCONSTRAINT<constraint_name>;Check ALTER TABLE <table name>ADD CONSTRAINT <constraint_name>CHECK (<column_name><condition>);ALTER TABLE <table name>DROP CONSTRAINT<constraint_name>;PrimarykeyALTER TABLE <table name>ADD CONSTRAINT <constraint_name>PRIMARY KEY (<column_name>);ALTER TABLE <table name>DROPCONSTRAINT<constraint_name>;Default ALTER TABLE<table name>MODIFY <column_name> DEFAULT <value>;ALTER TABLE <table name>MODIFY <column_name> DEFAULTNULL;Foreign key ALTER TABLE <table name>ADD CONSTRAINT <constraint_name>FOREIGN KEY (<column_name>)ALTER TABLE <table name>DROPCONSTRAINT<constraint_name>;
  2. 2. DML (Data Manipulation language)INSERTInsert into all columns INSERT INTO <table_name>VALUES(<column1_value>,< column2_value>,……);Insert into specific columns INSERTINTO<table_name> (<column1>, <column2>,…)VALUES(<column1_value>, <column2_value>,……);SELECTSelect all data (all rows all columns – fulltable)SELECT *FROM<table_name>;Select specific columns SELECT<column1, column2,….>FROM <table_name>;Select all data based on condition SELECT *FROM<table_name> WHERE <condition>;Select data in ascending/descendingorderSELECT *FROM<table_name>ORDER BY <column1><ascending/descending>;UPDATEUpdate values which satisfy condition UPDATE<table_name>SET<column_name>=<new_value>;Update all values of a specific column(samevalues for a particular column)UPDATE<table_name>SET<column_name>=<new_value>WHERE<condition>;DELETEDelete specific rows based on condition DELETEFROM <table_name>WHERE <condition>;Clear all data of a table(delete all rows) DELETEFROM <table_name>;Identifiers-An Identifier is essentially a name of a database_name, table_name, column_name or constraint_name.Rules-1. First letter must be alphabet (a-z, A-Z).2. Second and other letters can be numbers (0-9), alphabet (a-z, A-Z) and _ (underscore).3. Must not be a keyword.REFERENCES <table name1>(<column_name>);

×