sql/server stephen cunningham thema davis. problem domain designed for retrieval and management of...
Post on 22-Dec-2015
213 views
TRANSCRIPT
Problem DomainProblem Domain
Designed for retrieval and management Designed for retrieval and management of dataof data
Defines the structures and operations Defines the structures and operations of a data model of the databaseof a data model of the database
Also used for data manipulation, data Also used for data manipulation, data access, security and many other thingsaccess, security and many other things
Historical ContextHistorical Context
First version developed IBM by Donald First version developed IBM by Donald D. Chamberlin and Raymod F. Boyce in D. Chamberlin and Raymod F. Boyce in the early 1970’sthe early 1970’sIt was called SEQUELIt was called SEQUELStandardized in 1986 by the American Standardized in 1986 by the American National Standards Institute (ANSI)National Standards Institute (ANSI)Also by the International Organization Also by the International Organization of Standardization (ISO)of Standardization (ISO)
Evolution of the LanguageEvolution of the Language
Expansions and revisions – 1989 & 1992Expansions and revisions – 1989 & 19921999 - Regular expression matching, 1999 - Regular expression matching, recursive queries, triggers, support for recursive queries, triggers, support for procedural and control-of-flow statements, procedural and control-of-flow statements, and some object-oriented features.and some object-oriented features.2003 - Introduced XML-related features, 2003 - Introduced XML-related features, window functionswindow functions, standardized sequences, , standardized sequences, and columns with auto-generated values and columns with auto-generated values (including identity-columns).(including identity-columns).
Language ConceptsLanguage Concepts
Stored ProceduresStored ProceduresSelecting a QuerySelecting a QueryInsertInsertDeleteDeleteUpdateUpdate
Stored ProceduresStored Procedures
Reference: http://99-bottles-of-beer.net/language-sql-609.html
/* available online in file 'sample6' */#include <stdio.h>#include <string.h>
typedef char asciz;
EXEC SQL BEGIN DECLARE SECTION; /* Define type for null-terminated strings. */ EXEC SQL TYPE asciz IS STRING(20); asciz username[20]; asciz password[20]; int dept_no; /* which department to query */ char emp_name[10][21]; char job[10][21]; EXEC SQL VAR emp_name is STRING (21); EXEC SQL VAR job is STRING (21); float salary[10]; int done_flag; int array_size; int num_ret; /* number of rows returned */ int SQLCODE;EXEC SQL END DECLARE SECTION;
EXEC SQL INCLUDE sqlca;
Selecting A QuerySelecting A Query
SELECT *
FROM books
WHERE price > 100.00
ORDER BY title;
A select query that returns a list of expensive
books.
InsertInsert
INSERT INTO my_table (field1, field2, field3) VALUES ('test', 'N',
NULL);
Insert is used to add rows (formally tuples) to an existed table
DeleteDelete
DELETE FROM my_table WHERE field2 = 'N';
Delete removes zero or more existing rows from a table
UpdateUpdate
UPDATE T1 SET C1 = 2 WHERE C2 in ( SELECT C3 FROM T2 WHERE C4 = 0)
Set the value of column C1 in table T1 to 2, only if the value of column C2 is found in the
sub list of values in column C3 in table T2 having the column C4 equal to 0.
Comparison to JavaComparison to Java
Java has classpaths, working Java has classpaths, working directories, environment variables and directories, environment variables and command-line parameterscommand-line parameters
Slower and less flexible Slower and less flexible
Comparison to PL/SQLComparison to PL/SQL
PL/SQL supports variables, conditions, PL/SQL supports variables, conditions, arrays and exceptionsarrays and exceptions
Makes it easy to use loopsMakes it easy to use loops
Has features for object oriented Has features for object oriented programmingprogramming
SourcesSources
http://www.paladn.com/sql-server-http://www.paladn.com/sql-server-programming-environment.htm programming-environment.htm
http://www.jcc.com/sql.htm http://www.jcc.com/sql.htm
http://en.wikipedia.org/wiki/http://en.wikipedia.org/wiki/Structured_Query_LanguageStructured_Query_Language