Using SQL in MS Access

Similar documents
Background Information. Instructions. Problem Statement. EXAM REVIEW PROJECT INSTRUCTIONS Exam #2 Review Football Statistics Problem

Database Management Systems. Chapter 5

RESERVATION.Sid and RESERVATION.Bid are foreign keys referring to SAILOR.Sid and BOAT.Bid, respectively.

TECHNICAL NOTE HOW TO USE LOOPERS. Kalipso_TechDocs_Loopers. Revision: 1.0. Kalipso version: Date: 16/02/2017.

Horse Farm Management s Report Writer. User Guide Version 1.1.xx

Database Systems CSE 414

Fastball Baseball Manager 2.5 for Joomla 2.5x

Healthcare Analytics Anticoagulation Time in Therapeutic Range Calculation Documentation September 4, 2015

How to Use My MS Access Hockey Statkeeper

Homework 4 PLAYERS, TEAMS, MATCHES, PENALTIES, COMMITTEE_MEMBERS

Club s Homepage Welcome Club Calendar Logout Add a Request Play Date Requested Time Hole Selection # of Tee Times Break Link

MIS0855: Data Science In-Class Exercise: Working with Pivot Tables in Tableau

Exam Name: db2 udb v7.1 family fundamentals

AFFINITY SPORTS [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]

Club s Homepage Use this feature to return the club s website.

Mac Software Manual for FITstep Pro Version 2

Inspection User Manual

Inspection User Manual This application allows you to easily inspect equipment located in Onix Work.

Populating Custom Excel Spreadsheets: The Non-DDE Way

OZCHASE RACING - ONLINE NOMINATIONS USER GUIDE - Ozchase Online Nominations User Guide Page 1 of 28

GSIS Video Director s Report ASCII File Layout 2013 Season

Oracle 11g Secure Files Overview Inderpal S. Johal. Inderpal S. Johal, Data Softech Inc.

Gaia ARI. ARI s Gaia Workshop. Grégory Mantelet. 20 th June 2018 CDS / ARI

Report. User guide for the NOWIcob tool (D5.1-75) Author(s) Matthias Hofmann Iver Bakken Sperstad Magne Kolstad

Comp115: Databases. Relational Algebra

Allocation of referees, hours and pistes User manual of Engarde - August, 2013

WEST POINT GOLF CLUB USING THE GOLFSOFTWARE PROGRAM FOR THE DRAW AND SCORING

Diver Training Options

Working with Marker Maps Tutorial

Oracle ebusiness CCTM Supplier: Rate Card

UNITY 2 TM. Air Server Series 2 Operators Manual. Version 1.0. February 2008

RESERVATION.Sid and RESERVATION.Bid are foreign keys referring to SAILOR.Sid and BOAT.Bid, respectively.

CGA INTERCLUB COMPETITION

Multi Class Event Results Calculator User Guide Updated Nov Resource

Inform Racing In Running Trading Tool

In my left hand I hold 15 Argentine pesos. In my right, I hold 100 Chilean

Understood, Inc. User Guide SCUBA Solutions Version 1.7

From the previous assignment, we have an Entity Relationship diagram (ERD or ER Diagram).

Key skills Information & Communication Technology. Level 3. Football

Background Information. Instructions. Problem Statement. HOMEWORK INSTRUCTIONS Homework #4 Pennsylvania Deer Problem

FRANCE GALOP PROFESSIONAL AREA GENERAL GUIDE TO WEBSITE FUNCTIONS (UNRESTRICTED ACCESS)

Online League Management lta.tournamentsoftware.com. User Manual. Further support is available online at

SQL Aggregate Queries

2017 USTA Chattanooga - Local League Rules

Excel 2013 Pivot Table Calculated Field Greyed Out

by Robert Gifford and Jorge Aranda University of Victoria, British Columbia, Canada

THE STATCREW SYSTEM For Basketball - What's New Page 1

How to run a club night

Background Information. Project Instructions. Problem Statement. EXAM REVIEW PROJECT Microsoft Excel Review Baseball Hall of Fame Problem

Maestro 3 rd Party Golf User Guide

HOW TO SUBMIT YOUR RACE RESULTS ONLINE?

A GUIDE TO USING MYNETBALL (CLUBS)

Administration and IT Assignment Assessment Task: Sounds on the Shore

Package rdpla. August 13, 2017

Software Manual for FITstep Pro Version 2

Wickets Administrator

Ameren Oracle ebusiness CCTM Supplier

One-way ANOVA: round, narrow, wide

Managing Timecard Exceptions

Decompression Plans October 26, 2009

METHODS PAPER: Downstream Bathymetry and BioBase Analyses of Substrate and Macrophytes

CENTER PIVOT EVALUATION AND DESIGN

THIS MANUAL HAS BEEN PREPARED FOR THE PURPOSE OF ASSISTING IN THE INSTALLATION AND MAINTENANCE OF THE MINIMAX GOLF HANDICAPPING SYSTEM.

Team BUSY : Excise register RG-23 A-11, provision made to input starting S.No.

Dive Planet. Manual. Rev Basic User Interface. 2 How to organize your dives. 3 Statistics. 4 Location Service and Map View.

Analysis of Variance. Copyright 2014 Pearson Education, Inc.

Competition Management Online User Guide for Basketball

CHICAGO DISTRICT LEAGUE RULES AND PROCEDURES Updated February 7, 2018 (Found at

Redis Graph. A graph database built on top of redis

Swing Labs Training Guide

FireHawk M7 Interface Module Software Instructions OPERATION AND INSTRUCTIONS

Session 2: Introduction to Multilevel Modeling Using SPSS

Key Skills Information and communication technology. Level 3. Squash

Start the Polars program and load this file by using the explorer tab on the left side. You will get following picture:

Overview. What Is It? Technical Information

IMGA PAIRINGS INSTRUCTIONS USING the ONLINE GOLF GENIUS SOFTWARE ROGRAM Revised as of 12/31/2017

2014/2015. Approvals for the Publication and Use of Victorian Thoroughbred Race Fields. Guide to the Provision of Information

How to Setup and Score a Tournament. May 2018

SQL LiteSpeed 3.0 Installation Guide

The ICC Duckworth-Lewis Calculator. Professional Edition 2008

2-. Allocation of catches aggregates to individual Gear and Species

The ICC Duckworth-Lewis-Stern calculator. DLS Edition 2016

How to Create a PAR. Campus procedures for operation of the PAR system include the following steps:

INSIDE VOLLEY TENNIS

MyCricket User Manual

Hazard Training Guide

The Powerful Sealing Calculation

Entry Checks and Results Forum for Dressage Clubs in NSW Sunday 26 February 2017

Access will be via the same Player Registration tab via the Player Registrations Officer role section.

HOW TO SETUP ROUND ROBIN IN DARTS FOR WINDOWS

RULES AND REGULATIONS FOR COMPETITIONS AND MATCHES ( RULES ) RULES AND REGULATIONS FOR COMPETITIONS AND MATCHES ( Rules ) Section 1 General

Proform Software Upgrade v1.9.1 Release Notes Welcome to release of the Proform Form Book and System Builder.

[CROSS COUNTRY SCORING]

2018 NC USTA LEAGUE MIXED DOUBLES STATE CHAMPIONSHIPS TOURNAMENT INFORMATION

STATIONARY SPRINKLER IRRIGATION SYSTEM

The MLB Language. Figure 1.

Race Screen: Figure 2: Race Screen. Figure 3: Race Screen with Top Bulb Lock

East Bay Swim League. Training Guide and Reporting Manual. For EBSL Team Computer Directors Version 1.2

Boyle s Law: Pressure-Volume Relationship in Gases

1 P a g e J O G R C & L S R A - S e n i o r I n f o r m a t i o n P a c k BANKERS ORDER FOR LANCASTER JOHN O GAUNT ROWING CLUB

Transcription:

Using SQL in MS Access Himadri Barman 1. Creating Tables Create a table PLAYERS. The fields and corresponding data types along with other requirements are: Player_ID Text of size 10, primary key Player_Name Text of size 100, mandatory field Player_Add Text of size 200 Player_DOB Date/Time Player_Weight Number Player_Height Number Player_Salary Currency, Default salary is 50000 Player_Eligible Yes/No Player_Remarks Memo CREATE TABLE PLAYERS (Player_ID TEXT (10) PRIMARY KEY, Player_Name TEXT (100) NOT NULL, Player_Add TEXT (200), Player_DOB DATETIME, Player_Weight NUMBER, Player_Height NUMBER, Player_Salary CURRENCY DEFAULT 1 50000, Player_Eligible YESNO, Player_Remarks MEMO) 2. Insert Data Enter data in all the fields. INSERT INTO PLAYERS VALUES ('123', 'RAM','GUWAHATI', '12/31/87', 67, 167, 4500, yes, 'captain') Selectively enter data into some fields. INSERT INTO PLAYERS (Player_ID, Player_Name) VALUES ('456', 'SHYAM') 3. Changing the Structure of the Table Add an additional field Player_Rating (data type is Number) to the table PLAYERS. ALTER TABLE PLAYERS ADD COLUMN Player_Rating NUMBER 1 If the DEFAULT is not working, you have to change a setting in MS Access. Go to File -> Options -> Object Designers -> Query Design. Tick both the options under SQL Server Compatible Syntax (ANSI 92) Downloaded from http://himadri.cmsdu.org 1

Delete the field Player_Rating from the table PLAYERS. ALTER TABLE PLAYERS DROP COLUMN Player_Rating What to do if you forget to add the primary key in the table PLAYER? ALTER TABLE PLAYERS ADD PRIMARY KEY (Player_ID) 4. Updating Data Update the address of the player whose id is 123 to DIBRUGARH. UPDATE PLAYERS SET Player_Add = 'DIBRUGARH' WHERE Player_ID = '123' 5. Deleting Data Delete player whose id is 456 from table PLAYERS. DELETE FROM PLAYERS WHERE Player_ID = '456' 6. Creating Relationships Create table TEAM and then create a 1 : M relationship between TEAM and PLAYERS. Enforce referential integrity. The table TEAM has the following fields: Team_ID Text of size 10, primary key Team_Name Text of size 100, mandatory Team_Address Text of size 200 CREATE TABLE TEAM (Team_ID TEXT (10) PRIMARY KEY, Team_Name TEXT (100) NOT NULL, Team_Add TEXT (200)) ALTER TABLE PLAYERS ADD COLUMN Team_ID TEXT (10) ALTER TABLE PLAYERS ADD FOREIGN KEY (Team_ID) REFERENCES TEAM (Team_ID) OR ALTER TABLE PLAYERS ADD COLUMN Team_ID TEXT (10) REFERENCES TEAM (Team_ID) Create table SPONSOR and then create a 1 : 1 relationship between TEAM and SPONSOR (A team has only one lead sponsor and a sponsor can handle only one team as a lead sponsor. It is to be remembered that there are many sponsors whose data will be stored in the SPONSOR table). Enforce referential integrity. The table TEAM has the following fields: Downloaded from http://himadri.cmsdu.org 2

Sponsor_ID Text of size 10, primary key Sponsor_Name Text of size 100, mandatory Sponsor_Address Text of size 200 Sponsor_Amount Currency, Default sponsorship amount is 100 thousand CREATE TABLE SPONSOR (Sponsor_ID TEXT (10) PRIMARY KEY, Sponsor_Name TEXT (100) NOT NULL, Sponsor_Add TEXT (200), Sponsor_Amount CURRENCY DEFAULT 100000) ALTER TABLE TEAM ADD COLUMN Sponsor_ID TEXT (10) CREATE UNIQUE INDEX LEAD_SPONSOR ON TEAM (Sponsor_ID) ALTER TABLE TEAM ADD FOREIGN KEY (Sponsor_ID) REFERENCES SPONSOR (Sponsor_ID) 7. Retrieving Data Before executing the following queries, see to it that sufficient data is there in both the tables or you ll be returned with no results. Retrieve all data from table PLAYERS. SELECT * FROM PLAYERS Retrieve the name of all players from table PLAYERS. In the output, display field Player_Name as Name of Player. ORDER BY Player_Name ASC Retrieve the ids of the team distinctly (only once) from the table PLAYERS. SELECT DISTINCT TEAM_ID FROM PLAYERS Retrieve the total number of players per team and the salary paid to them from the table PLAYERS. In the output, display the output for players per team as Total Players and salary paid to them as Total Salary. SELECT Team_ID, Count (Player_ID) as [Total Players], SUM( Player_Salary) as [Total Salary] FROM PLAYERS GROUP BY Team_ID Downloaded from http://himadri.cmsdu.org 3

As previous query, but this time the team ids should be sorted in the descending order. SELECT Team_ID, Count (Player_ID) as [Total Players], SUM( Player_Salary) as [Total Salary] FROM PLAYERS GROUP BY Team_ID ORDER BY Team_ID DESC Retrieve the names of all the players along with their address for team with id 001. WHERE Team_ID ='001' Retrieve the names of all the players along with their address for team with id 001 or 002. WHERE Team_ID IN ('001','002') Retrieve the names of all the players along with their address for team with id 001 or salary of player is greater than 3000. WHERE Team_ID ='001' OR Player_Salary > 3000 Retrieve the names of all the players whose name starts with R. SELECT Player_Name FROM PLAYERS WHERE Player_Name like 'R*' Retrieve the names of all the players, their addresses and DOB whose DOB is between January 1, 1985 and January 1, 1988. The results should be ordered by player name in the ascending order. SELECT Player_Name, Player_Add, Player_DOB FROM PLAYERS WHERE Player_DOB BETWEEN #1/1/1985# AND #1/1/1988# ORDER BY Player_Name ASC Retrieve the names of all the players, their address and the team name. SELECT Player_Name, Player_Add, Team_Name FROM PLAYERS INNER JOIN TEAM ON PLAYERS.Team_ID=TEAM.Team_ID (The INNER JOIN keyword selects all rows from both tables as long as there is a match between the columns in both tables.) Downloaded from http://himadri.cmsdu.org 4

Retrieve the names of all the players, their address and the team name from the team with id 001. SELECT Player_Name, Player_Add, Team_Name FROM PLAYERS INNER JOIN TEAM ON PLAYERS.Team_ID=TEAM.Team_ID WHERE PLAYERS.Team_ID='001' A Left Outer Join Query SELECT Player_Name, Player_Add, Team_Name FROM PLAYERS LEFT OUTER JOIN TEAM ON PLAYERS.Team_ID=TEAM.Team_ID (The LEFT OUTER JOIN keyword returns all rows from the left table (table1), with the matching rows in the right table (table2). The result is NULL in the right side when there is no match. A left outer join retains all of the rows of the left table, regardless of whether there is a row that matches on the right table.) A Right Outer Join Query SELECT Player_Name, Player_Add, Team_Name FROM PLAYERS RIGHT OUTER JOIN TEAM ON PLAYERS.Team_ID=TEAM.Team_ID The RIGHT OUTER JOIN keyword returns all rows from the right table (table2), with the matching rows in the left table (table1). The result is NULL in the left side when there is no match. Retrieve the information as to how to many players are there in the PLAYERS table SELECT COUNT(*) as Number of Players FROM PLAYERS Find the average salary of the players who are there in the PLAYERS table SELECT AVG(Player_Salary) as Average Salary of Players FROM PLAYERS 8. Deleting Tables Delete the table PLAYERS. DROP TABLE PLAYERS Downloaded from http://himadri.cmsdu.org 5