Database. Quiz with Explainations. Hans-Petter Halvorsen, M.Sc.

Similar documents
Database Systems. S. Adams. Dilbert. Available: Hans-Petter Halvorsen

SQL Server and SQL Structured Query Language

Database Views & Stored Procedures. Hans-Petter Halvorsen, M.Sc.

Introduction to ERwin

Database Lab. Hans-Petter Halvorsen

Database Overview. Introduction to Database Systems, ERwin, SQL Server, SQL, etc. Hans-Petter Halvorsen, M.Sc.

Software Platforms. Quiz with Explainations. Hans-Petter Halvorsen, M.Sc.

UML. Quiz with Explainations. Hans-Petter Halvorsen, M.Sc.

Structured Query Language

Unit Testing. Quiz with Explainations. Hans-Petter Halvorsen, M.Sc.

Industrial IT Laboratory Work Hans-Petter Halvorsen

Software Architecture

Software Documentation

Software Implementation

Source Code Control. Quiz with Explainations. Hans-Petter Halvorsen, M.Sc.

University College of Southeast Norway. Introduction to Database. Systems. Hans-Petter Halvorsen,

Software Testing. Hans-Petter Halvorsen, M.Sc.

Using SQL Server in C#

Databases CSCI 201 Principles of Software Development

University College of Southeast Norway ASP.NET. Web Programming. Hans-Petter Halvorsen,

Software Architecture

Create a Virtual Test Environment

A practical introduction to database design

Week Assignment. Software Testing Test Planning. Hans-Petter Halvorsen

Working with Databases and Java

SQL language. Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c)

Data Modeling Diagram Open Source Tool Oracle

From business need to implementation Design the right information solution

The DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data.

The Relational Model. Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC)

Consistency The DBMS must ensure the database will always be in a consistent state. Whenever data is modified, the database will change from one

SCADA Lab. Supervisory Control and Data Acquisition. Hans-Petter Halvorsen

Networks and Web for Health Informatics (HINF 6220)

MySQL. A practical introduction to database design

CS143: Relational Model

Team Assignment. Final Software Delivery. IA4412 Software Engineering

The appendix contains information about the Classic Models database. Place your answers on the examination paper and any additional paper used.

A hypothetical M:M student schedule example

CSC 453 Database Technologies. Tanu Malik DePaul University

CSC 355 Database Systems

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

Simulation in LabVIEW. Hans-Petter Halvorsen, M.Sc.

Team Foundation Server Visual Studio Team Services. Hans-Petter Halvorsen, M.Sc.

Introduction to Data Management. Lecture #4 (E-R Relational Translation)

CGS 3066: Spring 2017 SQL Reference

In This Lecture. SQL Data Definition SQL SQL. Non-Procedural Programming. Notes. Database Systems Lecture 5 Natasha Alechina

Databases: Introduction

Physical Design of Relational Databases

CS317 File and Database Systems

The University of Nottingham

COMP 430 Intro. to Database Systems. Encapsulating SQL code

Visual Studio Team Services

UNIVERSITY OF BOLTON WESTERN INTERNATIONAL COLLEGE FZE BSC (HONS) COMPUTING SEMESTER ONE EXAMINATION 2015/2016 DATABASE THEORY AND PRACTICE

The Relational Model. Chapter 3

Introduction to MySQL /MariaDB and SQL Basics. Read Chapter 3!

Score. 1 (10) 2 (10) 3 (8) 4 (13) 5 (9) Total (50)

CS127 Homework #3. Due: October 11th, :59 P.M. Consider the following set of functional dependencies, F, for the schema R(A, B, C, D, E)

Oral Questions and Answers (DBMS LAB) Questions & Answers- DBMS

University College of Southeast Norway. Database Communication. in LabVIEW. Hans-Petter Halvorsen,

Where is Database Management System (DBMS) being Used?

CMPE 131 Software Engineering. Database Introduction

What is database? Types and Examples

Get Table Schema In Sql Server 2008 To Add Column If Not Exists >>>CLICK HERE<<<

Database Management Systems,

Informatics 1: Data & Analysis

CS317 File and Database Systems

ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION

Chapter 3: Introduction to SQL. Chapter 3: Introduction to SQL

SQL: Part II. Announcements (September 18) Incomplete information. CPS 116 Introduction to Database Systems. Homework #1 due today (11:59pm)

EE221 Databases Practicals Manual

CSE 344 AUGUST 1 ST ENTITIES

Informatics 1: Data & Analysis

CSE 544 Principles of Database Management Systems

Relational Model. Topics. Relational Model. Why Study the Relational Model? Linda Wu (CMPT )

Today Learning outcomes LO2

UML. Unified Modeling Language. Hans-Petter Halvorsen, M.Sc. O. Widder. (2013). geek&poke. Available:

SQL Data Definition Language: Create and Change the Database Ray Lockwood

Where Are We? Next Few Lectures. Integrity Constraints Motivation. Constraints in E/R Diagrams. Keys in E/R Diagrams

Create a simple database with MySQL

DATABASES SQL INFOTEK SOLUTIONS TEAM

Informatics 1: Data & Analysis

Relational Database Systems Part 01. Karine Reis Ferreira

Introduction to Database Systems CSE 414

Introduction to Data Management CSE 344

The Relational Model. Chapter 3. Database Management Systems, R. Ramakrishnan and J. Gehrke 1

BIS Database Management Systems.

MIS Database Systems.

Part I: Introduction. Outline. Introduction to Databases & SQL. Motivating Example Flat Files. Relational Databases. Problems with Flat Files

CS 327E Lecture 5. Shirley Cohen. February 8, 2016

CS403- Database Management Systems Solved MCQS From Midterm Papers. CS403- Database Management Systems MIDTERM EXAMINATION - Spring 2010

Database Systems. Bence Molnár

MongoDB and Mysql: Which one is a better fit for me? Room 204-2:20PM-3:10PM

Database Management Systems,

Chapter 3: Introduction to SQL

Instructor: Craig Duckett. Lecture 02: Thursday, March 29 th, 2018 SQL Basics and SELECT, FROM, WHERE

Module 3 MySQL Database. Database Management System

Relational model and basic SQL

DATABASE DESIGN. Fields in database table have a data type. Some of the data types used in database table are explained below.

University College of Southeast Norway. Web Services. with Examples. Hans-Petter Halvorsen,

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

Transcription:

Database Quiz with Explainations Hans-Petter Halvorsen, M.Sc.

Questions 1. What is a Database? 2. Give Examples of Systems that use a Database 3. What is DBMS? 4. Give Examples of DBMS systems? 5. We have 2 different types of Databases. Give also some Examples in each Category 6. What is an ER diagram? 7. Give examples of Database Design Tools? 8. Give Examples of Database Best practice 9. We have 4 different types of SQL Queries. Give also an example in each Category 10. What is a View, Stored Procedure and a Trigger?

What is a Database?

Old fashion Database (Data-storage) Systems Not too long ago, this was the only data-storage device most companies needed. Those days are over.

Database Systems A database is an organized collection of data. A Database is a structured way to store lots of information. The information is stored in different tables. Everything today is stored in databases!

Give Examples of Systems that use a Database

Database Examples Bank/Account systems Information in Web pages such as Facebook, Wikipedia, YouTube, etc. Fronter, TimeEdit, etc. lots of other examples!

What is DBMS?

Database Management Systems (DBMS) A database management system (DBMS) is system software for creating and managing databases. The DBMS provides users and programmers with a systematic way to create, retrieve, update and manage data. A DBMS makes it possible for end users to create, read, update and delete data in a database. The DBMS essentially serves as an interface between the database and end users or application programs, ensuring that data is consistently organized and remains easily accessible. http://searchsqlserver.techtarget.com/definition/database-management-system

Database Management Systems (DBMS) The DBMS manages three important things: the data, the database engine that allows data to be accessed, locked and modified and the database schema, which defines the database s logical structure.

Give Examples of DBMS systems?

Database Management Systems (DBMS) Microsoft SQL Server Enterprise, Developer versions, etc. (Professional use) Express version is free of charge Oracle MySQL (owned by Oracle, but previously owned by Sun Microsystems) - MySQL can be used free of charge (open source license), Web sites that use MySQL: YouTube, Wikipedia, Facebook Microsoft Access IBM DB2 Sybase MariaDB MongoDB etc.

We have 2 different types of Databases Which? Give also some Examples in each Category

Database Types Relation Database/SQL Databases Microsft SQL Server Oracle MySQL MariaDB etc. NoSQL Databases MongoDB etc.

What is an ER diagram?

Database Design ER Diagram ER Diagram (Entity-Relationship Diagram) Used for Design and Modeling of Databases. Specify Tables and relationship between them (Primary Keys and Foreign Keys) Example: Table Name Table Name Primary Key Primary Key Foreign Key Column Names Relational Database. In a relational database all the tables have one or more relation with each other using Primary Keys (PK) and Foreign Keys (FK). Note! You can only have one PK in a table, but you may have several FK s.

Table Name ER Diagram Example - Visio Primary Key (PK) Foreign Key (FK)

Give examples of Database Design Tools?

Database Design Tools Visio PowerDesigner CA ERwin CA ERwin Data Modeler Community Edition Community Edition is Free, 25 objects limit Support for Oracle, SQL Server, MySQL, ODBC, Sybase Toad Data Modeler A Simple designer is also included with SQL Server (physical model, not logical model)

Give Examples of Database Best practice

Database - Best Practice Tables: Use upper case and singular form in table names not plural, e.g., STUDENT (not students) Columns: Use Pascal notation, e.g., StudentId Primary Key: If the table name is COURSE, name the Primary Key column CourseId, etc. Always use Integer and Identity(1,1) for Primary Keys. Use UNIQUE constraint for other columns that needs to be unique, e.g. RoomNumber Specify Required Columns (NOT NULL) i.e., which columns that need to have data or not Standardize on few/these Data Types: int, float, varchar(x), datetime, bit Use English for table and column names Avoid abbreviations! (Use RoomNumber not RoomNo, RoomNr,...)

We have 4 different types of SQL Queries. Give also an example in each Category

SQL Structured Query language A Database Computer Language designed for Managing Data in Relational Database Management Systems (RDBMS) Query Examples: insert into STUDENT (Name, Number, SchoolId) values ('John Smith', '100005', 1) select SchoolId, Name from SCHOOL select * from SCHOOL where SchoolId > 100 update STUDENT set Name='John Wayne' where StudentId=2 delete from STUDENT where SchoolId=3 We have 4 different Query Types (CRUD): INSERT, SELECT, UPDATE anddelete CRUD Create (Insert), Read (Select), Update and Delete

What is a View, Stored Procedure and a Trigger?

A View is a virtual table that can contain data from multiple tables A Stored Procedure is like Method in C# - it is a piece of code with SQL commands that do a specific task and you reuse it A Trigger is executed when you insert, update or delete data in a Table specified in the Trigger.

Create View: IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CourseData' AND type = 'V') DROP VIEW CourseData GO Creating Views using SQL A View is a virtual table that can contain data from multiple tables The Name of the View CREATE VIEW CourseData AS SELECT SCHOOL.SchoolId, SCHOOL.SchoolName, COURSE.CourseId, COURSE.CourseName, COURSE.Description FROM SCHOOL INNER JOIN COURSE ON SCHOOL.SchoolId = COURSE.SchoolId GO Using the View: select * from CourseData Inside the View you join the different tables together using the JOIN operator You can Use the View as an ordinary table in Queries : 27

Create Stored Procedure: IF EXISTS (SELECT name FROM sysobjects WHERE name = 'StudentGrade' AND type = 'P') DROP PROCEDURE StudentGrade OG CREATE PROCEDURE StudentGrade @Student varchar(50), @Course varchar(10), @Grade varchar(1) AS Stored Procedure A Stored Procedure is like Method in C# - it is a piece of code with SQL commands that do a specific task and you reuse it Procedure Name Input Arguments DECLARE @StudentId int, @CourseId int select StudentId from STUDENT where StudentName = @Student Internal/Local Variables Note! Each variable starts with @ select CourseId from COURSE where CourseName = @Course insert into GRADE (StudentId, CourseId, Grade) values (@StudentId, @CourseId, @Grade) GO Using the Stored Procedure: execute StudentGrade 'John Wayne', 'SCE2006', 'B' SQL Code (the body of the Stored Procedure)

IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CalcAvgGrade' AND type = 'TR') DROP TRIGGER CalgAvgGrade GO CREATE TRIGGER CalcAvgGrade ON GRADE FOR UPDATE, INSERT, DELETE AS DECLARE @StudentId int, @AvgGrade float select @StudentId = StudentId from INSERTED Trigger A Trigger is executed when you insert, update or delete data in a Table specified in the Trigger. Create the Trigger: select @AvgGrade = AVG(Grade) from GRADE where StudentId = @StudentId update STUDENT set TotalGrade = @AvgGrade where StudentId = @StudentId GO Name of the Trigger Specify which Table the Trigger shall work on Specify what kind of operations the Trigger shall act on Internal/Local Variables Inside the Trigger you can use ordinary SQL statements, create variables, etc. Note! INSERTED is a temporarily table containing the latest inserted data, and it is very handy to use inside a trigger SQL Code (The body of the Trigger)

References Software Development - A Practical Approach Halvorsen, Hans-Petter, 2015 Essentials of Software Engineering Frank Tsui; Orlando Karam; Barbara Bernal, 3 ed., Jones & Bartlett Learning Software Engineering I. Sommerville, 10 ed.: Pearson, 2015 Software Engineering. Modern Approaches E. J. Braude and M. E.Bernstein, 2 ed.: Wiley, 2011.

Hans-Petter Halvorsen, M.Sc. University College of Southeast Norway www.usn.no E-mail: hans.p.halvorsen@hit.no Blog: http://home.hit.no/~hansha/