Presentation is loading. Please wait.

Presentation is loading. Please wait.

Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.

Similar presentations


Presentation on theme: "Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total."— Presentation transcript:

1 Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total Sessional Terminal Exam Final Evaluation 10 52550 100 By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 1 Remember:

2 Chapter NoChapter NamePage No 1. Database Foundation OR An Overview of Database Management System (DBMS) 2.Semantic Modeling OR Entity Relationship Model (ERD) 3.An introduction to Relational Database 4.Normalization 5.Relational Algebra 6.An Introduction to Structured Query Language (SQL) By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 2 Course Contents

3 COURSE INSTRUCTOR: ILTAF MEHDI By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 3 Chapter No: 06

4 1. SQL Introduction SQL Intro 2. SQL Syntax SQL Syntax 3. SQL Select SQL Select 4. SQL Distinct SQL Distinct 5. SQL Where SQL Where 6. SQL And & Or SQL And & Or 7. SQL Order By SQL Order By 8. SQL Insert SQL Insert 9. SQL Update SQL Update 10. SQL Delete SQL Delete 1. SQL Introduction SQL Intro 2. SQL Syntax SQL Syntax 3. SQL Select SQL Select 4. SQL Distinct SQL Distinct 5. SQL Where SQL Where 6. SQL And & Or SQL And & Or 7. SQL Order By SQL Order By 8. SQL Insert SQL Insert 9. SQL Update SQL Update 10. SQL Delete SQL Delete By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 4

5 What is SQL?  SQL is a standard language for accessing and manipulating databases.  SQL stands for Structured Query Language  SQL lets you access and manipulate databases  SQL is an ANSI (American National Standards Institute) standard By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 5

6 6

7 7

8 8

9 Using SQL in Your Web Site  To build a web site that shows some data from a database, you will need the following: 1. An RDBMS database program (i.e. MS Access, SQL Server, MySQL) 2. A server-side scripting language, like PHP or ASP, ASP.NET 3. SQL 4. HTML / CSS / java Script Using SQL in Your Web Site  To build a web site that shows some data from a database, you will need the following: 1. An RDBMS database program (i.e. MS Access, SQL Server, MySQL) 2. A server-side scripting language, like PHP or ASP, ASP.NET 3. SQL 4. HTML / CSS / java Script By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 9

10 RDBMS  RDBMS stands for Relational Database Management System.  RDBMS is the basis for SQL, and for all modern database systems like MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access.  The data in RDBMS is stored in database objects called tables.  A table is a collections of related data entries and it consists of columns and rows. RDBMS  RDBMS stands for Relational Database Management System.  RDBMS is the basis for SQL, and for all modern database systems like MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access.  The data in RDBMS is stored in database objects called tables.  A table is a collections of related data entries and it consists of columns and rows. By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 10

11 By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 11

12 Semicolon after SQL Statements?  Some database systems require a semicolon at the end of each SQL statement.  Semicolon is the standard way to separate each SQL statement in database systems that allow more than one SQL statement to be executed in the same call to the server.  We are using MS Access and SQL Server 2000 and we do not have to put a semicolon after each SQL statement, but some database programs force you to use it. By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 12

13 SQL DML and DDL  SQL can be divided into two parts: 1. The Data Manipulation Language (DML) and 2. the Data Definition Language (DDL). The query and update commands form the DML part of SQL:  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 SQL DML and DDL  SQL can be divided into two parts: 1. The Data Manipulation Language (DML) and 2. the Data Definition Language (DDL). The query and update commands form the DML part of SQL:  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 By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 13

14  The DDL part of SQL permits database tables to be created or deleted. It also define indexes (keys), specify links between tables, and impose constraints between tables. The most important DDL statements in SQL are:  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  The DDL part of SQL permits database tables to be created or deleted. It also define indexes (keys), specify links between tables, and impose constraints between tables. The most important DDL statements in SQL are:  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 By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 14

15 By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 15

16 By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 16

17 By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 17

18 By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 18

19  SELECT * FROM Student WHERE FirstName=‘Ajmal’ OR FirstName=‘Hamid’ Combining AND & OR  You can also combine AND and OR (use parenthesis to form complex expressions).  Now we want to select only the Student with the last name equal to “Ullah" AND the first name equal to “Ajmal" OR to “Hamid": We use the following SELECT statement:  SELECT * FROM Student WHERE LastName=‘Ullah' AND (FirstName=‘Ajmal’ OR FirstName=‘Hamid')  SELECT * FROM Student WHERE FirstName=‘Ajmal’ OR FirstName=‘Hamid’ Combining AND & OR  You can also combine AND and OR (use parenthesis to form complex expressions).  Now we want to select only the Student with the last name equal to “Ullah" AND the first name equal to “Ajmal" OR to “Hamid": We use the following SELECT statement:  SELECT * FROM Student WHERE LastName=‘Ullah' AND (FirstName=‘Ajmal’ OR FirstName=‘Hamid') By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 19

20  The ORDER BY keyword is used to sort the result-set by a specified column.  The ORDER BY keyword sort the records in ascending order by default.  If you want to sort the records in a descending order, you can use the DESC keyword. SQL ORDER BY Syntax  SELECT column_name(s) FROM table_name ORDER BY column_name(s) ASC|DESC By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 20

21  The INSERT INTO statement is used to insert a new row in a table. SQL INSERT INTO Syntax  It is possible to write the INSERT INTO statement in two forms. The first form doesn't specify the column names where the data will be inserted, only their values:  INSERT INTO table_name VALUES (value1, value2, value3,...) The second form specifies both the column names and the values to be inserted:  INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...) By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 21

22 Insert Data Only in Specified Columns  It is also possible to only add data in specific columns. The following SQL statement will add a new row, but only add data in the "P_Id", "LastName" and the "FirstName" columns:  INSERT INTO Student (P_Id, LastName, FirstName) VALUES (5, ‘Shahid’, ‘Afridi’) By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 22

23  The UPDATE statement is used to update existing records in a table. SQL UPDATE Syntax  UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value  Note: Notice the WHERE clause in the UPDATE syntax. The WHERE clause specifies which record or records that should be updated. If you omit the WHERE clause, all records will be updated! By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 23

24  The DELETE statement is used to delete rows in a table. SQL DELETE Syntax  DELETE FROM table_name WHERE some_column=some_value Note: Notice the WHERE clause in the DELETE syntax. The WHERE clause specifies which record or records that should be deleted. If you omit the WHERE clause, all records will be deleted! By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 24

25  The PRIMARY KEY constraint uniquely identifies each record in a database table.  Primary Keys must contain unique values.  A primary key column cannot contain NULL values.  Each table should have a primary key, and each table can have only ONE primary key. By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 25

26  The following SQL creates a PRIMARY KEY on the "P_Id" column when the "Persons" table is created: SQL Server / Oracle / MS Access:  CREATE TABLE Student ( P_Id int NOT NULL PRIMARY KEY, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255) ) By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 26

27  To allow naming of a PRIMARY KEY constraint, and for defining a PRIMARY KEY constraint on multiple columns, use the following SQL syntax for :  MySQL / SQL Server / Oracle / MS Access: CREATE TABLE Students ( st_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255), CONSTRAINT pk_PersonID PRIMARY KEY (st_Id, LastName) ) By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 27

28  To drop a PRIMARY KEY constraint, use the following SQL: MySQL:  ALTER TABLE Persons DROP PRIMARY KEY SQL Server / Oracle / MS Access:  ALTER TABLE Persons DROP CONSTRAINT pk_PersonID By ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) SQL 28


Download ppt "Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total."

Similar presentations


Ads by Google