Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sundara Ram Matta Apr 01 st, 2015 - Sundara Ram Matta Apr 01 st, 2015

Similar presentations


Presentation on theme: "Sundara Ram Matta Apr 01 st, 2015 - Sundara Ram Matta Apr 01 st, 2015"— Presentation transcript:

1 Sundara Ram Matta sundara.matta@mail.wvu.edu Apr 01 st, 2015 - Sundara Ram Matta sundara.matta@mail.wvu.edu Apr 01 st, 2015 sundara.matta@mail.wvu.edu 1

2 IMPORTANT ANNOUNCEMENTS !!! HW #4 due by this Friday – 4/3/2015 HW #5 has been posted and due date is next Friday – 4/10/2015. Also MyITLab Lesson D – due by Monday 4/6/2015. 2

3 INTRODUCTION SQL is short for Structured Query Language. SQL is pronounced “sequel”. It is a widely used database language, providing means of data manipulation (store, retrieve, update, delete) and database creation. 3

4 INTRODUCTION Almost all modern RDMS use SQL as standard database language. – MS SQL Server – Microsoft Access – Oracle – Sybase – Informix Although all those RDBMS use SQL, they use different SQL dialects. 4

5 SQL DATABASE TABLE The foundation of every RDMS is a database object called TABLE. The database table columns (called also table fields) have their own unique names and have a pre-defined data types. While table columns describe the data types, the table rows contain the actual data for the columns. 5

6 SQL DATABASE TABLE CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry 1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany 2 Ana Trujillo Emparedados y helados Ana Trujillo Avda. de la Constitución 2222 México D.F.5021Mexico 3 Antonio Moreno Taquería Antonio MorenoMataderos 2312México D.F.5023Mexico 4Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK 5 Berglunds snabbköp Christina BerglundBerguvsvägen 8LuleåS-958 22Sweden 6

7 SQL INSTRUCTIONS Keep in Mind That... SQL is NOT case sensitive: select is the same as SELECT Semicolon after SQL Statements? Semicolon is the standard way to separate each SQL statement in database systesm. 7

8 MOST IMPORTANT SQL COMMANDS SELECT - extracts data from a database UPDATE - updates data in a database DELETE - deletes data from a database INSERT INTO - inserts new data into a database CREATE DATABASE - creates a new database ALTER DATABASE - modifies a database CREATE TABLE - creates a new table ALTER TABLE - modifies a table DROP TABLE - deletes a table CREATE INDEX - creates an index (search key) DROP INDEX - deletes an index 8

9 SQL SELECT STATEMENT The SELECT statement is used to select data from a database. The result is stored in a result table, called the result-set. SELECT column_name,column_name FROM table_name; SELECT * FROM table_name; 9

10 SQL SELECT ‘DISTINCT’ STATEMENT In a table, a column may contain many duplicate values; and sometimes you only want to list the different (distinct) values. The DISTINCT keyword can be used to return only distinct (different) values. SELECT DISTINCT column_name,column_name FROM table_name; 10

11 SQL WHERE CLAUSE The WHERE clause is used to extract only those records that fulfil a specified criterion. SELECT column_name,column_name FROM table_name WHERE column_name operator value; 11

12 SQL WHERE CLAUSE 12 OperatorDescription =Equal <>Not equal. Note: In some versions of SQL this operator may be written as != >Greater than <Less than >=Greater than or equal <=Less than or equal BETWEENBetween an inclusive range LIKESearch for a pattern INTo specify multiple possible values for a column

13 SQL AND & OR OPERATORS The AND & OR operators are used to filter records based on more than one condition. The AND operator displays a record if both the first condition AND the second condition are true. The OR operator displays a record if either the first condition OR the second condition is true. 13

14 SQL UPDATE STATEMENT The UPDATE statement is used to update records in a table. UPDATE table_name SET column1=value1,column2=value2,... WHERE some_column=some_value; 14

15 SQL UPDATE STATEMENT Be careful when updating records. If we had omitted the WHERE clause, in the example above, like this: UPDATE Customers SET ContactName='Alfred Schmidt', City='Hamburg'; Entire ContactName and City Column will get replaced. 15

16 SQL DELETE STATEMENT The DELETE statement is used to delete records in a table. DELETE FROM table_name WHERE some_column=some_value; Notice the WHERE clause in the SQL DELETE statement! Be very careful when deleting records. You cannot undo this statement! 16

17 SQL ORDER BY KEYWORD The ORDER BY keyword is used to sort the result-set by one or more columns. The ORDER BY keyword sorts the records in ascending order by default. SELECT column_name, column_name FROM table_name ORDER BY column_name DESC, column_name DESC; 17

18 SQL ’JOIN’ KEYWORD 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 return all rows when there is at least one match in BOTH the tables. 18

19 NEXT WEEK… Study the Reports – just like forms, Cover Misc. topics and we will wrap up MS - Access. We will have an Exam review session on Wednesday – April 08 th. Exam #2: Comprehensive on MS Access Monday – April 13 th (Section 3). Wednesday – April 15 th (Section 5). 19

20 20 Sundara Ram Matta sundara.matta@mail.wvu.edu Apr 01 st, 2015 - Sundara Ram Matta sundara.matta@mail.wvu.edu Apr 01 st, 2015 sundara.matta@mail.wvu.edu


Download ppt "Sundara Ram Matta Apr 01 st, 2015 - Sundara Ram Matta Apr 01 st, 2015"

Similar presentations


Ads by Google