archivists toolkit sql - a tutorial

25
Using phyMyAdmin to create SQL queries with Archivist Toolkit Contents Logging in through the web interface.................................2 Search............................................................... 4 Structure............................................................ 5 Browse............................................................... 6 SQL – one table selected............................................. 7 SQL multiple table query............................................. 8 Printing or Exporting results.......................................12 Appendix............................................................ 17 1

Upload: michael-cummings

Post on 16-Jan-2017

141 views

Category:

Data & Analytics


2 download

TRANSCRIPT

Page 1: Archivists toolkit SQL - a tutorial

Using phyMyAdmin to create SQL queries with Archivist Toolkit

Contents

Logging in through the web interface..........................................................................................................2

Search..........................................................................................................................................................4

Structure......................................................................................................................................................5

Browse.........................................................................................................................................................6

SQL – one table selected.............................................................................................................................7

SQL multiple table query.............................................................................................................................8

Printing or Exporting results......................................................................................................................12

Appendix...................................................................................................................................................17

1

Page 2: Archivists toolkit SQL - a tutorial

Using phyMyAdmin to create SQL queries with Archivist Toolkit

Logging in through the web interface

1. Login at

http://the server address/phpmyadmin

User: atdbreadPassword: [see C.Peterson]

2. Select ‘toolkit’

2

Page 3: Archivists toolkit SQL - a tutorial

Using phyMyAdmin to create SQL queries with Archivist Toolkit

This document covers some basics of using SQL queries.

We won’t use these features:

Query Operations Privileges Tracking Designer

We should be using user account ‘atdbread’ that has read-only rights.

This document will show screens from Mike’s admin account including options to delete records, and other actions that are not available to the user atdbread.

Features covered in this document include:

Search Structure Browse SQL

o Printo Export

The directions provide examples. The reader may enter the text shown in red font.

3

Page 4: Archivists toolkit SQL - a tutorial

Using phyMyAdmin to create SQL queries with Archivist Toolkit

SearchExample: Go to the Search tab; enter search for Snyder, Mitch click Go

Returns results:

4

Page 5: Archivists toolkit SQL - a tutorial

Using phyMyAdmin to create SQL queries with Archivist Toolkit

StructureSelect the Structure tab

Shows number of rows in each table, there are 1,016 Accessions records.

Example: Select the Accessions table to view the structure of a specific table.

Returns field list, properties of fields.

5

Page 6: Archivists toolkit SQL - a tutorial

Using phyMyAdmin to create SQL queries with Archivist Toolkit

BrowseSelect the Browse tab. Click a table name on the list of tables, e.g., Accessions.

Lets you browse records in a table.

The Appendix of this document lists some same data from important tables in the system. The sample data shows the “id” fields that you need to know in order to create SQL statements that get fields from more than one table.

6

Page 7: Archivists toolkit SQL - a tutorial

Using phyMyAdmin to create SQL queries with Archivist Toolkit

SQL – one table selectedSelect the SQL tab

A default query will display for the chosen table. Select * means select all fields in the table.

We will only be using the SELECT command. Notice a list of fields or ‘columns’ for the chosen table is shown on the right-hand side of the screen.

7

Page 8: Archivists toolkit SQL - a tutorial

Using phyMyAdmin to create SQL queries with Archivist Toolkit

SQL multiple table queryThe general syntax of an SQL query is to identify the fields you want in the “select” clause, then list the tables in the “from” clause. In the “where” clause you identify which id fields are common between the tables, and optionally any conditions. The optional “order by” clause may be used to specify sorting preference.

Example: Copy and paste this sample query into the query box:

SELECTResources.resourceId,Resources.resourceIdentifier1,Resources.title as ResourceTitle,ResourcesComponents.title as ComponentTitle,ResourcesComponents.resourceLevel,ResourcesComponents.resourceComponentId as ComponentIdentifier,ResourcesComponents.restrictionsApply,ArchDescriptionRepeatingData.title as NoteType,ArchDescriptionRepeatingData.notesEtcTypeId,ArchDescriptionRepeatingData.noteContentFROM `Resources`,`ResourcesComponents`,`ArchDescriptionRepeatingData`WHERE Resources.resourceId=ResourcesComponents.resourceId ANDResourcesComponents.resourceId=ArchDescriptionRepeatingData.resourceId ANDArchDescriptionRepeatingData.notesEtcTypeId IN ('8','9','31') ORDER BYResources.resourceId, ComponentTitle;

Then click the GO button

8

Page 9: Archivists toolkit SQL - a tutorial

Using phyMyAdmin to create SQL queries with Archivist Toolkit

Results of query. This query returned over 72 thousand rows! It shows 30 rows at a time, and you can scroll horizontally to see the contents of the fields.

Click ‘Show query box’ to edit the query

Try this: Edit the WHERE clause, adding a condition to list only MS0253:

WHERE

Resources.resourceId=ResourcesComponents.resourceId AND

ResourcesComponents.resourceId=ArchDescriptionRepeatingData.resourceId AND

ArchDescriptionRepeatingData.notesEtcTypeId IN ('8','9','31') AND

Resources.resourceidentifier1='MS0253'

Then click GO button

9

Page 10: Archivists toolkit SQL - a tutorial

Using phyMyAdmin to create SQL queries with Archivist Toolkit

Results of revised query, 42 rows selected.

Exercise to retrieve extents in DCAAP

1. Find information about repositories,including the important repositoryIda. Select the SQL tab

i. Enter this query and click Go

select * from `Repositories`;

ii. Note the DCAAP repository id is 5. Let’s find the extents of Resources associated with DCAAP:

b. Select the SQL tabi. Enter this query and click Go

(note the field names are enclosed in backticks in the select clause, butthe field name in the where clause is not. The value in the where clauseis enclosed in single quotes; the statement ends in a semicolon.)

select `title`,`extentNumber`,`extentType`from `Resources`whereResources.repositoryId='5';

10

Page 11: Archivists toolkit SQL - a tutorial

Using phyMyAdmin to create SQL queries with Archivist Toolkit

Result of the query

This might make a good report.

11

Page 12: Archivists toolkit SQL - a tutorial

Using phyMyAdmin to create SQL queries with Archivist Toolkit

Printing or Exporting resultsScroll to the end of the query output.

Select the Print view (with full texts) to get a printout that looks like the example below.

12

Page 13: Archivists toolkit SQL - a tutorial

Using phyMyAdmin to create SQL queries with Archivist Toolkit

Select the Export option. The following option selector displays (the default Format may say SQL):

13

Page 14: Archivists toolkit SQL - a tutorial

Using phyMyAdmin to create SQL queries with Archivist Toolkit

Choose Quick or Custom display options. Choose a Format, e.g., CSV for ExcelClick the Go button

The file will be downloaded to your workstation, as in this example, Resources.csv

14

Page 15: Archivists toolkit SQL - a tutorial

Using phyMyAdmin to create SQL queries with Archivist Toolkit

Start a new spreadsheet in ExcelGo to the Data tab, click the “From Text” option

Select the file to import

Click the Import button

15

Page 16: Archivists toolkit SQL - a tutorial

Using phyMyAdmin to create SQL queries with Archivist Toolkit

Complete the steps in Text Import Wizard

Note: Select Other from the Delimiters section, and enter a semicolon character in the box.

The fields should look like this screenshot:

16

Page 17: Archivists toolkit SQL - a tutorial

Using phyMyAdmin to create SQL queries with Archivist Toolkit

Here is our report as a spreadsheet:

17

Page 18: Archivists toolkit SQL - a tutorial

Using phyMyAdmin to create SQL queries with Archivist Toolkit

AppendixSample data

Table: Repositories

repositoryId: 1repositoryName: Special Collections Research Center, The George Washington UniversityshortName: Spec

repositoryId: 2repositoryName: Global Resources CentershortName: GRC

repositoryId: 3repositoryName: Gifts and ExchangeshortName: Gifts

repositoryId: 4repositoryName: SC OfficeshortName: SCO

repositoryId: 5repositoryName: DC Africana Archives ProjectshortName: DCAAP

Table: Resources

Sample RecordrepositoryId: 1resourceId: 6created: 2014-02-20 13:10:5037title: Samuel Solomon papersdateExpression: 1932-1964dateBegin: nulldateEnd: nullextentNumber: 36extentType: linear feetdisplayCreator: Solomon, Samuel JosephdisplayRepository: Special Collections Research Center, The George Washington UniversityresourceIdentifier1: MS2092resourceIdentifier2: nullfindingAidTitle: Guide to the Samuel Solomon papers,

<date calendar="gregorian" era="ce">1932-1964</date>findingAidDate: 2006

18

Page 19: Archivists toolkit SQL - a tutorial

Using phyMyAdmin to create SQL queries with Archivist Toolkit

author: Processed by: Special Collections Staff;machine-readable finding aid created by: Jennifer King

descriptionRules: Describing Archives: A Content StandardTable: ResourcesComponents

Sample RecordresourceId: 6resourceComponentId: 2667sequenceNumber: 0title: Papers,dateExpression: 1932-1964resourceLevel: seriessubdivisionIdentifier: MS2092 Series 1

Table: ArchDescriptionRepeatingData

Sample RecordresourceComponentId: 2667repeatingDataType: NotesequenceNumber: 1notesEtcTypeId: 31title: Scope and Contents notenoteContent: This series consists of documents from Samuel Solomon's career in aviation. He

was manager of the Washington National Airport; organized a new airline, National Airways (the predecessor of Northeast Airlines) with Amelia Earhart in 1933; was president and trainer of the War Training Institute; and was Chairman of the Airlines Committee for the United States Air Policy.

The materials range in date from 1932-64.

Table: NotesEtcTypesSample RecordnotesEtcTypeId: 31notesEtcName: Scope and Contents note

Sample RecordnotesEtcTypeId: 8notesEtcName: Conditions Governing Access note

19

Page 20: Archivists toolkit SQL - a tutorial

Using phyMyAdmin to create SQL queries with Archivist Toolkit

Document name: Using phpMyAdmin to create SQL queries with Archivist ToolkitDocument name: AT-SQL-TutorialDocument version: 1Date: December 2, 2015Author: Michael Cummings, Scholarly Technology Group

20