Transcription

SQL Tutorial

SQL TUTORIALSimply Easy Learning by tutorialspoint.comtutorialspoint.comi

ABOUT THE TUTORIALSQL TutorialSQL is a database computer language designed for the retrieval and management of data in relationaldatabase. SQL stands for Structured Query Language.This tutorial will give you quick start with SQL.AudienceThis reference has been prepared for the beginners to help them understand the basic to advancedconcepts related to SQL languages.PrerequisitesBefore you start doing practice with various types of examples given in this reference, I'm making anassumption that you are already aware about what is database, especially RDBMS and what is acomputer programming language.Copyright & Disclaimer Notice Allthe content and graphics on this tutorial are the property of tutorialspoint.com. Any content fromtutorialspoint.com or this tutorial may not be redistributed or reproduced in any way, shape, or formwithout the written permission of tutorialspoint.com. Failure to do so is a violation of copyright laws.This tutorial may contain inaccuracies or errors and tutorialspoint provides no guarantee regarding theaccuracy of the site or its contents including this tutorial. If you discover that the tutorialspoint.com siteor this tutorial content contains some errors, please contact us at [email protected] POINTSimply Easy Learning

Table of ContentSQL Tutorial . 2Audience . 2Prerequisites . 2Copyright & Disclaimer Notice. 2SQL Overview . 15What is SQL? . 15Why SQL? . 15History: . 16SQL Process: . 16SQL Commands: . 17DDL - Data Definition Language: . 17DML - Data Manipulation Language: . 17DCL - Data Control Language: . 17DQL - Data Query Language: . 17SQL RDBMS Concepts . 18What is field?. 19What is record, or row? . 19What is column? . 19What is NULL value?. 19SQL Constraints: . 20NOT NULL Constraint: . 20DEFAULT Constraint:. 21Example: . 21Drop Default Constraint: . 21UNIQUE Constraint: . 21Example: . 21DROP a UNIQUE Constraint:. 22PRIMARY Key: . 22Create Primary Key: . 22Delete Primary Key: . 23FOREIGN Key: . 24Example: . 24DROP a FOREIGN KEY Constraint: . 25CHECK Constraint: . 25Example: . 25DROP a CHECK Constraint: . 25INDEX: . 26TUTORIALS POINTSimply Easy Learning

Example: . 26DROP a INDEX Constraint:. 26Data Integrity: . 26Database Normalization . 27Third Rule of 1NF: . 29SQL RDBMS Databases . 32MySQL . 32History: . 32Features: . 33MS SQL Server . 33History: . 33Features: . 34ORACLE . 34History: . 34Features: . 35MS- ACCESS . 36Features: . 36SQL Syntax . 37SQL SELECT Statement: . 37SQL DISTINCT Clause: . 37SQL WHERE Clause:. 37SQL AND/OR Clause: . 37SQL IN Clause: . 38SQL BETWEEN Clause: . 38SQL Like Clause: . 38SQL ORDER BY Clause: . 38SQL GROUP BY Clause: . 38SQL COUNT Clause: . 38SQL HAVING Clause: . 38SQL CREATE TABLE Statement: . 38SQL DROP TABLE Statement: . 39SQL CREATE INDEX Statement: . 39SQL DROP INDEX Statement: . 39SQL DESC Statement: . 39SQL TRUNCATE TABLE Statement: . 39SQL ALTER TABLE Statement: . 39SQL ALTER TABLE Statement (Rename): . 39SQL INSERT INTO Statement: . 39SQL UPDATE Statement: . 39TUTORIALS POINTSimply Easy Learning

SQL DELETE Statement: . 40SQL CREATE DATABASE Statement: . 40SQL DROP DATABASE Statement: . 40SQL USE Statement: . 40SQL COMMIT Statement: . 40SQL ROLLBACK Statement:. 40SQL Data Types . 41Exact Numeric Data Types: . 41Approximate Numeric Data Types: . 41Date and Time Data Types: . 42Character Strings Data Types: . 42Unicode Character Strings Data Types: . 42Binary Data Types: . 42Misc Data Types: . 43SQL Operators . 44What is an Operator in SQL? . 44SQL Arithmetic Operators: . 44SQL Comparison Operators: . 45SQL Logical Operators: . 47SQL Expressions . 50Syntax: . 50SQL - Boolean Expressions: . 50SQL - Numeric Expression: . 51SQL - Date Expressions: . 51SQL CREATE Database . 53Syntax: . 53Example: . 53DROP or DELETE Database . 54Syntax: . 54Example: . 54SQL SELECT Database. 55Syntax: . 55Example: . 55SQL CREATE Table . 56Syntax: . 56Syntax: . 56Example: . 57Example: . 57SQL DROP or DELETE Table. 59TUTORIALS POINTSimply Easy Learning

Syntax: . 59Example: . 59SQL INSERT Query . 60Syntax: . 60Example: . 60Populate one table using another table: . 61SQL SELECT Query . 62Syntax: . 62Example: . 62SQL WHERE Clause . 64Syntax: . 64Example: . 64SQL AND and OR Operators . 66The AND Operator: . 66Syntax: . 66Example: . 66The OR Operator: . 67Syntax: . 67Example: . 67SQL UPDATE Query. 69Syntax: . 69Example: . 69SQL DELETE Query . 71Syntax: . 71Example: . 71SQL LIKE Clause . 73Syntax: . 73Example: . 74SQL TOP Clause . 75Syntax: . 75Example: . 75SQL ORDER BY Clause . 77Syntax: . 77Example: . 77SQL Group By. 79Syntax: . 79Example: . 79SQL Distinct Keyword . 81Syntax: . 81TUTORIALS POINTSimply Easy Learning

Example: . 81SQL SORTING Results. 83Syntax: . 83Example: . 83SQL Constraints. 85NOT NULL Constraint: . 85DEFAULT Constraint:. 86Example: . 86Drop Default Constraint: . 86UNIQUE Constraint: . 87Example: . 87DROP a UNIQUE Constraint:. 87PRIMARY Key: . 88Create Primary Key: . 88Delete Primary Key: . 89FOREIGN Key: . 89Example: . 89DROP a FOREIGN KEY Constraint: . 90CHECK Constraint: . 90Example: . 90DROP a CHECK Constraint: . 91INDEX: . 91Example: . 91DROP a INDEX Constraint:. 91Dropping Constraints:. 92Integrity Constraints: . 92SQL Joins . 93SQL Join Types: . 94INNER JOIN .