Presentation is loading. Please wait.

Presentation is loading. Please wait.

الفصل السادس لغة Structured Query Language) SQL الفصل السادس لغة Structured Query Language) SQL.

Similar presentations


Presentation on theme: "الفصل السادس لغة Structured Query Language) SQL الفصل السادس لغة Structured Query Language) SQL."— Presentation transcript:

1 الفصل السادس لغة Structured Query Language) SQL الفصل السادس لغة Structured Query Language) SQL

2 CSC 1203 - Dr. Yousry Taha2 Introduction SQL (Structured Query Language) is one of the major reasons for the success of RDB. SQL (Structured Query Language) is one of the major reasons for the success of RDB. It is a standard language for RDB. It is a standard language for RDB. It enables the migration among RDBMS easily. It enables the migration among RDBMS easily. It became a standard for most of the commercial RDBMSs. It became a standard for most of the commercial RDBMSs. SQL provides a high level declarative language enables the users to only specify what he needs and leaving the details to the system. SQL provides a high level declarative language enables the users to only specify what he needs and leaving the details to the system.

3 CSC 1203 - Dr. Yousry Taha3 DDL and Constraints 2. Create Table: Create Table Student( ID Integer, Name Varchar(30), Grade1 Integer, Grade2 Integer, Grade3 Integer, Total Integer, Primary Key (ID));

4 CSC 1203 - Dr. Yousry Taha4 DDL – Constraints (cont) Data types: Data types: »Numeric: Integer – Long – Byte – Single – Double - Decimal »String: CHAR - CHAR(n) - VARCHAR(n) »Date and time: DATE - TIME NOT NULL option: NOT NULL option: NameVarchar(30) NOT NULL,

5 CSC 1203 - Dr. Yousry Taha5 DDL (continued) DROP TABLE Student; DROP TABLE Student; (Remove Student from the database) DROP TABLE Student CASCADE; DROP TABLE Student CASCADE; (Remove Student and any related tables) ALTER TABLE Student ADD Dept VARCHAR(15); ALTER TABLE Student ADD Dept VARCHAR(15); (Add new field Dept to student table) ALTER TABLE Student DROP Grade3 CASCADE; ALTER TABLE Student DROP Grade3 CASCADE; (Remove field Grade3 from student table)

6 CSC 1203 - Dr. Yousry Taha6 Insert, Delete and Update in SQL InsertExamples: INSERT INTO Student VALUES INSERT INTO Student VALUES (12345, "Ahmed Saad", 50, 60, 70, 0, Null); Note: The values of the attributes in the insert command must satisfy all constraints. Delete 1.DELETE FROMStudent WHEREID = 12345; 2.DELETE FROMStudent; (Delete all tuples of Student)

7 CSC 1203 - Dr. Yousry Taha7 Insert, Delete and Update in SQL (cont) Update 1.UPDATEStudent SETtotal = Grade1 + Grade2 + Grade3 WHEREID = 12345; 2.UPATE Student SETGrade1 = Grade1 * 1.1 WHEREGrade1 < 70;

8 CSC 1203 - Dr. Yousry Taha8 Basic Queries in SQL Select-From-Where structure SELECT SELECT FROM FROM WHERE ; Example: Example: Retrieve the student ID and Total for Ahmed Saad. SELECTID,Total FROMStudent WHERENAME= ‘Ahmed Saad’;

9 CSC 1203 - Dr. Yousry Taha9 SQL commands (cont) Unspecified WHERE and use of (*) 1.SELECTID FROMStudent; 2.SELECT* FROMStudent WHEREGrade1 < 60;


Download ppt "الفصل السادس لغة Structured Query Language) SQL الفصل السادس لغة Structured Query Language) SQL."

Similar presentations


Ads by Google