Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Microsoft Access wikipedia , lookup
Relational algebra wikipedia , lookup
Oracle Database wikipedia , lookup
Microsoft Jet Database Engine wikipedia , lookup
Tandem Computers wikipedia , lookup
Clusterpoint wikipedia , lookup
Database model wikipedia , lookup
Relational model wikipedia , lookup
Microsoft SQL Server wikipedia , lookup
NTAUG Introduction in to use of SQL Peter Dominey Copyright © Peter Dominey 2004, <[email protected]> SQL Some History SQL Some History Grew out of IBM’s System/R project in 1974 SQL Some History Grew out of IBM’s System/R project in 1974 Originally “Structured English Query Language” which is why we pronounce it ‘sequel’. SQL Some History Grew out of IBM’s System/R project in 1974 Originally “Structured English Query Language” which is why we pronounce it ‘sequel’. Oracle, in 1979 had SQL as it’s query language SQL Some History Grew out of IBM’s System/R project in 1974 Originally “Structured English Query Language” which is why we pronounce it ‘sequel’. Oracle, in 1979 had SQL as it’s query language After DB2 arrived and SQL became accepted, ANSI/ISO standards developed SQL Used in SQL Used in Oracle SyBase DB2 SQLServer MySQL Others 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 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. English-like command structure makes it readable, while providing for the most complex of database functionality. 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. 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 SQL Structure All statements start with SQL Structure All statements start with A verb, SQL Structure All statements start with A verb, select SQL Structure All statements start with A verb, Select Insert Delete Update SQL Structure All statements start with A verb, Select Insert Delete Update A list of tables and/or fields follow the verb Followed by a clause or clauses SQL Structure Consider the following: SELECT job_name,machine FROM job WHERE machine=‘somename’ 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. 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’. SQL Structure Another example: SELECT job_name FROM job WHERE machine=‘somename’ AND owner=‘root’ 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’ SQL Structure 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' SQL Structure This highlights two important points SQL Structure This highlights two important points The any number of clauses can be appended to refine the statement SQL Structure This highlights two important points 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 ‘’ SQL Structure This highlights two important points 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 ‘’ Please note – ignore MS’s stupid quote marks, they are just single quotes SQL clauses The extend and power of SQL lays in the clauses you can construct. SQL clauses The extend and power of SQL lays in the clauses you can construct. 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' SQL ‘LIKE’ clause 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: 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’ % is used as a wild card. SQL ‘DISTINCT’ clause 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: SELECT DISTINCT machine FROM job SQL ‘DISTINCT’ clause 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: SELECT DISTINCT machine FROM job And then order it in a simple alphabetical order SELECT DISTINCT machine FROM job ORDER BY machine SQL ‘WHERE’ clause We touched earlier on the where clause SQL ‘WHERE’ clause We touched earlier on the where clause SELECT job_name FROM job WHERE machine=‘somename’ And made the use of the simplest form, equals ‘=‘ SQL ‘WHERE’ clause We touched earlier on the where clause SELECT job_name FROM job WHERE machine=‘somename’ And made the use of the simplest form and equals ‘=‘ There are other operators: SQL ‘WHERE’ clause We touched earlier on the where clause SELECT job_name FROM job WHERE machine=‘somename’ And made the use of the simplest form and equals ‘=‘ There are other operators: = <> > < >= <= BETWEEN LIKE Equal Not equal Greater than Less than Greater than or equal Less than or equal Between an inclusive range Search for a pattern SQL ‘WHERE’ clause To extract information where you have a list of items: SELECT job_name FROM job WHERE machine IN (‘machine1’,’machinezxt’,’machine1b’) SQL Select within Select SELECT job_name FROM job WHERE machine IN (SELECT hostname FROM keymaster) SQL Information from multiple tables Examine the following statement: SELECT keymaster.hostid, job.job_name FROM keymaster, job WHERE job.machine=keymaster.hostname 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. 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. [email protected] www.dominey.biz