Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Database Lei Yang Computer Science Department.

Similar presentations


Presentation on theme: "Introduction to Database Lei Yang Computer Science Department."— Presentation transcript:

1 Introduction to Database Lei Yang Computer Science Department

2 Why we use database? You have a company with more than 10000 employees… Someday, you want to find out ◦ The average salary of employees who own Ph.d degree… ◦ The average age of your company… ◦…◦…

3 Manage Employees in the Company Employee Information ◦ Name: Jack, Ram… ◦ Gender: Male, Female ◦ Degree: Bachelor, Master, Ph.d… ◦ Department: HR, Market Department… ◦ Job: Engineer, Salesman, … ◦ Salary: 10k, 15k, … ◦ Manager: Jason, … ◦ …

4 Table Database Store Data in Tables Employee IDNameGenderDegreeSalary 001JamesMalePh.D15k 002LinaFemaleMS10k 003BogdanMaleMS12k 004MaryFemalePh.D14k ROW: a record COLUMN A field or an attribute NUMBER TextCurrency Question: how to distinguish two employee with nearly the same information?

5 Primary Key Employee IDNameGenderDegreeSalary 001JamesMalePh.D15k 002JamesMalePh.D15k Primary Key Unique

6 Data Type - 1 Text ◦ Stores text, numbers, or a combination of both, up to 255 characters long. Text fields are the most common of all data types. Memo ◦ Stores long text entries up to 64,000 characters long. Number: int, float… Date/Time ◦ Stores dates, times, or both. Currency ◦ Stores numbers and symbols that represent money.

7 Data Type - 2 AutoNumber ◦ Automatically fills in a unique number for each record. AutoNumber is used as primary key in many tables. Yes/No ◦ Stores only one of two values, such as Yes or No, True or False, etc. OLE Object ◦ Stores objects created in other programs such as a graphic, Excel spreadsheet, or Word document. Hyperlink ◦ Stores clickable links to files on your computer, on the network, or to Web pages on the Internet.

8 Data Type - 3 Lookup Wizard ◦ A wizard that helps you create a field whose values are selected from a table, query, or a preset list of values.

9 Query Answer in Database-1 Query: Find out the names of all employees whose salary is greater than 12k? Employee IDNameGenderDegreeSalary 001JamesMalePh.D15k 002LinaFemaleMS10k 003BogdanMaleMS12k 004MaryFemalePh.D14k

10 Query in Database-2 Employee IDNameGenderDegreeSalary 001JamesMalePh.D15k 002LinaFemaleMS10k 003BogdanMaleMS12k 004MaryFemalePh.D14k SELECTIONPROJECTION James, Mary

11 Query in Database-3 SELECTION ◦ Selecting records which satisfies certain conditions Projection ◦ Projecting a field into query simply means including it in the query

12 Query in Database-4 SQL(Structured Query Language) ◦ Used in Database ◦ A simple structure  SELECT  FROM  WHERE

13 Query in Database-4 Query: Find out the names of all employees whose salary is greater than 12k?  SELECT  FROM  WHERE Name Employee Salary > 12k PROJECTION SELECTION SELECTION: Selecting records which satisfies certain conditions. PROJECTION: Projecting a field into query simply means including it in the query

14 Query in Database-5 How to search in two tables? Employee IDNameDptID 001JimyD004 002KarlD005 DptIDDptName D004HR D005IT Find out the name of employees in HR?

15 Query in Database-6 Cartesian Product Employee ID NameDptID 001JimyD004 002KarlD005 DptIDDptName D004HR D005IT X = Employee ID NameDptID DptName 001JimyD004 HR 001JimyD004D005IT 002KarlD005D004HR 002KarlD005 IT Employee Department

16 Query in Database-7 SELECT FROM WHERE <DepartmentName = “HR” and  Employee.DptID = Department.DptID> Employee ID NameDptID Department Name 001JimyD004 HR 001JimyD004D005IT 002KarlD005D004HR 002KarlD005 IT JOIN Cartesian Product

17 Query in Database-8 Operators in conditions OperatorExampleDescription == “Apple”Finds records equal to Apple. << 10Finds records less than 10. <=<= 10Finds records less than or equal to 10. >> 10Finds records greater than 10. >=Finds records greater than or equal to 10. LIKELike “test*”Finds text beginning with the word “test." You can use LIKE with wildcards such as *.

18 Query in Database-9 Aggregate Function Employee IDNameDptID 001JimyD004 002KarlD005 003LauraD004 005RamD004 006JamesD005 How many employees are there in department D004?

19 Query in Database-10  SELECT count(EmployeeID)  FROM  HAVING DptID = “D004” Employee IDNameDptID 001JimyD004 002KarlD005 003LauraD004 005RamD004 006JamesD005 Aggregate Function

20 Query in Database-11 Aggregate Functions FunctionDescription Group ByGroups the values in the field so that you can perform calculations on the groups SumCalculates the total (sum) of values in a field. AvgCalculates the average of values in a field. CountCounts the number of entries in a field, not including blank (Null) records. MaxFinds the highest value in a field. ……

21 Question


Download ppt "Introduction to Database Lei Yang Computer Science Department."

Similar presentations


Ads by Google