SQLINTRODUCTION TO    SQLWhat 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 viewsSQL  is used for:Data Manipulation
Data Definition
Data Administration
All are expressed as an SQL statement or command.SQL REQUIREMENTS:SQL Must be embedded in a programming language, or used with a 4GL like VB2. 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 SiteTo 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

lovely

  • 1.
    SQLINTRODUCTION TO SQLWhat is SQL?SQL stands for Structured Query Language
  • 2.
    SQL lets youaccess and manipulate databases
  • 3.
    SQL is anANSI (American National Standards Institute) standard
  • 4.
    It is themost commonly used relational database language today.
  • 5.
    SQL works witha variety of different fourth-generation (4GL) programming languages, such as Visual Basic.What Can SQL do?SQL can execute queries against a database
  • 6.
    SQL can retrievedata from a database
  • 7.
    SQL can insertrecords in a database
  • 8.
    SQL can updaterecords in a database
  • 9.
    SQL can deleterecords from a database
  • 10.
    SQL can createnew databases
  • 11.
    SQL can createnew tables in a database
  • 12.
    SQL can createstored procedures in a database
  • 13.
    SQL can createviews in a database
  • 14.
    SQL can setpermissions on tables, procedures, and viewsSQL is used for:Data Manipulation
  • 15.
  • 16.
  • 17.
    All are expressedas an SQL statement or command.SQL REQUIREMENTS:SQL Must be embedded in a programming language, or used with a 4GL like VB2. 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.
  • 18.
    Using SQL inYour Web SiteTo 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)
  • 19.
    A server-side scriptinglanguage, like PHP or ASP
  • 20.
  • 21.
  • 22.
    RDBMSRDBMS stands forRelational 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.
  • 23.
    SQL is aRelational DatabaseA Fully Relational Database Management System must:Represent all info in database as tablesKeep logical representation of data independent from its physical storage characteristicsUse one high-level language for structuring, querying, and changing info in the databaseSupport the main relational operationsSupport alternate ways of looking at data in tablesProvide a method for differentiating between unknown values and nulls (zero or blank)Support Mechanisms for integrity, authorization, transactions, and recovery
  • 24.
    SQLDesignSQL represents allinformation in the form of tables
  • 25.
    Supports three relationaloperations: selection, projection, and join. These are for specifying exactly what data you want to display or use
  • 26.
    SQL is usedfor data manipulation, definition and administration6
  • 27.
    SQL SYNTAXSQLDatabase TablesAdatabase 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":INSERT TABLE
  • 28.
    SQL Commands:SQL commandsare 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:
  • 29.
    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.
  • 30.
    Data Manipulation Language(DML) - These SQL commands are used for storing, retrieving, modifying, and deleting data. These commands are SELECT, INSERT, UPDATE, and DELETE.
  • 31.
    Transaction Control Language(TCL) - These SQL commands are used for managing changes affecting the data. These commands are COMMIT, ROLLBACK, and SAVEPOINT.
  • 32.
    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.
  • 33.
    CREATE CREATETABLE 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.
  • 34.
    USEUSE 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.
  • 35.
    ALTER ALTERTABLE personal_infoADD 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.
  • 36.
    DROPDROP TABLE personal_info;removing the personal_info table permanentlyDROP 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.
  • 37.
    RENAMERENAME dpll To deptYou can execute the above statement only if you are the owner of the object you are renaming
  • 38.
    TRUNCATEAnother DDLstatement is the TRUNCATE TABLE statement, which removes all rows from the table andreleases the storage space used by that table. You can truncate a table in the following manner:TRUNCATE TABLE deptThe 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 structureBeing a DDL statement, you cannot roll back the TRUNCATE TABLEstatement. 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.
  • 39.
    The DATA MANIPULATIONLANGUAGE (DML) 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.
  • 40.
    INSERTINSERT INTOpersonal_infovalues(‘bart’,’simpson’,1234,$45000)!! 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. SELECTSELECT *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 tableSELECT last_nameFROM personal_info requires a list of the last names of all employees in the company.SELECT *FROM personal_infoWHERE 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
  • 41.
    UPDATEUPDATE personal_infoWHEREsalary = salary *1.03 each year, the company gives all employees a 3% cost- of-living increase in their salary.UPDATE personal_infoSET salary = salary + $5000WHERE employee_id = 1234 raising the salary of a CERTAIN employee by $5,000
  • 42.
    DELETEDELETE FROMpersonal_infoWHERE employee_id = 1234 removing record of a certain employee from the personal_info