Click here to load reader

26743218 SQL Tutorial

  • View
    154

  • Download
    0

Embed Size (px)

Text of 26743218 SQL Tutorial

SQL Tutorial2/10/2010

1

Table of Contents1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 SQL Tutorial ............................................................................................................................. 4 Introduction to SQL ................................................................................................................... 4 SQL Syntax ............................................................................................................................... 6 SQL SELECT Statement ........................................................................................................... 7 SQL SELECT DISTINCT Statement ......................................................................................... 9 SQL WHERE Clause ............................................................................................................... 10 SQL AND & OR Operators ..................................................................................................... 12 SQL ORDER BY Keyword ..................................................................................................... 13 SQL INSERT INTO Statement ................................................................................................ 15 SQL UPDATE Statement ........................................................................................................ 17 SQL DELETE Statement ......................................................................................................... 18 SQL TOP Clause ..................................................................................................................... 19 SQL LIKE Operator ................................................................................................................ 21 SQL Wildcards ........................................................................................................................ 23 SQL IN Operator ..................................................................................................................... 26 SQL BETWEEN Operator ....................................................................................................... 27 SQL Alias ................................................................................................................................ 28 SQL Joins ................................................................................................................................ 29 SQL INNER JOIN Keyword.................................................................................................... 30 SQL LEFT JOIN Keyword ...................................................................................................... 32 SQL RIGHT JOIN Keyword.................................................................................................... 33 SQL FULL JOIN Keyword...................................................................................................... 34 SQL UNION Operator ............................................................................................................. 35 SQL SELECT INTO Statement ............................................................................................... 38 SQL CREATE DATABASE Statement ................................................................................... 39 SQL CREATE TABLE Statement ........................................................................................... 40 SQL Constraints ...................................................................................................................... 41 SQL NOT NULL Constraint .................................................................................................... 41 SQL UNIQUE Constraint ........................................................................................................ 42 SQL PRIMARY KEY Constraint ............................................................................................ 43 SQL FOREIGN KEY Constraint ............................................................................................. 46 SQL CHECK Constraint .......................................................................................................... 48 SQL DEFAULT Constraint ..................................................................................................... 50 SQL CREATE INDEX Statement ............................................................................................ 51 SQL DROP INDEX, DROP TABLE, and DROP DATABASE ............................................... 52 SQL ALTER TABLE Statement .............................................................................................. 53 SQL AUTO INCREMENT Field ............................................................................................. 55 SQL Views .............................................................................................................................. 58 SQL Date Functions ................................................................................................................ 60 SQL NULL Values .................................................................................................................. 62 SQL NULL Functions ............................................................................................................. 64 SQL Data Types ...................................................................................................................... 65 SQL Functions ......................................................................................................................... 70 SQL AVG() Function .............................................................................................................. 70 SQL COUNT() Function ......................................................................................................... 72 SQL FIRST() Function ............................................................................................................ 74 SQL LAST() Function ............................................................................................................. 75 2

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

SQL MAX() Function .............................................................................................................. 76 SQL MIN() Function ............................................................................................................... 77 SQL SUM() Function .............................................................................................................. 78 SQL GROUP BY Statement .................................................................................................... 79 SQL HAVING Clause ............................................................................................................. 81 SQL UCASE() Function .......................................................................................................... 82 SQL LCASE() Function .......................................................................................................... 83 SQL MID() Function ............................................................................................................... 84 SQL LEN() Function ............................................................................................................... 85 SQL ROUND() Function ......................................................................................................... 86 SQL NOW() Function ............................................................................................................. 87 SQL FORMAT() Function....................................................................................................... 88 SQL Quick Reference From W3Schools .................................................................................. 89 SQL Hosting ............................................................................................................................ 92 You Have Learned SQL, Now What? ...................................................................................... 93 SQL Quiz ................................................................................................................................ 93

3

1 SQL Tutorial W3Schools HomeSQL 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 SyntaxSELECT Company, Country FROM Customers WHERE Country 'USA'

Next Chapter

SQL ResultCompany Island Trading Galera del gastrnomo Laughing Bacchus Wine Cellars Paris spcialits Simons bistro Wolski Zajazd Try it yourself Country UK Spain Canada France Denmark Poland

2 Introduction to SQLSQL 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

4

What Can SQL do? SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL can can can can can can can can can can execute queries against a database retrieve data from a database insert records in a database update records in a database delete records from a database create new databases create new tables in a database create stored procedures in a database create views in a database set permissions on tables, procedures, and views

SQL is a Standard - BUT....Although SQL is an ANSI (American National Standards Institute) standard, there are many different versions of the SQL language. However, to be compliant with the ANSI standard, they all support at least the major commands