Click here to load reader

W3 SQL Tutorial

  • View
    99

  • Download
    4

Embed Size (px)

DESCRIPTION

Basic SQL from W3

Text of W3 SQL Tutorial

  • 1

    SQL

    Tutorial

    2/10/2010

  • 2

    Table of Contents 1 SQL Tutorial ............................................................................................................................. 42 Introduction to SQL ................................................................................................................... 43 SQL Syntax ............................................................................................................................... 64 SQL SELECT Statement ........................................................................................................... 75 SQL SELECT DISTINCT Statement ......................................................................................... 96 SQL WHERE Clause ............................................................................................................... 107 SQL AND & OR Operators ..................................................................................................... 128 SQL ORDER BY Keyword ..................................................................................................... 139 SQL INSERT INTO Statement ................................................................................................ 1510 SQL UPDATE Statement ........................................................................................................ 1711 SQL DELETE Statement ......................................................................................................... 1812 SQL TOP Clause ..................................................................................................................... 1913 SQL LIKE Operator ................................................................................................................ 2114 SQL Wildcards ........................................................................................................................ 2315 SQL IN Operator ..................................................................................................................... 2616 SQL BETWEEN Operator ....................................................................................................... 2717 SQL Alias ................................................................................................................................ 2818 SQL Joins ................................................................................................................................ 2919 SQL INNER JOIN Keyword .................................................................................................... 3020 SQL LEFT JOIN Keyword ...................................................................................................... 3221 SQL RIGHT JOIN Keyword .................................................................................................... 3322 SQL FULL JOIN Keyword ...................................................................................................... 3423 SQL UNION Operator ............................................................................................................. 3524 SQL SELECT INTO Statement ............................................................................................... 3825 SQL CREATE DATABASE Statement ................................................................................... 3926 SQL CREATE TABLE Statement ........................................................................................... 4027 SQL Constraints ...................................................................................................................... 4128 SQL NOT NULL Constraint .................................................................................................... 4129 SQL UNIQUE Constraint ........................................................................................................ 4230 SQL PRIMARY KEY Constraint ............................................................................................ 4331 SQL FOREIGN KEY Constraint ............................................................................................. 4632 SQL CHECK Constraint .......................................................................................................... 4833 SQL DEFAULT Constraint ..................................................................................................... 5034 SQL CREATE INDEX Statement ............................................................................................ 5135 SQL DROP INDEX, DROP TABLE, and DROP DATABASE ............................................... 5236 SQL ALTER TABLE Statement .............................................................................................. 5337 SQL AUTO INCREMENT Field ............................................................................................. 5538 SQL Views .............................................................................................................................. 5839 SQL Date Functions ................................................................................................................ 6040 SQL NULL Values .................................................................................................................. 6241 SQL NULL Functions ............................................................................................................. 6442 SQL Data Types ...................................................................................................................... 6543 SQL Functions ......................................................................................................................... 7044 SQL AVG() Function .............................................................................................................. 7045 SQL COUNT() Function ......................................................................................................... 7246 SQL FIRST() Function ............................................................................................................ 7447 SQL LAST() Function ............................................................................................................. 75

  • 3

    48 SQL MAX() Function .............................................................................................................. 7649 SQL MIN() Function ............................................................................................................... 7750 SQL SUM() Function .............................................................................................................. 7851 SQL GROUP BY Statement .................................................................................................... 7952 SQL HAVING Clause ............................................................................................................. 8153 SQL UCASE() Function .......................................................................................................... 8254 SQL LCASE() Function .......................................................................................................... 8355 SQL MID() Function ............................................................................................................... 8456 SQL LEN() Function ............................................................................................................... 8557 SQL ROUND() Function ......................................................................................................... 8658 SQL NOW() Function ............................................................................................................. 8759 SQL FORMAT() Function ....................................................................................................... 8860 SQL Quick Reference From W3Schools .................................................................................. 8961 SQL Hosting ............................................................................................................................ 9262 You Have Learned SQL, Now What? ...................................................................................... 9363 SQL Quiz ................................................................................................................................ 93

  • 4

    1 SQL Tutorial

    W3Schools Home Next Chapter

    SQL is a standard language for accessing databases.

    Our SQL tutorial will teach you how to use SQL to access and manipulate data in:

    MySQL, SQL Server, Access, Oracle, Sybase, DB2, and other database systems.

    SQL Syntax

    SELECT Company, Country FROM Customers WHERE Country 'USA' SQL Result

    Company Country

    Island Trading UK

    Galera del gastrnomo Spain

    Laughing Bacchus Wine Cellars Canada

    Paris spcialits France

    Simons bistro Denmark

    Wolski Zajazd Poland

    Try it yourself

    2 Introduction to SQL

    SQL is a standard language for accessing and manipulating databases.

    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

  • 5

    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