Presentation is loading. Please wait.

Presentation is loading. Please wait.

NTAUG Introduction in to use of SQL Peter Dominey Copyright © Peter Dominey 2004, Copyright © Peter Dominey 2004,

Similar presentations


Presentation on theme: "NTAUG Introduction in to use of SQL Peter Dominey Copyright © Peter Dominey 2004, Copyright © Peter Dominey 2004,"— Presentation transcript:

1 NTAUG Introduction in to use of SQL Peter Dominey Copyright © Peter Dominey 2004, Copyright © Peter Dominey 2004,

2 SQL Some History Some History

3 SQL Grew out of IBMs System/R project in 1974 Grew out of IBMs System/R project in 1974

4 SQL Some History Some History Grew out of IBMs System/R project in 1974 Grew out of IBMs System/R project in 1974 Originally Structured English Query Language which is why we pronounce it sequel. Originally Structured English Query Language which is why we pronounce it sequel.

5 SQL Some History Some History Grew out of IBMs System/R project in 1974 Grew out of IBMs System/R project in 1974 Originally Structured English Query Language which is why we pronounce it sequel. Originally Structured English Query Language which is why we pronounce it sequel. Oracle, in 1979 had SQL as its query language Oracle, in 1979 had SQL as its query language

6 SQL Some History Some History Grew out of IBMs System/R project in 1974 Grew out of IBMs System/R project in 1974 Originally Structured English Query Language which is why we pronounce it sequel. Originally Structured English Query Language which is why we pronounce it sequel. Oracle, in 1979 had SQL as its query language Oracle, in 1979 had SQL as its query language After DB2 arrived and SQL became accepted, ANSI/ISO standards developed After DB2 arrived and SQL became accepted, ANSI/ISO standards developed

7 SQL Used in

8 Oracle Oracle SyBase SyBase DB2 DB2 SQLServer SQLServer MySQL MySQL Others Others

9 SQL Overview SQL is the standard database language for most commercial relational databases. It's wide acceptance stems from its ability to manage all of the necessary database manipulations while remaining relatively easy to learn. SQL is the standard database language for most commercial relational databases. It's wide acceptance stems from its ability to manage all of the necessary database manipulations while remaining relatively easy to learn.

10 SQL Overview SQL is the standard database language for most commercial relational databases. It's wide acceptance stems from its ability to manage all of the necessary database manipulations while remaining relatively easy to learn. SQL is the standard database language for most commercial relational databases. It's wide acceptance stems from its ability to manage all of the necessary database manipulations while remaining relatively easy to learn. English-like command structure makes it readable, while providing for the most complex of database functionality. English-like command structure makes it readable, while providing for the most complex of database functionality.

11 SQL Overview SQL is the standard database language for most commercial relational databases. It's wide acceptance stems from its ability to manage all of the necessary database manipulations while remaining relatively easy to learn. SQL is the standard database language for most commercial relational databases. It's wide acceptance stems from its ability to manage all of the necessary database manipulations while remaining relatively easy to learn. English-like command structure makes it readable, while providing for the most complex of database functionality. English-like command structure makes it readable, while providing for the most complex of database functionality. 40+ SQL statements follow the same basic structure, structural consistency keeps it easy to read and learn 40+ SQL statements follow the same basic structure, structural consistency keeps it easy to read and learn

12 SQL Structure All statements start with All statements start with

13 SQL Structure All statements start with All statements start with A verb, A verb,

14 SQL Structure All statements start with All statements start with A verb, A verb, select select

15 SQL Structure All statements start with All statements start with A verb, A verb, Select Select Insert Insert Delete Delete Update Update

16 SQL Structure All statements start with All statements start with A verb, A verb, Select Select Insert Insert Delete Delete Update Update A list of tables and/or fields follow the verb A list of tables and/or fields follow the verb Followed by a clause or clauses Followed by a clause or clauses

17 SQL Structure Consider the following: Consider the following: SELECT job_name,machine FROM job WHERE machine=somename SELECT job_name,machine FROM job WHERE machine=somename

18 SQL Structure The verb defines this as a SELECT statement, which retrieves rows from a table. We are selecting two columns, job_name and machine from the table, job. The verb defines this as a SELECT statement, which retrieves rows from a table. We are selecting two columns, job_name and machine from the table, job. Two clauses follow the SELECT statement with the keywords FROM and WHERE. The FROM clause selects the two columns from a table named job", while the WHERE clause includes the expression that we only want data from rows where the machine is somename. This query's result would be a list of jobs for the machine somename. Two clauses follow the SELECT statement with the keywords FROM and WHERE. The FROM clause selects the two columns from a table named job", while the WHERE clause includes the expression that we only want data from rows where the machine is somename. This query's result would be a list of jobs for the machine somename.

19 SQL Structure Another example: Another example: SELECT job_name FROM job WHERE machine=somename AND owner=root SELECT job_name FROM job WHERE machine=somename AND owner=root

20 SQL Structure We have here created a query that no only selects the jobs that are run on a particular machine (somename) but refined it to select only those that are run on that machine AND owned by the user root We have here created a query that no only selects the jobs that are run on a particular machine (somename) but refined it to select only those that are run on that machine AND owned by the user root

21 SQL Structure A further example: A further example: SELECT job_name FROM job WHERE machine=somename AND owner=fred AND command='/sybasedv/dbaroot/bin/do_dbcc.k sh -Dmaster -SAUTOSYS_SQL_DEV1' SELECT job_name FROM job WHERE machine=somename AND owner=fred AND command='/sybasedv/dbaroot/bin/do_dbcc.k sh -Dmaster -SAUTOSYS_SQL_DEV1'

22 SQL Structure This highlights two important points This highlights two important points

23 SQL Structure This highlights two important points This highlights two important points The any number of clauses can be appended to refine the statement The any number of clauses can be appended to refine the statement

24 SQL Structure This highlights two important points This highlights two important points The any number of clauses can be appended to refine the statement and The any number of clauses can be appended to refine the statement and The text can be included as fully as you wish, so long as it is enclosed in quotes The text can be included as fully as you wish, so long as it is enclosed in quotes

25 SQL Structure This highlights two important points This highlights two important points The any number of clauses can be appended to refine the statement and The any number of clauses can be appended to refine the statement and The text can be included as fully as you wish, so long as it is enclosed in quits The text can be included as fully as you wish, so long as it is enclosed in quits Please note – ignore MSs stupid quote marks, they are just single quotes Please note – ignore MSs stupid quote marks, they are just single quotes

26 SQL clauses The extend and power of SQL lays in the clauses you can construct. The extend and power of SQL lays in the clauses you can construct.

27 SQL clauses The extend and power of SQL lays in the clauses you can construct. The extend and power of SQL lays in the clauses you can construct. Take the earlier statement: Take the earlier statement: SELECT job_name FROM job WHERE machine=somename AND owner=fred AND command='/sybasedv/dbaroot/bin/do_dbcc.ksh - Dmaster -SAUTOSYS_SQL_DEV1' SELECT job_name FROM job WHERE machine=somename AND owner=fred AND command='/sybasedv/dbaroot/bin/do_dbcc.ksh - Dmaster -SAUTOSYS_SQL_DEV1'

28 SQL LIKE clause The extend and power of SQL lays in the clauses you can construct. The extend and power of SQL lays in the clauses you can construct. To make it find jobs that have similar commands we could have a state: To make it find jobs that have similar commands we could have a state: SELECT job_name FROM job WHERE machine=somename AND owner=fred AND command LIKE %dbcc% SELECT job_name FROM job WHERE machine=somename AND owner=fred AND command LIKE %dbcc% Here we are finding anything that has the string dbcc in it from the column command Here we are finding anything that has the string dbcc in it from the column command % is used as a wild card. % is used as a wild card.

29 SQL DISTINCT clause The extend and power of SQL lays in the clauses you can construct. The extend and power of SQL lays in the clauses you can construct. To find all the machines that have jobs defined, but only list each unique machines name: To find all the machines that have jobs defined, but only list each unique machines name: SELECT DISTINCT machine FROM job SELECT DISTINCT machine FROM job

30 SQL DISTINCT clause The extend and power of SQL lays in the clauses you can construct. The extend and power of SQL lays in the clauses you can construct. To find all the machines that have jobs defined, but only list each unique machines name: To find all the machines that have jobs defined, but only list each unique machines name: SELECT DISTINCT machine FROM job SELECT DISTINCT machine FROM job And then order it in a simple alphabetical order And then order it in a simple alphabetical order SELECT DISTINCT machine FROM job ORDER BY machine SELECT DISTINCT machine FROM job ORDER BY machine

31 SQL WHERE clause We touched earlier on the where clause We touched earlier on the where clause

32 SQL WHERE clause We touched earlier on the where clause We touched earlier on the where clause SELECT job_name FROM job WHERE machine=somename SELECT job_name FROM job WHERE machine=somename And made the use of the simplest form, equals =

33 SQL WHERE clause We touched earlier on the where clause We touched earlier on the where clause SELECT job_name FROM job WHERE machine=somename SELECT job_name FROM job WHERE machine=somename And made the use of the simplest form and equals = There are other operators:

34 SQL WHERE clause We touched earlier on the where clause We touched earlier on the where clause SELECT job_name FROM job WHERE machine=somename SELECT job_name FROM job WHERE machine=somename And made the use of the simplest form and equals = There are other operators: =Equal <>Not equal >Greater than <Less than >=Greater than or equal <=Less than or equal BETWEEN Between an inclusive range LIKESearch for a pattern

35 SQL WHERE clause To extract information where you have a list of items: To extract information where you have a list of items: SELECT job_name FROM job WHERE machine IN (machine1,machinezxt,machine1b) SELECT job_name FROM job WHERE machine IN (machine1,machinezxt,machine1b)

36 SQL Select within Select SELECT job_name FROM job WHERE machine IN (SELECT hostname FROM keymaster) SELECT job_name FROM job WHERE machine IN (SELECT hostname FROM keymaster)

37 SQL Information from multiple tables Examine the following statement: Examine the following statement: SELECT keymaster.hostid, job.job_name FROM keymaster, job WHERE job.machine=keymaster.hostname SELECT keymaster.hostid, job.job_name FROM keymaster, job WHERE job.machine=keymaster.hostname

38 SQL Introduction As stated earlier, this was introduction to SQL and hopefully has provided a taste of the things that can be done to extract information directly from the AutoSys database. As stated earlier, this was introduction to SQL and hopefully has provided a taste of the things that can be done to extract information directly from the AutoSys database.

39 SQL Introduction As stated earlier, this was introduction to SQL and hopefully has provided a taste of the things that can be done to extract information directly from the AutoSys database. As stated earlier, this was introduction to SQL and hopefully has provided a taste of the things that can be done to extract information directly from the AutoSys database. pdominey@dominey.biz pdominey@dominey.biz pdominey@dominey.biz www.dominey.biz www.dominey.biz www.dominey.biz


Download ppt "NTAUG Introduction in to use of SQL Peter Dominey Copyright © Peter Dominey 2004, Copyright © Peter Dominey 2004,"

Similar presentations


Ads by Google