datubaze.files.wordpress.com€¦ · web view03/01/2020 · datu bāzes sistēma = datu bāze +...
TRANSCRIPT
Datu bāzes sistēma
1
Datu bāzes sistēma = Datu bāze + Datu bāzes vadības instance
Datu bāze
DatiMetadati
(datu bāzes vārdnīca)
Glabājamās (stored)
procedūras un funkcijas
Datu bāzes vadības instance jeb eksemplārs
Dat
u bā
zes d
raiv
eris
jeb
dzin
isDatu bāzes interfeiss
Lietojums
2
1
SQLPL/SQL
2
Mācību kursa galvenie zināšanu apgūšanas uzdevumi
1. Datu bāzes sistēmas arhitektūra.
2. Datu bāzes valoda SQL.
3. Datu bāzes servera iekšējā programmēšanas valoda PL/SQL.
3
Datu bāzes valoda
1. Datu definēšanas valoda – datu glabāšanas struktūru
izveidošana.
2. Datu manipulēšanas valoda – datu ievade,
koriģēšana, dzēšana.
3. Datu vaicājumu valoda – datu izgūšana.
4. Datu administrēšanas valoda jeb datu vadības valoda
– lietotāju un to tiesību definēšana.
5. Transakciju vadības valoda (commit, savepoint, rollback, set transaction).
Datu bāzes sistēma
Datu bāze (DB)
Datu bāzes vadības instance
Lietojums jeb lietojuma
programma
Savi
enoj
ums
Datu bāzes valoda
4
Biežāk lietotās vaicājumu valodas1. .QL is a proprietary object-oriented query language for querying relational databases; successor of Datalog;2. Contextual Query Language (CQL) a formal language for representing queries to information retrieval systems such as web indexes or bibliographic catalogues;3. CQLF (CODASYL Query Language, Flat) is a query language for CODASYL-type databases;4. Concept-Oriented Query Language (COQL) is used in the concept-oriented model (COM). It is based on a novel data modeling construct, concept, and uses such operations as projection and de-projection for multi-dimensional analysis, analytical operations and inference;5. D is a query language for truly relational database management systems (TRDBMS);6. DMX is a query language for Data Mining models;7. Datalog is a query language for deductive databases;8. Gellish English is a language that can be used for queries in Gellish English Databases, for dialogues (requests and responses) as well as for information modeling and knowledge modeling; 9. HTSQL is a query language that translates HTTP queries to SQL;10. ISBL is a query language for PRTV, one of the earliest relational database management systems;11. LINQ query-expressions is a way to query various data sources from .NET languages;12. MDX is a query language for OLAP databases;13. OQL is Object Query Language;14. OCL (Object Constraint Language). Despite its name, OCL is also an object query language and an OMG standard;15. OttoQL, intended for querying tables, XML, and databases;16. Poliqarp Query Language is a special query language designed to analyze annotated text. Used in the Poliqarp search engine;17. QUEL is a relational database access language, similar in most ways to SQL;18. RDQL is a RDF query language;19. SMARTS is the cheminformatics standard for a substructure search;20. SPARQL is a query language for RDF graphs;21. SPL is a search language for machine-generated big data, based upon Unix Piping and SQL;22. SQL is a well known query language and Data Manipulation Language for relational databases;23. SuprTool is a proprietary query language for SuprTool, a database access program used for accessing data in Image/SQL (formerly TurboIMAGE) and Oracle databases;24. TMQL Topic Map Query Language is a query language for Topic Maps;25. UnQL (Unstructured Query Language) is a functional superset of SQL, developed by the authors of SQLite and CouchDB;26. XQuery is a query language for XML data sources;27. XPath is a declarative language for navigating XML documents;28. XSPARQL is an integrated query language combining XQuery with SPARQL to query both XML and RDF data sources at once.
5
Datu bāzes valoda SQL (Structured Query Language)
1970. g. IBM firmas zinātniskais līdzstrādnieks doktors E. F. Kodds publicēja rakstu "Relāciju modelis lielām koplietošanas datu bankām"2, kurā tika definēti matemātiskie pamati relāciju datu bāzēm.
Viņa IBM firmas kolēģi Donald D. Chamberlin un Raymond F. Boyce 70. g. sākumā izstrādāja vaicājumu valodu SQUARE (Specifying Queries As Relational Expressions), kura izmantoja kopu teoriju un predikātu teoriju, lai veiktu datu atlasi no relāciju datu bāzes.
1971. g. E. F. Kods arī pats izstrādāja vaicājumu valodu Alpha relāciju datu bāzēm1. Tās pamatidejas vēlāk tika izmantotas vaicājumu valodā QUEL.
1974. gadā D. D. Chamberlin un R. F. Boyce publicēja rakstu “SEQUEL: A Structured English Query Language”, kura detalizēja un bagātināja SQUARE. Vēlāk SEQUEL nosaukums, izmetot patskaņus, tika reducēts uz nosaukumu SQL2, jo SEQUEL bija Hawker Siddeley avio kompānijas firmas zīme. SQL matemātisko pamatu veido relāciju algebra un kortežu relāciju rēķini (izstrādāja E. F. Kods3). SQL valodu izstrādāja izmantošanai relāciju DB, bet vēlāk to izmantoja arī citiem datu bāzes loģiskajiem modeļiem. 70. g. sākumā sākās relāciju datu bāzes vadības sistēmu izstrāde. Lielāko un nozīmīgāko projektu System/R realizēja IBM kompānija Santa Teresa laboratorijā San-Hosē pilsētā Kalifornijas štatā. 1975. gadā tika izveidots sākotnējais relāciju datu bāzes vadības sistēmas (DBVS) prototips. 1978. un 1977. gados otrā System/R realizācija izmantoja arī vaicājumu valoda SEQUEL. Sakarā ar juridiskiem apsvērumiem tika mainīts valodas nosaukums. Tagad tā saucas vaicājumu valoda SQL (Structured Query Language). 1979. gadā projekts System/R tika pabeigts, secinot ka relāciju datu bāžu izmantošana ir komerciāli perspektīva.
1 Codd, E.F., "Data Base Sublanguage Founded on the Relational Calculus", Proc. 1971 ACM-SIGFIDET Workshop on Data Description, Access, and Control, San Diego.2 D. D. Chamberlin, R. F. Boyce, 1974, SEQUEL: A Structured English Query Language. Retrieved on May 16, 2007 fromhttp://www.almaden.ibm.com/cs/people/chamberlin/sequel-1974.pdf.3 Codd, Edgar F (June 1970). "A Relational Model of Data for Large Shared Data Banks". Communications of the ACM (Association for Computing Machinery) 13 (6): 377–87. doi:10.1145/362384.362685. Retrieved 2007-06-09.
6
Ziņojumi par projekta System/R panākumiem saistīja Kalifornijas štata pilsētas Menlou Park inženieru grupas uzmanību un 1977. gadā tika izveidota kompānija Relational Software, Inc. 1979. gadā jau tika uzsāktas grupas izstrādātās relāciju DBVS Oracle piegādes pasūtītājiem. Oracle kļuva par pirmo komerciālo DBVS skaitļošanas tehnikas programmatūru. Tā par diviem gadiem apsteidza IBM pirmās komerciālās DBVS DB-2 parādīšanos programmatūras tirgū. Turpinājumā kompānija Relational Software, Inc. tika pārsaukta par Oracle, Inc. kompāniju un patreiz tā ir vadošā datu bāzes tehnoloģijas izstrādes un ieviešanas organizācija pasaulē.
7
Datu bāzes valodas SQL (Structured Query Language) izmantošana(1973. g. SEQUEL, IBM)
Datu bāzes sistēmaLietojums, lietojumprogramma,
aplikācija(Java, C, Python,
SQL)
Datu bāzes interfeiss
(JDBC, ADO, OLE DB, ODBC)
Datu bāzes vadības instance
Datu bāzeDati un
metadatiGlabājamās procedūras
(stored procedures)
(PL/SQL, Java, SQL)
Datu bāzes administratora
grupa
CREATE TABLE ...INSERT INTO ...UPDATE ...SELECT ... FROM ...
ALTER SESSION ...ALTER SYSTEM ...CREATE USER ...GRANT ...
8
SQL pamatkomandas jeb priekšraksti
CREATE TABLE [<schema>.]<table_name> ( <column_name> <datatype> [<size1>[,<size2>]] [DEFAULT
<default_value>] [<column_constraint>,...],... [<table_constraint>,...] [<physical_properties>] )
INSERT INTO <table_or_view_name>[(<column_name>,...)]{ {VALUES (<literal> | <expression> | NULL | DEFAULT,...)} | {<select_statement>} }
UPDATE <table_or_view_name>SET {<column_name> = <literal> | <expression> | (<single_row_select_statement>) | NULL | DEFAULT,...}[WHERE <predicate>]
SELECT [DISTINCT] [<qualifier>.]<column_name> | * | <expression> [AS <column_alias>],...FROM <table_or_view_name> | [[AS] <table_alias>] [WHERE <predicate>][GROUP BY [<qualifier>.]<column_name>,... [HAVING <predicate>]][ORDER_BY <column_name> | <column_number> [ASC | DESC],...];
9
SQL valodas SELECT vaicājuma piemērs
select f.committee_level "CC Level", f.name "CC Name", (select kk.user_name from gl_loan.ln_cc_member kk where kk.id in (select ii.cc_member_id from gl_loan.ln_cc_session_member ii where ii.cc_session_id =a.cc_session_id and nvl(ii.deleted,0)=0 and ii.role='FIRST') and nvl(kk.deleted,0)=0) "1st decision maker",(select kk.user_name from gl_loan.ln_cc_member kk where kk.id in (select ii.cc_member_id from gl_loan.ln_cc_session_member ii where ii.cc_session_id =a.cc_session_id and nvl(ii.deleted,0)=0 and ii.role='SECOND') and nvl(kk.deleted,0)=0) "2st decision maker",a.case_name "LC Nr.",a.manager_name "Manager", a.customer_name "Customer name", a.customer_code "Customer code", decode(a.customer_type, 'P','Private', 'C', 'Legal', 'X', 'Non-client(error)' ) "Customer type", e.name "Product", (select mm.name from gl_loan.ln_classificator mm where e.product_line=mm.code and mm.classif_type_id=15and mm.language='ENG'---'LAT' and nvl(mm.inactive,0)=0)"Product line", b.currency "Currency", (select l.decided_value from gl_loan.ln_decision_row l, gl_loan.ln_product_row o where l.product_decision_id = cc.id and o.product_id=b.product_id and o.row_type_id=16 and nvl(o.deleted,0)=0 and l.product_row_id=o.id) "Interest", to_number(b.DECIDED_AMOUNT_LOCAL) "Amount", to_number(a.customer_new_risk )"New risk",(select l.decided_value from gl_loan.ln_decision_row l, gl_loan.ln_product_row o where l.product_decision_id = cc.id and o.product_id=b.product_id and o.row_type_id=24 and nvl(o.deleted,0)=0 and l.product_row_id=o.id) "Maturity",(select mm.name from gl_loan.ln_classificator mm where cc.decision=mm.code and mm.classif_type_id=22 and mm.language='ENG' and nvl(mm.inactive,0)=0) "Product decision",(select mm.name from gl_loan.ln_classificator mm where a.final_decision=mm.code and mm.classif_type_id=22 and mm.language='ENG' and nvl(mm.inactive,0)=0) "LC decision",a.DECISION_DATE "Decision Date",(select mm.name from gl_loan.ln_classificator mm where a.current_status_code=mm.code and mm.classif_type_id=12and mm.language='ENG'and nvl(mm.inactive,0)=0) "LC status",(select mm.name from gl_loan.ln_classificator mm where a.finishing_event_code=mm.code and mm.classif_type_id=2and mm.language='ENG'and nvl(mm.inactive,0)=0) "Finishing event",a.created_by "Creator",(select zz.nimi from salesman.mp_kontor zz where zz.country_id='LV'and zz.business_unit_code in (select pp.business_unit_code from salesman.mp_haldur pp where pp.uname not in ('ANITAB','ANITA','ANITBERZ') and pp.missing='E' and pp.lkpv is null and pp.country_id='LV' and pp.nimi=upper (a.created_by))) "Creator branch",replace(cc.collateral,chr(13)||chr(10),' ') "Collateral", replace(cc.comments,chr(13)||chr(10),' ') "Comments",DECODE(B.APPLICATION_TYPE,'N', 'New', 'C', 'Change', 'E' , 'Extend') "Appliation type"from gl_loan.ln_loan_case a, gl_loan.ln_application_product b, gl_loan.ln_product e, gl_loan.ln_committee f, gl_loan.ln_cc_product_decision cc
10
where a.id=b.loancase_idand b.product_id=e.id and a.committee_id=f.id and nvl(e.deleted,0)=0 and nvl(a.deleted,0)=0 and nvl(b.deleted,0)=0and e.country='LV' and cc.application_product_id=b.id and nvl(cc.deleted,0)=0and a.DECISION_DATE >= '17-Apr-2006' and a.DECISION_DATE <= '23-Apr-2006' order by f.committee_level, f.name, a.case_name
11
SQL valodas priekšrakstu izpilde
SQL komanda, priekšraksts jeb vaicājums (statement)
SELECT ... FROM ... WHERE;
Sintakses pārbaude (pareizrakstība)
Semantikas pārbaude (vai ir DB attiecīgie objekti ).
Vaicājuma pieraksta transformēšana.
Plānu novērtētājs (plāns + vērtējums)
Plāna izpilde Rezultāts
Iteratīva izpildes plāna ģenerēšana (row source generator)
DB vārdnīca (metadati)
Izpildes plānu ģenerators
12
SQLDeveloper redaktora darba videSQL komandu ievade
Izpilde
Rezultāts
13
EXPLAIN PLAN izmantošana vaicājuma izpildes plāna iegūšanai
14
Datu bāzes vadības sistēmas tipiskās komponentes
DB vadības instance
Lietojumprogrammas (lietojumi)
Vaicājumi (SQL) DB shēmas elementu definējumi
Datu manipulāciju valodas pre-
procesors
Vaicājumu procesors
Datu definēšanas valodas kompilators
Programmu objektu kods
DB pārraugs Datu vārdnīcas pārraugs
Failu pārraugsPieejas metodes
Sistēmas buferi
Datu bāze un sistēmas katalogs
15
Architecture of a DBMS
The DBMS accepts SQL commands generated from a variety of user interfaces, produces query evaluation plans, executes these plans against the database, and returns the answers. (This is a simplification: SQL commands can be embedded in host language application programs, e.g., Java or COBOL programs. We ignore these issues to concentrate on the core DBMS functionality.)When a user issues a query, the parsed query is presented to aquery optimizer, which uses information about how the data is stored to produce an efficient execution plan for evaluating the query. An execution plan is a blueprint for evaluating a query, and is usually represented as a tree of relational operators (with annotations that contain additional detailed information about which access methods to use, etc.). Relational operators serve as the building blocks for evaluating queries posed against the data. The code that implements relational operators sits on top of the file and access methods layer. This layer includes a variety of software for supporting the concept of a file, which, in a DBMS, is a collection of pages or a collection of records. This layer typically supports a heap file, or file of unordered pages, as well as indexes. In addition to keeping track of the pages in a file, this layer organizes the information
16
within a page. The files and access methods layer code sits on top of the buffer manager, which brings pages in from disk to main memory as needed in response to read requests. The lowest layer of the DBMS software deals with management of space on disk, where the data is stored. Higher layers allocate, deallocate, read, and write pages through (routines provided by) this layer, called the disk space manager. The DBMS supports concurrency and crash recovery by carefully scheduling user requests and maintaining a log of all changes to the database. DBMS components associated with concurrency control and recovery include the transaction manager, which ensures that transactions request and release locks according to a suitable locking protocol and schedules the execution transactions; the lock manager, which keeps track of requests for locks and grants locks on database objects when they become available; and the recovery manager, which is responsible for maintaining a log, and restoring the system to a consistent state after a crash. The disk space manager, buffer manager, and file and access method layers must interact with these components.
17
Firmas Oracle datu bāzes servera kopējā arhitektūra
Datu bāzes sistēmas arhitektūra
Datu bāzes valoda SQL
Datu bāzes sistēmas iekšējā
programmēšanas valoda
PL/SQL
18