Datubaze.files.wordpress.com



Informācijas sistēmu un datu bāzes sistēmu vaicājumu valodasDatoru vaicājumu valodas (query languages) lieto lai iegūtu (izgūtu) datus un informāciju no:datu bāzēm (datu bāzes vaicājumu valoda (database query languages)) – datu un faktu iegū?ana;informācijas sistēmām (informācijas izguves vaicājumu valodas (information retrieval query languages)) - dokumentu ar vajadzīgo informāciju iegū?ana.Datu bāzes sistēmaDatu bāzeDatu bāzes vadības sistēmaLietojumsVaicājumu valodaBie?āk lietotās vaicājumu valodas.QL is a proprietary object-oriented query language for querying relational databases; successor of Datalog;Contextual Query Language (CQL) a formal language for representing queries to information retrieval systems such as web indexes or bibliographic catalogues;CQLF (CODASYL Query Language, Flat) is a query language for CODASYL-type databases;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;D is a query language for truly relational database management systems (TRDBMS);DMX is a query language for Data Mining models;Datalog is a query language for deductive databases;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; HTSQL is a query language that translates HTTP queries to SQL;ISBL is a query language for PRTV, one of the earliest relational database management systems;LINQ query-expressions is a way to query various data sources from .NET languages;MDX is a query language for OLAP databases;OQL is Object Query Language;OCL (Object Constraint Language). Despite its name, OCL is also an object query language and an OMG standard;OttoQL, intended for querying tables, XML, and databases;Poliqarp Query Language is a special query language designed to analyze annotated text. Used in the Poliqarp search engine;QUEL is a relational database access language, similar in most ways to SQL;RDQL is a RDF query language;SMARTS is the cheminformatics standard for a substructure search;SPARQL is a query language for RDF graphs;SPL is a search language for machine-generated big data, based upon Unix Piping and SQL;SQL is a well known query language and Data Manipulation Language for relational databases;SuprTool is a proprietary query language for SuprTool, a database access program used for accessing data in Image/SQL (formerly TurboIMAGE) and Oracle databases;TMQL Topic Map Query Language is a query language for Topic Maps;UnQL (Unstructured Query Language) is a functional superset of SQL, developed by the authors of SQLite and CouchDB;XQuery is a query language for XML data sources;XPath is a declarative language for navigating XML documents;XSPARQL is an integrated query language combining XQuery with SPARQL to query both XML and RDF data sources at once.Datu bāzes valodaLietojums jeb lietojuma programmaSavienojumsDatu bāzes sistēmaDatu bāzes valodaDatu bāzes vadības sistēma (DBVS)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).Datu bāzes valoda SQL (Structured Query Language)5648325381001970. 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. 5648325269240-35560062230Vi?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. 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 SQL, 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. Kods). 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. 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ē.Nozīmīgākie gadaskait?i SQL valodas vēsturēDatumsNotikums1970Kodds izveido relāciju datu bāzu modeli1974Kompānija IBM sāk projekta Sustem/R izstrādi1974Pirmais publicētais raksts, kurā tiek aprakstīta SEQUEL valoda1978Projekta System/R ekspluatācija1979Parādās pirmā kompānijas Oracle DBVS realizācija komerciāliem mēr?iem1981Kompānija Relation Technolpgy izveido DBVS Ingres1981IBM izveido DBVS SQL/DS1982ANSI izveido valodas SQL standartu komisiju1983IBM pazi?o par DBVS DB2 izveidi1986ANSI pie?em SQL standartu1986Firma Sybase izveido relāciju DBVS transakciju apstrādei1987ISO pie?em valodas SQL standartu1988Firmas Ashton-Tate un Microsoft pazi?o par DBVS SQL Server izveidi OS/2 vidē1988IBM pazi?o par DBVS BD2 otrās versijas izveido?anu1989Pirmā datu bāzu servera uztādī?ana un SQL pamata operētājsistēmai OS/21989Izveidota SQL Access Group1991SQL Access Group publicē savu specifikāciju1992Firmas Microsoft publicē protokola ODBC specifikāciju1992Pirmā relāciju datu bāzu serveru uzstādī?ana tīkla operētājsistēmai Novell Netware1992ANSI pie?em standartu SQL21993Pirmās programmas ar protokolu ODBC produktu piegādeDatu 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ēmaDatu bāzeDati un metadatiGlabājamās procedūras (stored procedures) (PL/SQL, Java, SQL)CREATE TABLE ...INSERT INTO ...UPDATE ...SELECT ... FROM ...Datu bāzes vadības sistēmaALTER SESSION ...ALTER SYSTEM ...CREATE USER ...GRANT ...Datu bāzes administratora grupaSQL valodas standartiYearNameAliasComments1986SQL-86SQL-87First formalized by ANSI.1989SQL-89FIPS 127-1Minor revision that added integrity constraints, adopted as FIPS 127-1.1992SQL-92SQL2, FIPS 127-2Major revision (ISO 9075), Entry Level SQL-92 adopted as FIPS 127-2.1999SQL:1999SQL3Added regular expression matching, recursive queries (e.g. transitive closure), triggers, support for procedural and control-of-flow statements, non-scalar types (arrays), and some object-oriented features (e.g. structured types). Support for embedding SQL in Java (SQL/OLB) and vice versa (SQL/JRT).2003SQL:2003Introduced XML-related features (SQL/XML), window functions, standardized sequences, and columns with auto-generated values (including identity-columns).2006SQL:2006ISO/IEC 9075-14:2006 defines ways that SQL can be used with XML. It defines ways of importing and storing XML data in an SQL database, manipulating it within the database, and publishing both XML and conventional SQL-data in XML form. In addition, it lets applications integrate queries into their SQL code with XQuery. 2008SQL:2008Legalizes ORDER BY outside cursor definitions. Adds INSTEAD OF triggers, TRUNCATE statement, FETCH clause.2011SQL:2011Adds temporal data (PERIOD FOR). Enhancements for window functions and FETCH clause. 2016SQL:2016Adds row pattern matching, polymorphic table functions, JSON.SQL pamatkomandasCREATE 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],...];SQL valodas SELECT vaicājuma piemērsselect mittee_level "CC Level", f.name "CC Name", ????? (select kk.user_name from gl_loan.ln_cc_member kk where kk.id in????? (select _member_id from gl_loan.ln_cc_session_member ii ????? where _session_id =_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 _member_id from gl_loan.ln_cc_session_member ii ????? where _session_id =_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(ments,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 ccwhere? a.id=b.loancase_idand b.product_id=e.id and mittee_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 mittee_level, f.name, a.case_nameSELECT vaicājuma pamatelementiSELECT ...Kādas vērtības gribam iegūt (kolonu un funkciju)? (5)FROM ...No kādām datu tabulām? (1)WHERE ...Kādi ir rindu meklē?anas noteikumi? (2)GROUP by ...Kādi ir rindu grupē?anas noteikumi? (3)HAVING ...Kādi ir rindu grupu meklē?anas noteikumi? (4)ORDER by ... Kā sakārtot iegūtos rezultātus? ??iro?anas norādes. (6)Tabula FirmasF_NUMF_NOSDIB_DATSTAT_KAPTELADRFirmas numursNosaukumsDibinā?anas datumsStatūtu kapitālsTelefonsAdrese1AA1998.12.0550 000,00 Ls7222222Rīga, Garā iela 152BB1998.05.0720 000,00 Ls7111111Rīga, Zir?u iela 33CC1999.03.05100 000,00 Ls7333333Rīga, Avotu 12Tabula DarbiniekiD_NUMUZVVARAMATSDZIMNUM_FIRDarbinieka numursUzvārdsVārdsAmatsDzimumsFirmas numurs1KoksJurisgaldnieksvīrietis22ZarsInesekrāsotājssieviete23CelmsLieneuzkopējasieviete14KoksLienesekretāresieviete15ZarsVarisgaldnieksvīrietis3Tabula DarbiNUMNOSIZP_DATSTUNDASST_CENADARBIN_NUMDarba numursNosaukumsIzpildes datumsStundasStundas cenaDarbinieka numurs1darbs11999.03.03.52,00 Ls12darbs21999.05.03.101,50 Ls13darbs31999.07.03.122,00 Ls14darbs41999.01.03.112,00 Ls25darbs51999.03.03.81,80 Ls26darbs61999.05.03.102,50 Ls37darbs71999.02.03.142,20 Ls31. Veikt visas tabulas (visu kolonu vērtību) izvadi.SELECT * FROM Firmas;F_NUMF_NOSDIB_DATSTAT_KAPTELADR1AA1998.12.0550 000,00 Ls7222222Rīga, Garā iela 152BB1998.05.0720 000,00 Ls7111111Rīga, Zir?u iela 33CC1999.03.05100 000,00 Ls7333333Rīga, Avotu 12Tabulas nosaukuma pierakstī?ana kolonu apzīmējumiem.2. Iegūt visu firmu nosaukumu sarakstu.SELECT Firmas.F_NUM, Firmas.F_NOSFROM Firmas;Firmas numursNosaukums1AA2BB3CCSinonīma izmanto?ana.3. Iegūt firmu, kuru statūtkapitāls lielāks par 50 000, nosaukumu sarakstu. SELECT A.F_NUM, A.F_NOSFROM Firmas AWHERE A.STAT_KAP > 50000;Firmas numursNosaukums3CCJoe Celko – labākais SQL grāmatu autors478599538735Joe Celko is an American relational database expert from Austin, Texas. He has participated on the ANSI X3H2 Database Standards Committee, and helped write the SQL-89 and SQL-92 standards. He is the author of a Morgan-Kaufmann series of books on SQL, and over 1200 published articles on SQL and other database topics. He had been a full-time statistician for several years. He is credited with coining the term lasagna code and popularizing Michael J. Kamfonas' nested set model for trees in SQL, a taxonomy of data encoding schemes, and several other design patterns in SQL DDL and DML. Grāmatas par SQL valodu2957195403860 Datu izgū?anas varianti no datu bāzes SavienojumsDatu bāzes sistēmaSQL redaktors(komandrindas)SQL> SELECT...SQLDatu bāzes vadības sistēma (DBVS)Datu bāze (DB)SQL redaktors(teksta redaktors + palīdzība)SQLIDE rīks (Integrated Development Environment)SQLSQLLietojums (lietojumprogramma)SQL vaicājumu izpildeSemantiskā analīzeSQL vaicājumsSintaksiskā analīzeDatu apstrādesdarbību secības optimizācijaStatistikas iegū?anaDatu bāzeRelāciju algebras darbību secībaIeteikumi (hints)Datora datu apstrādes darbību secība AnalīzeIzpildes plāns IzpildeSQL valodas standartu izmai?as1986. g. SQL k?uva par standartu Amerikas Nacionālajā Standartu institūtā (American National Standards Institution (ANSI)) un 1987. g. Starptautiskajā Standartizācijas institūtā (International Organization of Standardization (ISO)). -19050176530SQL standartos ir veikti daudzi pilnveidojumi un uzlabojumi. Ir ?ādas SQL standartu versijas: SQL-89 (datu integritātes noteikumu pilnveido?ana), SQL-92 (jauni datu tipi, CASE konstrukcija, CHECK ierobe?ojumi), SQL:1999 (objektu-relāciju DB vaicājumi), SQL:2003 (XML DB struktūras, analītiskās funkcijas), SQL:2006 (XML vaicājumi), SQL:2008 (INSTEAD OF tipa trigeri, ??ērstabulas (pivot tables)). Firma Microsoft ir izstrādājusi U-SQL valodu. Tas ir SQL pilnveidojums darbam ar ?oti lielām DB ("Big Data" database). Firma Apache Software veido jaunu vienkār?otu pierakstu SQL valodai. Ir jau izstrādātas divas realizācijas NewSQL Jdb un NewSQL S2. Standarts SQL 861. Creating and Manipulating Table Definitions ( Create, Alter+Add, Drop )1.1 CREATE TABLE1.2 DROP TABLE1.3 ALTER TABLE1.4 CREATE [UNIQUE] INDEX1.5 Use of indexes for performance enhancement1.6 Use of indexes as a data integrity check1.7 DROP INDEX2. Updating the database ( Insert, Update+Set, Delete )2.1 Adding rows to a table: the INSERT command2.2 Updating rows of a table: the UPDATE/SET -command2.3 Deleting rows from a table: the DELETE -command3. Controlling the Execution of Commands ( Commit / Rollback Work )3.1 AUTOCOMMIT modes3.2 The ROLLBACK WORK command4. Granting and Revoking User Privileges4.1 GRANT4.2 REVOKESQL-92 was the third revision of the SQL database query language. Unlike SQL-89, it was a major revision of the standard. New FeaturesSQL AgentNew data types defined: DATE, TIME, TIMESTAMP, INTERVAL, BIT string, VARCHAR strings, and NATIONAL CHARACTER strings.Support for additional character sets beyond the base requirement for representing SQL statements.New scalar operations such as string concatenation, date and time mathematics, and conditional statements.New set operations such as UNION JOIN, NATURAL JOIN, set differences, and set intersections.Support for alterations of schema definitions via ALTER and DROP.Bindings for C, Ada, and MUMPS.New features for user privileges.New integrity-checking functionality such as within a CHECK constraint.New schema definitions for "Information".Dynamic execution of queries (as opposed to prepared).Better support for remote database access.Temporary tables.Transaction isolation levels.New operations for changing data types on the fly via CAST.Scrolling patibility flagging for backwards and forwards compatibility with other SQL standards.Call Level InterfaceStandarts SQL99 New built-in data types for increased modeling power;- Boolean- Large objects (LOBs)- Enhanced update capabilities- Update/delete through unions- Additional predicates (FOR ALL, FOR SOME, SIMILAR TO)Triggers:- Enhances integrity mechanism (active DBMS)- Different triggering events: update/delete/insert- Optional condition- Activation time: before or after- Multi-statement action- Several triggers per tableCondition and multi-statement action per each row or per statement:- Roles- GRANT/REVOKE privileges to roles- GRANT/REVOKE roles to users and other roles- Recursion- Different search strategies (depth first, breadth first)Savepoints:- Enhances user-controlled integrity- Savepoint definition- Roll back to savepoint- NestingOLAP extensions: CUBE, ROLLUP, Expressions in ORDER BY, ?Object-relational extensions- User-defined types- Encapsulation- Collection types- Arrays- Row types- Like record structures in programming languages- Type of rows in tables- Nesting (rows with row-valued fields)- Reference types- Support “object identity”- Navigational access (path expressions)- User-defined functions- User-defined procedures- SQL and external procedures- Overloading and overriding- Subtables (table hierarchies)The SQL:2003 standard makes minor modifications to all parts of SQL:1999 (also known as SQL3), and officially introduces a few new features such as: XML-related features (SQL/XML)Window functionsthe sequence generator, which allows standardized sequencestwo new column types: auto-generated values and identity-columnsthe new MERGE statementextensions to the CREATE TABLE statement, to allow "CREATE TABLE AS" and "CREATE TABLE LIKE"removal of the poorly-implemented "BIT" and "BIT VARYING" data typesThe SQL:2008 standard is split into several parts, covering the Framework, the Foundation, the Call-Level Interface, Persistent Stored Modules, Management of External Data, Object Language Bindings, Information and Definition Schemas, Routines and Types Using Java, and various "Related Specifications."Additions to the Foundation includeenhanced MERGE and DIAGNOSTIC statements,the TRUNCATE TABLE statement,comma-separated WHEN clauses in a CASE expression,INSTEAD OF database triggerspartitioned JOIN tables,support for various XQuery regular expression/pattern-matching features, andenhancements to derived column names. SQL procedurālie papla?inājumi (programmē?anas valodas datu bāzes serverī) ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download