• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content







Total Views
Views on SlideShare
Embed Views



1 Embed 3

http://www.linkedin.com 3



Upload Details

Uploaded via as Microsoft PowerPoint

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.

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

    lovely lovely Presentation Transcript

    • SQL
      What is SQL?
      • SQL stands for Structured Query Language
      • SQL lets you access and manipulate databases
      • SQL is an ANSI (American National Standards Institute) standard
      • It is the most commonly used relational database language today.
      • SQL works with a variety of different fourth-generation (4GL) programming languages, such as Visual Basic.
    • What Can SQL do?
      • SQL can execute queries against a database
      • SQL can retrieve data from a database
      • SQL can insert records in a database
      • SQL can update records in a database
      • SQL can delete records from a database
      • SQL can create new databases
      • SQL can create new tables in a database
      • SQL can create stored procedures in a database
      • SQL can create views in a database
      • SQL can set permissions on tables, procedures, and views
    • SQL is used for:
      • Data Manipulation
      • Data Definition
      • Data Administration
      • All are expressed as an SQL statement or command.
      SQL Must be embedded in a programming language, or used with a 4GL like VB
      2. SQL is a free form language so there is no limit to the the number of words per line or fixed line break.
      3. Syntax statements, words or phrases are always in lower case; keywords are in uppercase.
    • Using SQL in Your Web Site
      To build a web site that shows some data from a database, you will need the following:
      • An RDBMS database program (i.e. MS Access, SQL Server, MySQL)
      • A server-side scripting language, like PHP or ASP
      • SQL
      • HTML / CSS
      • 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 collection of related data entries and it consists of columns and rows.
    • SQL is a Relational Database
      A Fully Relational Database Management System must:
      Represent all info in database as tables
      Keep logical representation of data independent from its physical storage characteristics
      Use one high-level language for structuring, querying, and changing info in the database
      Support the main relational operations
      Support alternate ways of looking at data in tables
      Provide a method for differentiating between unknown values and nulls (zero or blank)
      Support Mechanisms for integrity, authorization, transactions, and recovery
    • SQL
      • SQL represents all information in the form of tables
      • Supports three relational operations: selection, projection, and join. These are for specifying exactly what data you want to display or use
      • SQL is used for data manipulation, definition and administration
      Database Tables
      A database most often contains one or more tables. Each table is identified by a name (e.g. "Customers" or "Orders"). Tables contain records (rows) with data.
      Below is an example of a table called "Persons":
    • SQL Commands:
      SQL commands are instructions used to communicate with the database to perform specific task that work with data. SQL commands can be used not only for searching the database but also to perform various other functions like, for example, you can create tables, add data to tables, or modify data, drop the table, set permissions for users. SQL commands are grouped into four major categories depending on their functionality:
      • Data Definition Language (DDL) - These SQL commands are used for creating, modifying, and dropping the structure of database objects. The commands are CREATE, USE, ALTER, DROP, RENAME, and TRUNCATE.
      • Data Manipulation Language (DML) - These SQL commands are used for storing, retrieving, modifying, and deleting data. These commands are SELECT, INSERT, UPDATE, and DELETE.
      • Transaction Control Language (TCL) - These SQL commands are used for managing changes affecting the data. These commands are COMMIT, ROLLBACK, and SAVEPOINT.
      • Data Control Language (DCL) - These SQL commands are used for providing security to database objects. These commands are GRANT and REVOKE.
    • The data definition language (DDL)
      • used o create and destroy databases and data objects. These commands will primarily be used by database administrators during the set up and removal phases of a database project.
      • CREATE
      CREATE TABLE personal_info (first_name char (20) not null, last_name char(20)not null, employee_id not null)
      • Establishes a table titled “personal_info” in the current database. The table contains three attributes: first_name, last_name and employee_id.
      • USE
      USE employees;
      • Issue commands that will affect the employees database.
      !!!It is important to always be conscious of the database you are working in before issuing SQL commands that manipulate data.
      • ALTER
      ALTER TABLE personal_info
      ADD salary money null;
      • adds new attribute to the personal_info table – an employees' salary. The money argument specifies that an employee’s salary will be stored using dollars and cents formats. The “null” keyword tell the database that it’s ok for this field to contain no value for any given argument.
      • DROP
      DROP TABLE personal_info;
      • removing the personal_info table permanently
      DROP DATABASE employees;
      • remove the entire employees database
      !!! Remember that the DROP command removes the entire data structures from your database. If you want to remove individual records, use the DELETE command of the DML.
      • RENAME
      RENAME dpll To dept
      • You can execute the above statement only if you are the owner of the object you are renaming
      • TRUNCATE
      Another DDL statement is the TRUNCATE TABLE statement, which removes all rows from the table and
      releases the storage space used by that table. You can truncate a table in the following manner:
      • The TRUNCATE TABLE statement removes data and releases storage space but does not remove the structure of the table, while the DELETE statement removes data, does not release storage space, and does not remove the structure
      • Being a DDL statement, you cannot roll back the TRUNCATE TABLE
      statement. You can execute the TRUNCATE TABLE statement only if you are the owner of the table you are truncating or you have been granted the DELETE TABLE privilege. The TRUNCATE TABLE statement is faster than the DELETE statement because no rollback information is generated for the TRUNCATE TABLE statement unlike for the DELETE statement.
      • is used to retrieve, insert and modify the database information. These commands will be used by all database users during the routing operation of the database.
      • INSERT
      INSERT INTO personal_info
      !! Note there are four values specified for the record. These corresponds with to the table attribute in the order they are defined: first_name, last_name, employee_id and salary.
      • SELECT
      SELECT *
      FROM personal_info
      • retrieves all of the information contained within the personal_info table. The asterisk (*) is used as a wildcard in SQL. It means “select everything from the personal_info table
    • SELECT last_name
      FROM personal_info
      • requires a list of the last names of all employees in the company.
      SELECT *
      FROM personal_info
      WHERE salary > $50000
      • reviewing the personnel records of all highly paid employees. The above command retrieves all of the data contained within personal_info for records that have a salary value greater than $5000
      • UPDATE
      UPDATE personal_info
      WHERE salary = salary *1.03
      • each year, the company gives all employees a 3% cost- of-living increase in their salary.
    • UPDATE personal_info
      SET salary = salary + $5000
      WHERE employee_id = 1234
      • raising the salary of a CERTAIN employee by $5,000
      • DELETE
      DELETE FROM personal_info
      WHERE employee_id = 1234
      • removing record of a certain employee from the personal_info