Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction To SQL Lynnwood Brown President System Managers LLC Copyright System Managers LLC 2003 all rights reserved.

Similar presentations


Presentation on theme: "Introduction To SQL Lynnwood Brown President System Managers LLC Copyright System Managers LLC 2003 all rights reserved."— Presentation transcript:

1 Introduction To SQL Lynnwood Brown President System Managers LLC Copyright System Managers LLC 2003 all rights reserved.

2 Structured Query Language The Structured Query Language is used to communicate with all relational databases. Oracle, DB2, Informix, SQL Server, MS Access are some of the more popular databases. Oracle - 30% market share DB2 - 30% market share SQL Server - 15% market share Copyright System Managers LLC 2003 all rights reserved.

3 Getting Information A database consist of various types of objects. One type of database object is called a table. Tables store end user information in records. Copyright System Managers LLC 2003 all rights reserved.

4 Getting Information End users must be able to insert new data into a table. End users must be able to update the information in a table. End users must be able to remove information from a table. End users must be able to look up information that is stored in a table. Copyright System Managers LLC 2003 all rights reserved.

5 Getting Information To get information from a table the table is queried. To get information from a table the SQL command “SELECT” is used to query the table. Copyright System Managers LLC 2003 all rights reserved.

6 Getting Information To find the name, locations and department numbers from the table called “DEPT” a “SELECT” statement is issued. Select deptno,dname,loc from dept; Copyright System Managers LLC 2003 all rights reserved.

7 Getting Information SQL supports the use of functions to aggregate data. Partial list of SQL functions: MIN - Find the minimum value in a column MAX - Find the maximum value in a column AVG - Calculate the average value for a column SQRT - Calculate the square root for the column data STDDEV - Calculate the standard deviation for a column. TO_CHAR - Convert data to character format Copyright System Managers LLC 2003 all rights reserved.

8 Getting information SQL supports a conditional search using the “WHERE” clause. Select * from dept where deptno = 10; Select * from dept where loc = ‘DALLAS’; Copyright System Managers LLC 2003 all rights reserved.

9 Getting Information Data may be stored in various tables. Data form multiple tables can be queried using a table join. Tables are joined on like columns. Select a.ename,b.loc from emp a, dept b where a.deptno=b.deptno; Select a.ename, b.loc from emp a, dept b where a.deptno > b.deptno; Copyright System Managers LLC 2003 all rights reserved.

10 Getting Information We can use one query as a input for another query. This is called a subquery. Select * from emp where deptno = select deptno from dept where loc = ‘DALLAS’; Select * from emp where deptno in (select deptno from dept); Select * from emp where deptno in (select deptno from dept where loc in (‘DALLAS’,’BOSTON’); Copyright System Managers LLC 2003 all rights reserved.

11 Creating A Table The SQL command “CREATE TABLE” is used create a table. CREATE TABLE EMP (EMPNO NUMBER(4) NOT NULL, ENAME VARCHAR2(10), JOB VARCHAR2(9), MGR NUMBER(4), HIREDATE DATE, SAL NUMBER(7,2), COMM NUMBER(7,2), DEPTNO NUMBER(2)); Copyright System Managers LLC 2003 all rights reserved.

12 Modifying A Table Columns can be added to an existing table using the SQL command “ALTER TABLE”. Alter table emp add loc varchar2(20); Columns can be enlarged using the “ALTER TABLE” command. Alter table emp modify loc varchar2(40); Columns can be removed from a table Alter table emp drop loc; Copyright System Managers LLC 2003 all rights reserved.

13 Adding New Information The SQL command “INSERT” is used to add new records to a table. INSERT INTO EMP VALUES (7369,'SMITH','CLERK',7902,'1 7-DEC-80',800,NULL,20); Copyright System Managers LLC 2003 all rights reserved.

14 Updating Information The SQL command “UPDATE” is used to modify data that exist in a table record. update emp set deptno = 5; update emp set deptno = 5 where ename = ‘SMITH’; Copyright System Managers LLC 2003 all rights reserved.

15 Removing Information The SQL command “DELETE” is used to remove a record(s) from a table. Delete from emp; Truncate table emp; Delete from emp where ename = ‘SMITH’; Copyright System Managers LLC 2003 all rights reserved.

16 Removing A Table The SQL command “DROP TABLE” is used to remove a table from the database. Drop table emp; Tables can also be renamed: rename emp to emp_old; Copyright System Managers LLC 2003 all rights reserved.

17 Summary SQL is the language used to communicate with a relational database SQL provides the commands “SELECT”, “INSERT”, “UPDATE” and “DELETE” to query the database, put new information into the database, update existing data that is in the database and remove data from the database respectively. Copyright System Managers LLC 2003 all rights reserved.

18 Summary (cont.) SQL provides various mathematical functions (MIN, MAX, STDDEV etc…). The command “ALTER TABLE” is used to modify the structure of a table. SQL*PLUS is Oracle’s version of ANSI SQL. Copyright System Managers LLC 2003 all rights reserved.


Download ppt "Introduction To SQL Lynnwood Brown President System Managers LLC Copyright System Managers LLC 2003 all rights reserved."

Similar presentations


Ads by Google