Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab 13 Databases and SQL.

Similar presentations


Presentation on theme: "Lab 13 Databases and SQL."— Presentation transcript:

1 Lab 13 Databases and SQL

2 Useful information Last lab of the semester .
Next week there will be a lab exam . No assignments for this lab.

3 Databases Data : facts and statistics collected together for reference or analysis Database : A database is a collection of one or more relations, where each relation is a table with rows and columns RDBMS : It contains a set of relations

4 Database Table attributes (or columns) customer_name customer_street
customer_city Jones Smith Curry Lindsay Main North Park Harrison Rye Pittsfield tuples (or rows)

5 RDBMS Relation: made up of 2 parts:
Instance : a table , with rows and columns. #Rows = cardinality, #fields = degree / arity. Schema : specifies name of relation, plus name and type of each column. E.G. Students(sid: string, name: string, login: string, age: integer, gpa: float )

6 SQL –Structured Query Langauage
Developed by IBM (system R) in the 1970s Vendors Oracle MYSQL MS-SQL server IBM DB2

7 SQL –Structured Query Langauage
Activity I : SELECT Tutorial from BBC TABLE Hint: SELECT >>FROM >>WHERE SELECT is the data extraction operator.You can choose the attributes here (columns),’ * ‘ returns all the columns from the table FROM :Table name is defined here. WHERE : It is used to limit the rows according to the condition/s.

8 SQL –Structured Query Langauage
Activity I : SELECT Tutorial from BBC TABLE 2.Relational operators same as c++ =(no double sign here like c++) ,>,<,<=,>=,!= Note :there is no operator like !< .Just use > instead 3.per capita GDP is the GDP divided by the population GDP/population Calculations are usually done in select clause .A new column is created with the calculation .It is a better practice to use an alias for a calculated column . Aliases : Aliases are defined in the from clause, called in select and where clauses . Eg.Select t.id from table as t ( Alternatively used as “from table t” without “as”.Here we create a new column called percaptaGDP using the formula) .

9 SQL –Structured Query Langauage
Activity I : SELECT Tutorial from BBC TABLE 4. SQL aggregate functions returns a single value, calculated from values in a column. Useful aggregate functions: Used on column with quantitative data AVG() - Returns the average value COUNT() - Returns the number of rows ROUND()-Returns after rounding the number MAX() - Returns the largest value MIN() - Returns the smallest value SUM() - Returns the sum

10 SQL –Structured Query Langauage
Activity I : SELECT Tutorial from BBC TABLE 6. The SQL LIKE Operator The LIKE operator is used to search for a specified pattern in a column. SQL LIKE Syntax: SELECT column name(s) FROM table name WHERE column name LIKE pattern; % operator is used inside the like operator. Ex. ‘%United’–Returns strings which ends with with United ‘United%’ -Returns string which starts with United ‘%United%’-Returns string which contains Unitedanywhere in the field.

11 SQL –Structured Query Langauage
Activity I : SELECT Tutorial from BBC TABLE 5.The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE column_name IN (value1,value2,...);

12 SQL –Structured Query Langauage
ActIivity 2:More practice with SELECT: Additional practice of the basic features using a table of Nobel Prize winners.

13 SQL joins An SQL JOIN clause is used to combine rows from two or more tables, based on a common field between them. The most common type of join is: SQL INNER JOIN (simple join). An SQL INNER JOIN returns all rows from multiple tables where the join condition is met.

14 Questions?


Download ppt "Lab 13 Databases and SQL."

Similar presentations


Ads by Google