בסיסי נתונים ושפת SQL הרצאה #4

Slides:



Advertisements
Similar presentations
The Relational Model J.G. Zheng May 15 th Introduction Edgar F. Codd, 1970 One sentence to explain relational database model: Data are organized.
Advertisements

Data Design The futureERD - CardinalityCODINGRelationshipsDefinition.
MySQL-Database Teppo Räisänen Oulu University of Applied Sciences School of Business and Information Management.
ISMT221 Information Systems Analysis and Design Entity-Relationship Diagram Lab 4 Tony Tam.
Mid-term Exam Answer Keys Week 7 Spring I. Multiple Choices Questions Each may have more than one answer (6 x 4 = 24 points total)
1 Introduction to Web Application Introduction to Data Base.
Database – Part 2a Dr. V.T. Raja Oregon State University.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.
DBA Developer. Responsibilities  Designing Relational databases  Developing interface layer Environment Microsoft SQL Server,.NET SQL Layer: Stored.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
DATA MODELING AND DATABASE DESIGN
Creating Databases with MySQL Workbench Build the Forums database in Ullman’s Chapter 6.
Database. Basic Definitions Database: A collection of related data. Database Management System (DBMS): A software package/ system to facilitate the creation.
Databases in Visual Studio. Database in VisualStudio An MS SQL database are built in Visual studio The Name can be something like ”(localdb)\Projects”
Relational Database Management Systems. A set of programs to manage one or more databases Provides means for: Accessing the data Inserting, updating and.
MIS 301 Information Systems in Organizations Dave Salisbury ( )
CSC 2720 Building Web Applications Database and SQL.
1 All Powder Board and Ski SQL Server Workbook Chapter 2: Database Design Jerry Post Copyright © 2004.
Database. Basic Definitions Database: A collection of related data. Database Management System (DBMS): A software package/ system to facilitate the creation.
The Relational Model J.G. Zheng Jan 2010 CIS 8040 Database Management Systems.
Database Management COP4540, SCS, FIU Database Modeling Using the Entity-Relationship Model (Continued)
What’s a database? Data stored in a structured format that lends itself to easy manipulation and recall.
WIBR Bioinformatics, © Whitehead Institute, 2004 Relational Databases for Biologists Robert Latek, Ph.D. Sr. Bioinformatics Scientist Whitehead Institute.
Module Review Basic SQL commands: Create Database, Create Table, Insert and Select 2. Connect an SQL Database to PHP 3. Execute SQL Commands in.
CpSc 462/662: Database Management Systems (DBMS) (TEXNH Approach) Relational Schema and SQL Queries James Wang.
1 MySQL and SQL. 2 Topics  Introducing Relational Databases  Terminology  Managing Databases MySQL and SQL.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
DATA MODELING AND DATABASE DESIGN DATA MODELING AND DATABASE DESIGN Part 2.
Standards and Conventions
CCT395, Week 6 Implementing a Database with SQL and a Case Study Exercise This presentation is licensed under Creative Commons Attribution License, v.
Standard language for querying and manipulating data Structured Query Language Many standards out there: ANSI SQL, SQL92 (a.k.a. SQL2), SQL99 (a.k.a. SQL3),
Getting started with Accurately Storing Data
Order Database – ER Diagram
Web Systems & Technologies
From: SQL From:
Chapter 5 Introduction to SQL.
CS320 Web and Internet Programming SQL and MySQL
MySQL-Database Jouni Juntunen Oulu University of Applied Sciences
Chapter 9 Part-1: Concepts & Foreign Keys
Introduction to Databases
Tables and Their Characteristics
CSIS 115 Database Design and Applications for Business
Order Database – ER Diagram
Order Database – ER Diagram
قاعدة البيانات Database
SQL FUNDAMENTALS CDSE Days 2018.
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Relational Model and ER Model: in a Nutshell
Order Database – ER Diagram
قاعدة البيانات Database
ERD’s REVIEW DBS201.
מודל הנתונים.
Entity relationship diagrams
Entity Relationship Diagrams ERDs
Chapter 9 Part-1: Concepts & Foreign Keys
PHP and MySQL.
Database Processing: David M. Kroenke’s Chapter Six:
בסיסי נתונים - מצגת ההרצאה - 1.
DATABASE SQL= Structure Query Language مبادئ قواعد بيانات
Order Database – ER Diagram
CS3220 Web and Internet Programming SQL and MySQL
DBMS ER-Relational Mapping
Database Processing: David M. Kroenke’s Chapter Six:
CS3220 Web and Internet Programming SQL and MySQL
Instructor: Samia arshad
Instructor Information: Mark Jamil
Database Processing: David M. Kroenke’s Chapter Six:
កម្មវិធីបង្រៀន SQL Programming ជាភាសាខ្មែរ Online SQL Training Course
SQL AUTO INCREMENT Field
Presentation transcript:

בסיסי נתונים ושפת SQL הרצאה #4 אורן דבוסקין telhaidb@cielago.com

מפגש #4 חזרה משיעור קודם – פקודת Select המשך - פקודת SQL select המודל הטבלאי תרגול ב SQL Server

דרישת שלום מ Contador

ומסלול הרכיבה

שאילתת SQL - מבנה בסיסי פקודת ה - SELECT : שאילתה לשליפת מידע מטבלה FROM [ טבלאות ] WHERE [ תנאי ] [ אפשרויות נוספות : order by, group by, having… ]

בחירת עמודות SELECT [distinct] [ * | columns [alias] ] FROM [ טבלאות ] WHERE [ תנאי ] [ אפשרויות נוספות : order by, group by, having… ] distinct רשימת פריטים ייחודיים * בחירת כל העמודות alias שינוי שם העמודה

תנאי SELECT [ עמודות ] FROM [ טבלאות ] WHERE [ תנאי ] [ אפשרויות נוספות : order by, group by, having… ] תנאי לוגי כבכל שפת תכנות. מילים מיוחדות : not, between, or, and, is null, is not null, like, in השוואות: <>, >, < , >=, <= פונקציות , לדוגמא: now()

פונקציות סקלר - דוגמא SELECT [ עמודות ] FROM [ טבלאות ] WHERE upper(city) = ‘TEL-AVIV’

פונקציות קבוצה - דוגמא SELECT count(*) FROM [ טבלאות ] WHERE upper(city) = ‘TEL-AVIV’

סקירת פונקציות עזרה של MS-SQL. W3Schools: http://www.w3schools.com/sql/sql_functions.asp בעברית: http://webmaster.org.il/articles/sql-system-functions

מיון SELECT [ עמודות ] FROM [ עמודות ] WHERE [ תנאי ] ORDER BY [ columns [asc|desc] ] מיון לפי עמודות בסדר עולה, יורד ברירת מחדל : מיון בסדר עולה

מיון - דוגמא SELECT [ עמודות ] FROM [ עמודות ] WHERE [ תנאי ] ORDER BY last_name desc, first_name

Aggregation SELECT [ עמודות ] FROM [ עמודות ] WHERE [ תנאי ] GROUP BY [ columns ] קיבוץ נתונים לפי עמודות

Aggregation - דוגמא SELECT [ עמודות ] FROM [ עמודות ] WHERE [ תנאי ] GROUP BY city

Aggregation SELECT [ עמודות ] FROM [ עמודות ] WHERE [ תנאי ] GROUP BY [ columns ] HAVING [ condition ] הפעלת תנאי על הקבוצה

Aggregation - דוגמא SELECT [ עמודות ] FROM [ עמודות ] WHERE [ תנאי ] GROUP BY city HAVING count(*) > 1

הכל ביחד SELECT * FROM users WHERE birthdate between ‘1/1/1973’ and ‘1/1/1983’ ORDER BY birthdate DESC

שלבים בעיצוב בסיס נתונים בניית המבנה התפישתי: הייצוג הלוגי של בסיס הנתונים. לרוב באמצעות תרשים. בניית המבנה הלוגי: תרגום המבנה הלוגי להגדרות עבור סכמת DBMS. המבנה הפיזי: פריסת הטבלאות, אופן שמירת בסיס הנתונים.

המודל התפישתי תאור הישויות/אובייקטים בבסיס הנתונים תאור הקשרים בין האובייקטים מתואר בתרשים ERD : Entity Relationship Diagram תרשים ישויות קשרים

ישות Entity אובייקט במודל שקיים במציאות, והוא בעל משמעות (טבלה) לדוגמא: סטודנט, ציונים, מרצים, כיתות לימוד ישות חזקה / חלשה: ישות עם קיום עצמאי / בעלת תלות בישות אחרת. מופע Instance: פריט מידע בישות (שורה בטבלה).

תכונה Attribute מאפיין של הישות (שדה בטבלה). כל תכונה מוגדרת על ידי: טיפוס נתונים Datatype: סוג הנתון (מספר, תאריך, מחרוזת וכו') מרחב ערכים Domain: מרחב ערכים חוקיים לתכונה (טווח מספרים, האם חובה?) ערך Value: פריט המידע הקיים בתכונה ברגע נתון.

מפתח Key מזהה עבור הישות: תכונה אחת או יותר המהווה זיהוי חד-ערכי למופע ביישות. מפתח ראשי Primary Key: קבוצת התכונות המהוות זיהוי חד-ערכי למופע בישות. מפתח זר/חיצוני Foreign key: תכונה/קבוצת תכונות בישות המהווה מפתח ראשי לישות אחרת.

תאור בתרשים Entity Name Attribute (PK) Attribute …

תרשים - דוגמא users user_id user_name birthday hometown …

קשרים Relationship יחס בעל משמעות בין ישויות שונות. פונקציית / קרדינליות הקשר: דרגת היחס בין הישויות 1:1 קשר חד-חד ערכי (אחד לאחד) 1:N קשר חד-רב ערכי (אחד לרבים) M:N קשר רב-רב ערכי (רבים לרבים)

קשרים - דוגמאות טבלת עובדים – פרטי חשבון טבלת מחלקות – עובדים טבלת עובדים – פרוייקטים דוגמאות נוספות...

תרשים ERD 1:1 1:N N:M

מפתחות ראשיים/זרים? 1:1 1:N N:M האם יש לנו ישות ללא מפתח ראשי?

SQL Web Admin ממשק ניהול Web עבור SQL-Server TOAD: כלי נוספים: http://sqlwebadmin.codeplex.com TOAD: http://www.quest.com/toad-for-sql-server/ כלי נוספים: http://www.sqlmaestro.com/products/mssql http://www.mylittleadmin.com/zip/mla_sql_3.7.zip

שאילתות על טבלאות משתמשים יצירת קשרים טבלאות פייסבוק: תרגיל כיתה שאילתות על טבלאות משתמשים יצירת קשרים טבלאות פייסבוק: https://developers.facebook.com/docs/reference/fql/

טבלת החברים uid bigint NOT NULL display_name varchar(50) NULL Type Allow null? uid bigint NOT NULL display_name varchar(50) NULL alternate_name username password email birthdate date gender interested_in relationship picture_link friends_count int שם טבלה: user

דגשים – תרגילי בית דרישת קדם למבחן מסכם: הגשה של 50% מהתרגילים סימולציית ציונים בקורס:

שיעור הבא המשך המודל התפישתי. המודל הטבלאי.