Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.

Similar presentations


Presentation on theme: "1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV."— Presentation transcript:

1 1 Structured Query Language (SQL)

2 2 Contents SQL – I SQL – II SQL – III SQL – IV

3 3 SQL- I Table Fundamentals –Oracle Data Types Basic Data Types –The CREATE TABLE Command Rules for Creating Tables A brief checklist when creating tables –Inserting data into tables Viewing data in the tables –All rows and all columns –Filtering table data Selected columns and all rows Selected rows and all columns Selected columns and selected rows Eliminating duplicate rows when using SELECT statement Sorting data in a table Creating a table from a table Inserting data into a table from another table –Insertion of a data set into a table from another table

4 4 Delete Operations –Removal all rows –Removal of specific row (s) –Removal of specific row (s) based on the data held by the other table Updating the contents of a table –Updating all rows –Updating records conditionally Modifying the structure of tables –Adding new columns –Dropping a column from a table –Modifying existing columns –Restrictions on the ALTER TABLE Renaming tables Truncating tables Destroying tables Examining objects created by a user

5 5 Table Fundamentals: A table is database object that holds user data –Oracle Data Types Basic Data Types char (size) – fixed length string. varchar (size)/varchar2 (size) – variable length string date - number (p, s) – precision, scale, eg. number (7, 2) 5 digit before decimal and 2 after. long – variable length string raw/ long raw – variable length binary string –The CREATE TABLE Command Rules for Creating Tables a name can have maximum up to 30 characters. alphabets from A-Z, a-Z and numbers from 0-9 are allowed. a name should begin with an alphabets. the use of special character like _ is allowed SQL reserved words not allowed A brief checklist when creating tables attributes, data types, primary key, default values CREATE TABLE ( ( ), ( ));

6 6 –Inserting data into tables Viewing data in the tables SELECT –All rows and all columns SELECT * FROM ; –Filtering table data Selected columns and all rows SELECT, FROM ; Selected rows and all columns SELECT * FROM WHERE ; Selected columns and selected rows SELECT, FROM WHERE ; INSERT INTO (, ) VALUES (, );

7 7 Eliminating duplicate rows when using SELECT statement DISTINCT SELECT DISTINCT * FROM ; Sorting data in a table SELECT * FROM ORDER BY, ; Sort Order: DESC Creating a table from a table CREATE TABLE (, ) AS SELECT, FROM ; eg. Create table to retrieve the table structure. WHERE Inserting data into a table from another table INSERT INTO SELECT, FROM ; –Insertion of a data set into a table from another table INSERT INTO SELECT, FROM WHERE ;

8 8 Delete Operations DELETE –Removal all rows DELETE FROM ; –Removal of specific row (s) DELETE FROM WHERE ; –Removal of specific row (s) based on the data held by the other table EXISTS DELETE FROM table1 WHERE Exists (SELECT fname FROM tabel2 WHERE table2.cust_no = table1. code_no AND table2.fname = “abc”); Updating the contents of a table UPDATE –Updating all rows UPDATE SET =, = ; –Updating records conditionally UPDATE SET =, = WHERE ;

9 9 Modifying the structure of tables ALTER TABLE –Adding new columns ALTER TABLE ADD ( ( ), ( ),..); –Dropping a column from a table ALTER TABLE DROP COLUMN ; –Modifying existing columns ALTER TABLE MODIFY ( ( )); –Restrictions on the ALTER TABLE Change the name of the table Change the name of the column Decrease the size of a column if table data exists9 Renaming tables RENAME TO ; Truncating tables: empties a table completely. TRUNCATE TABLE ; Destroying tables DROP TABLE ;

10 10 Examining objects created by a user – SELECT * FROM TAB; – DESCRIBE ;


Download ppt "1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV."

Similar presentations


Ads by Google