of 23 /23
Datu bāzes sistēma 1 Datu bāzes sistēma = Datu bāze + Datu bāzes vadības instance Datu bāze Dati Metadati (datu bāzes vārdnīca ) Glabājamās (stored) procedūras un funkcijas Datu bāzes vadības instance jeb eksemplārs Datu bāzes draiveris jeb dzinis Datu bāzes interfeis Lietojums SQL PL/SQL

datubaze.files.wordpress.com€¦  · Web view03/01/2020  · Datu bāzes sistēma = Datu bāze + Datu bāzes vadības instance. Datu bāzes sistēma. Datu bāzes vadības instance

  • Author
    others

  • View
    1

  • Download
    0

Embed Size (px)

Text of datubaze.files.wordpress.com€¦  · Web view03/01/2020  · Datu bāzes sistēma = Datu bāze +...

13

Datu bāzes sistēma = Datu bāze + Datu bāzes vadības instance

(Datu bāzes sistēma)

(Datu bāzes vadības instance jeb eksemplārs)

(Datu bāze)

(Datu bāzes interfeiss) (Datu bāzes draiveris jeb dzinis)

( 2) ( 1) (Glabājamās (stored) procedūras un funkcijas) (Metadati (datu bāzes vārdnīca)) (Dati)

(Lietojums)

(SQL)

(PL/SQL)

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.

Datu bāzes valoda

(Lietojums jeb lietojuma programma) (Savienojums) (Datu bāzes sistēma)

(Datu bāzes valoda) (Datu bāzes vadības instance) (Datu bāze (DB))

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).

Biežāk lietotās vaicājumu valodas

1. .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.

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ēm[footnoteRef:2]. Tās pamatidejas vēlāk tika izmantotas vaicājumu valodā QUEL. [2: Codd, E.F., "Data Base Sublanguage Founded on the Relational Calculus", Proc. 1971 ACM-SIGFIDET Workshop on Data Description, Access, and Control, San Diego.]

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 SQL[footnoteRef:3], jo SEQUEL bija Hawker Siddeley avio kompānijas firmas zīme. [3: 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.]

SQL matemātisko pamatu veido relāciju algebra un kortežu relāciju rēķini (izstrādāja E. F. Kods[footnoteRef:4]). 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. [4: 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.]

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.

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ē.

Datu bāzes valodas SQL (Structured Query Language) izmantošana(1973. g. SEQUEL, IBM) (Datu bāzes interfeiss (JDBC, ADO, OLE DB, ODBC)) (Lietojums, lietojumprogramma, aplikācija(Java, C, Python,SQL)) (Datu bāzes sistēma) (Datu bāze)

(Dati un metadati) (Glabājamās procedūras (stored procedures) (PL/SQL, Java, SQL))

(CREATE TABLE ...INSERT INTO ...UPDATE ...SELECT ... FROM ...)

(Datu bāzes vadības instance)

(ALTER SESSION ...ALTER SYSTEM ...CREATE USER ...GRANT ...) (Datu bāzes administratora grupa)

SQL pamatkomandas jeb priekšraksti

CREATE TABLE [.] (

[[,]] [DEFAULT

] [,...],...

[,...] [] )

INSERT INTO [(,...)]{ {VALUES ( | | NULL | DEFAULT,...)} | {} }

UPDATE SET { = | | () | NULL | DEFAULT,...}[WHERE ]

SELECT [DISTINCT] [.] | * | [AS ],...FROM | [[AS] ] [WHERE ][GROUP BY [.],... [HAVING ]][ORDER_BY | [ASC | DESC],...];

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=15

and 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=12

and 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=2

and 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

where  a.id=b.loancase_id

and 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)=0

and e.country='LV'

and cc.application_product_id=b.id and nvl(cc.deleted,0)=0

and a.DECISION_DATE >=  '17-Apr-2006' and a.DECISION_DATE <=  '23-Apr-2006'

order by f.committee_level, f.name, a.case_name

SQL valodas priekšrakstu izpilde

(SQL komanda, priekšraksts jeb vaicājums (statement)SELECT ... FROM ... WHERE;)

(Sintakses pārbaude (pareizrakstība))

(DB vārdnīca (metadati)) (Semantikas pārbaude (vai ir DB attiecīgie objekti ).)

(Vaicājuma pieraksta transformēšana.)

(Izpildes plānu ģenerators)

(Plānu novērtētājs (plāns + vērtējums))

(Iteratīva izpildes plāna ģenerēšana (row source generator))

(Plāna izpilde Rezultāts)

SQLDeveloper redaktora darba vide

SQL komandu ievade

Izpilde

Rezultāts

EXPLAIN PLAN izmantošana vaicājuma izpildes plāna iegūšanai

Datu bāzes vadības sistēmas tipiskās komponentes

(Vaicājumi (SQL)) (DB shēmas elementu definējumi) (Lietojumprogrammas (lietojumi))

DB vadības instance

(Datu definēšanas valodas kompilators) (Vaicājumu procesors) (Datu manipulāciju valodas pre-procesors)

(DB pārraugs) (Programmu objektu kods) (Datu vārdnīcas pārraugs)

(Failu pārraugs) (Pieejas metodes)

(Datu bāze un sistēmas katalogs) (Sistēmas buferi)

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 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.

Firmas Oracle datu bāzes servera kopējā arhitektūra

(Datu bāzes sistēmas arhitektūraDatu bāzes valoda SQLDatu bāzes sistēmas iekšējā programmēšanas valodaPL/SQL)