Download SQL Ebook W3schools.com PDF

TitleSQL Ebook W3schools.com
TagsMicrosoft Access Sql Database Index Table (Database) Databases
File Size2.8 MB
Total Pages192
Table of Contents
                            1. SQL Introduction
2. SQL Syntax
3. SQL SELECT Statement
4. SQL SELECT DISTINCT Statement
5. SQL WHERE Clause
6. SQL AND, OR, NOT Operators
7. SQL ORDER BY Keyword
8. SQL INSERT INTO Statement
9. SQL UPDATE Statement
10. SQL DELETE Statement
11. SQL SELECT TOP, LIMIT, ROWNUM
12. SQL MIN() and MAX() Functions
13. SQL COUNT(), AVG() and SUM() Functions
14. SQL LIKE Operator
15. SQL Wildcard Characters
16. SQL IN Operator
17. SQL BETWEEN Operator
18. SQL Aliases
19. SQL Joins
20. SQL INNER JOIN Keyword
21. SQL LEFT JOIN Keyword
22. SQL RIGHT JOIN Keyword
23. SQL FULL OUTER JOIN Keyword
24. SQL Self JOIN
25. SQL UNION Operator
26. SQL GROUP BY Statement
27. SQL HAVING Clause
28. SQL SELECT INTO Statement
29. SQL INSERT INTO SELECT Statement
30. SQL CREATE DATABASE Statement
31. SQL DROP DATABASE Statement
32. SQL CREATE TABLE Statement
33. SQL DROP TABLE Statement
34. SQL ALTER TABLE Statement
35. SQL Constraints
36. SQL NOT NULL Constraint
37. SQL UNIQUE Constraint
38. SQL PRIMARY KEY Constraint
39. SQL FOREIGN KEY Constraint
40. SQL CHECK Constraint
41. SQL DEFAULT Constraint
42. SQL CREATE INDEX Statement
43. SQL AUTO INCREMENT a Field
44. SQL CREATE VIEW, REPLACE VIEW, DROP VIEW Statements
45. SQL Injection
46. SQL Hosting
47. SQL Functions
	47. 1. SQL AVG() Function
	47. 2. SQL COUNT() Function
	47. 3. SQL FIRST() Function
	47. 4. SQL LAST() Function
	47. 5. SQL MAX() Function
	47. 6. SQL MIN() Function
	47. 7. SQL ROUND() Function
	47. 8. SQL SUM() Function
	47. 9. SQL LEN() Function
	47. 10. SQL LCASE() Function
	47. 11. SQL MID() Function
	47. 12. SQL UCASE() Function
48. Date Functions in SQL Server and MySQL
	48. 1. MySQL NOW() Function
	48. 2. MySQL CURDATE() Function
	48. 3. MySQL CURTIME() Function
	48. 4. MySQL DATE() Function
	48. 5. MySQL EXTRACT() Function
	48. 6. MySQL DATE_ADD() Function
	48. 7. MySQL DATE_SUB() Function
	48. 8. MySQL DATEDIFF() Function
	48. 9. MySQL DATE_FORMAT() Function
	48. 10. SQL Server GETDATE() Function
	48. 11. SQL Server DATEPART() Function
	48. 12. SQL Server DATEADD() Function
	48. 13. SQL Server DATEDIFF() Function
	48. 14. SQL Server CONVERT() Function
	48. 15. SQL FORMAT() Function
	48. 16. SQL NOW() Function
49. SQL ISNULL(), NVL(), IFNULL() and COALESCE() Functions
50. SQL Operators
51. SQL General Data Types
52. SQL Data Types for MS Access, MySQL, and SQL Server
53. SQL Quick Reference
                        
Document Text Contents
Page 1

Content of this Ebook is Downoaded From www.w3schools.com . All

Copyrights reserved to www.w3schools.com

This Ebook is created by www.ebooktutorials.in

Page 2

Use Bookmarks for Easy Navigation

Page 96

The DEFAULT constraint is used to provide a default value for a column.

The default value will be added to all new records IF no other value is specified.

The following SQL sets a DEFAULT value for the "City" column when the "Persons" table
is created:

My SQL / SQL Server / Oracle / MS Access:

CREATE TABLE Persons (

    ID int NOT NULL,

    LastName varchar(255) NOT NULL,

    FirstName varchar(255),

    Age int,

    City varchar(255) DEFAULT 'Sandnes'

);

The DEFAULT constraint can also be used to insert system values, by using functions
like GETDATE():

CREATE TABLE Orders (

    ID int NOT NULL,

    OrderNumber int NOT NULL,

    OrderDate date DEFAULT GETDATE()

);

T H E W O R L D ' S L A R G E S T W E B D E V E L O P E R S I T E

Created By www.ebooktutorials.in

Content Downloaded from www.w3schools.com 94

Page 97

To create a DEFAULT constraint on the "City" column when the table is already created,
use the following SQL:

MySQL:

ALTER TABLE Persons

ALTER City SET DEFAULT 'Sandnes';

SQL Server / MS Access:

ALTER TABLE Persons

ALTER COLUMN City SET DEFAULT 'Sandnes';

Oracle:

ALTER TABLE Persons

MODIFY City DEFAULT 'Sandnes';

To drop a DEFAULT constraint, use the following SQL:

MySQL:

ALTER TABLE Persons

ALTER City DROP DEFAULT;

SQL Server / Oracle / MS Access:

ALTER TABLE Persons

ALTER COLUMN City DROP DEFAULT;

Created By www.ebooktutorials.in

Content Downloaded from www.w3schools.com 95

Page 191

HAVING SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value

IN SELECT column_name(s)
FROM table_name
WHERE column_name
IN (value1,value2,..)

INSERT INTO INSERT INTO table_name
VALUES (value1, value2, value3,....)

or

INSERT INTO table_name
(column1, column2, column3,...)
VALUES (value1, value2, value3,....)

INNER JOIN SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name

LEFT JOIN SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON table_name1.column_name=table_name2.column_name

RIGHT JOIN SELECT column_name(s)
FROM table_name1
RIGHT JOIN table_name2
ON table_name1.column_name=table_name2.column_name

FULL JOIN SELECT column_name(s)
FROM table_name1
FULL JOIN table_name2
ON table_name1.column_name=table_name2.column_name

LIKE SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern

ORDER BY SELECT column_name(s)
FROM table_name

Created By www.ebooktutorials.in

Page 192

ORDER BY column_name [ASC|DESC]

SELECT SELECT column_name(s)
FROM table_name

SELECT * SELECT *
FROM table_name

SELECT DISTINCT SELECT DISTINCT column_name(s)
FROM table_name

SELECT INTO SELECT *
INTO new_table_name [IN externaldatabase]
FROM old_table_name

or

SELECT column_name(s)
INTO new_table_name [IN externaldatabase]
FROM old_table_name

SELECT TOP SELECT TOP number|percent column_name(s)
FROM table_name

TRUNCATE TABLE TRUNCATE TABLE table_name

UNION SELECT column_name(s) FROM table_name1
UNION
SELECT column_name(s) FROM table_name2

UNION ALL SELECT column_name(s) FROM table_name1
UNION ALL
SELECT column_name(s) FROM table_name2

UPDATE UPDATE table_name
SET column1=value, column2=value,...
WHERE some_column=some_value

WHERE SELECT column_name(s)
FROM table_name
WHERE column_name operator value

Created By www.ebooktutorials.in

Similer Documents