• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Topic 07 : SQL
 

Topic 07 : SQL

on

  • 792 views

 

Statistics

Views

Total Views
792
Views on SlideShare
295
Embed Views
497

Actions

Likes
0
Downloads
48
Comments
0

2 Embeds 497

http://www.pradipkharbuja.com.np 496
http://webcache.googleusercontent.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Topic 07 : SQL Topic 07 : SQL Presentation Transcript

    • SQL Er. Pradip Kharbuja
    • 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)
    • 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
    • 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
    • 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.
    • 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
    • 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
    • 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.
    • Data Manipulation Language : DML • For retrieving and updating data • SELECT – retrieving • INSERT, UPDATE, DELETE – updating Difference between INSERT and UPDATE?
    • Literals • INSERT INTO workers (emp_no, first_name, last_name) VALUES (1, 'Ram', 'Shrestha'); • Non-numeric in single quotes • Numeric NOT in quotes
    • Database Update • Insert • Update • Delete
    • 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');
    • 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;
    • DELETE • DELETE FROM workers; • DELETE FROM workers WHERE first_name = 'Lawerence'; • DELETE FROM workers WHERE emp_no = 4;
    • 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.
    • Datatypes • Datatypes are much affected by different ‘flavours’ of SQL. 1. String 2. Number 3. Date
    • 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
    • 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
    • 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
    • Datetime Types • Date - System defined date • Time – System defind time • Timestamp – Dates and times including fractions of a second • Interval – Intervals between dates
    • Advantages of SQL • Universal • Easy to use • Fits (more or less) with relational model
    • 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
    • Any Questions ??? SQL