Successfully reported this slideshow.

Topic 07 : SQL

1,498 views

Published on

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

Topic 07 : SQL

  1. 1. SQL Er. Pradip Kharbuja
  2. 2. SQL • Structured Query Language • SQL is a special-purpose programming language designed for managing data held in a Database Management System (DBMS). • Types of SQL Statements 1. Data Manipulation Language (DML) 2. Data Definition Language (DDL) 3. Data Control Language (DCL)
  3. 3. DML • • • • DML is used for inserting, deleting and updating data in a database DML is also used to retrieve and manipulate data in a database DML modifies stored data not the database definition or database objects. DML Statements are : 1. SELECT 2. INSERT 3. UPDATE 4. DELETE 5. COMMIT 6. ROLLBACK
  4. 4. DDL • defines and controls the database structure • can add, change, or delete definitions of tables, fields and their data types • DDL Statements are : 1. CREATE 2. ALTER • table, database, index 3. DROP
  5. 5. DCL • used to control access to data stored in a database. • DCL Statements 1. GRANT - to allow specified users to perform specified tasks like SELECT, INSERT, DELETE, CREATE, UPDATE, etc. 2. REVOKE - to cancel previously granted or denied permissions.
  6. 6. History of SQL • Developed from IBM’s SYSTEM R • It was developed as the standard database language by 1970s. • First standard published in 1987 by ISO based on work by ANSI ISO - International Standards Organisation ANSI – American National Standards Institute
  7. 7. History of SQL [Contd.] • Before 1987, SQL was developed by different vendors • Addition minor revisions in 1989 • SQL: 1992 – Major revision ‘inSQL-92’  Introduced new data types like VARCHAR and new operators like UNION, JOIN and NATURAL JOIN • SQL: 1999 - with object-relational features
  8. 8. History of SQL [Contd.] • SQL: 2003 - introduced concept of ‘core SQL’  every implementation of core SQL gammar must meet.  main aim was to overcome the divergence in the language • SQL: 2006 – SQL to be used with XML • SQL: 2008 Minor revisions.
  9. 9. Data Manipulation Language : DML • For retrieving and updating data • SELECT – retrieving • INSERT, UPDATE, DELETE – updating Difference between INSERT and UPDATE?
  10. 10. Literals • INSERT INTO workers (emp_no, first_name, last_name) VALUES (1, 'Ram', 'Shrestha'); • Non-numeric in single quotes • Numeric NOT in quotes
  11. 11. Database Update • Insert • Update • Delete
  12. 12. INSERT • INSERT INTO workers (emp_no, first_name, last_name) VALUES (1, 'Ram', 'Shrestha'); • INSERT INTO workers VALUES (1, 'Ram', 'Shrestha'); • INSERT INTO workers (first_name, last_name) VALUES ('Lawerence', 'Smith');
  13. 13. UPDATE • UPDATE workers SET first_name = 'Emily'; • UPDATE workers SET first_name = 'Emily' WHERE last_name = 'Smith'; • UPDATE workers SET first_name = 'Emily' WHERE emp_no = 3;
  14. 14. DELETE • DELETE FROM workers; • DELETE FROM workers WHERE first_name = 'Lawerence'; • DELETE FROM workers WHERE emp_no = 4;
  15. 15. Datatype • When we create a table or add a field to a table we specify the datatype. • Datatype is a classification that identifies the possible values for the field and operations that can be done on the data. • Datatype is also the way the data in that field is stored in the database.
  16. 16. Datatypes • Datatypes are much affected by different ‘flavours’ of SQL. 1. String 2. Number 3. Date
  17. 17. String Datatypes 1. 2. 3. 4. 5. CHAR - Fixed width character string. Maximum 8,000 characters VARCHAR - Variable width character string. Maximum 8,000 characters TEXT - Variable width character string. Maximum 2GB of text data NCHAR - Fixed width Unicode string. Maximum 4,000 characters NVARCHAR - Variable width Unicode string. Maximum 4,000 characters
  18. 18. Char vs Varchar • Suppose 2 fields : one char 5 length another varchar 5 length • How these two will store 'Ram'? • In CHAR, Ram__ • In VARCHAR, Ram
  19. 19. Numeric Datatypes • Integer, e.g. 8 • Numeric or Decimal, e.g. 8.23 with point set • Float or Real, e.g. 8.23 but could also be changed so that point moves when needed
  20. 20. Datetime Types • Date - System defined date • Time – System defind time • Timestamp – Dates and times including fractions of a second • Interval – Intervals between dates
  21. 21. Advantages of SQL • Universal • Easy to use • Fits (more or less) with relational model
  22. 22. Disadvantages of SQL • Does not support all features of relational model • No one standard and the different flavours in SQL • Has had to be extended • Much redundancy – possible to do the same thing many ways
  23. 23. Any Questions ??? SQL

×