Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

sql_tutorial

The SQL tutorial provides a comprehensive guide to learning Structured Query Language (SQL), covering essential concepts from basic to advanced levels. It includes practical examples, standard SQL commands, and an online editor for executing SQL code. The tutorial is designed for students and professionals in software development, emphasizing the importance of SQL in managing relational databases.

Uploaded by

Srawann Srav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

sql_tutorial

The SQL tutorial provides a comprehensive guide to learning Structured Query Language (SQL), covering essential concepts from basic to advanced levels. It includes practical examples, standard SQL commands, and an online editor for executing SQL code. The tutorial is designed for students and professionals in software development, emphasizing the importance of SQL in managing relational databases.

Uploaded by

Srawann Srav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

SQL Tutorial

About the Tutorial


Our SQL tutorial helps you learn SQL (Structured Query Language) in simple and easy
steps so that you can start your database programming quickly. It covers most of the
important concepts related to SQL for a basic to advanced understanding of SQL and to
get a feel of how SQL works.
SQL (Structured Query Language) is a programming language which is used to manage
data stored in relational databases like MySQL, MS Access, SQL Server, Oracle, Sybase,
Informix, Postgres etc.
SQL is a database computer language designed for the retrieval and management of data
in relational databases like MySQL, MS Access, SQL Server, Oracle, Sybase, Informix,
Postgres etc. SQL stands for Structured Query Language. SQL was developed in the
1970s by IBM Computer Scientists.

SQL is not a database management system, but it is a query language which is


used to store and retrieve the data from a database or in simple words SQL is a
language that communicates with databases.

SQL Examples
Consider we have following CUSTOMERS table which stores customer's ID, Name, Age,
Salary, City and Country −

ID Name Age Salary City Country

1 Ramesh 32 2000.00 Maryland USA

2 Mukesh 40 5000.00 New York USA

3 Sumit 45 4500.00 Muscat Oman

4 Kaushik 25 2500.00 Kolkata India

5 Hardik 29 3500.00 Bhopal India

6 Komal 38 3500.00 Saharanpur India

7 Ayush 25 3500.00 Delhi India

SQL makes it easy to manipulate this data using simple DML (Data Manipulation Language)
Statements. For example, if we want to list down all the customers from USA then following
will be the SQL query.

SELECT * FROM CUSTOMERS WHERE country = 'USA';

i
SQL Tutorial

This will produce the following result:

ID Name Age Salary City Country

1 Ramesh 32 2000.00 Maryland USA

2 Mukesh 40 5000.00 New York USA

SQL Online Editor


We have provided SQL Online Editor which helps you to Edit and Execute the SQL code
directly from your browser. Try to click the icon to run the following SQL code to be
executed on CUSTOMERS table and print the records matching with the given condition.

SELECT * FROM CUSTOMERS WHERE country = 'USA';

So now, you do not need to do a sophisticated setup to execute all the examples given in
this tutorial because we are providing you Online SQL Editor, which allows you to edit
your code and compile it online. You can try our Online SQL Editor.

SQL Basic Commands


We have a list of standard SQL commands to interact with relational databases. These
commands are CREATE, SELECT, INSERT, UPDATE, DELETE, DROP and TRUNCATE and
can be classified into the following groups based on their nature −

Data Definition Language (DDL)


A Data Definition Language (DDL) is used to create and modify the structure of database
objects which include tables, views, schemas, and indexes etc.

Command Description Demo

Creates a new table, a view of a table, or other object in the


CREATE Demo
database.

ALTER Modifies an existing database object, such as a table. Demo

Deletes an entire table, a view of a table or other objects in the


DROP Demo
database.

TRUNCATE Truncates the entire table in a go. Demo

Data Manipulation Language (DML)

ii
SQL Tutorial

A Data Manipulation Language (DML) is used for adding, deleting, and modifying data in
a database.

Command Description Demo

SELECT Retrieves certain records from one or more tables. Demo

INSERT Creates a record. Demo

UPDATE Modifies records. Demo

DELETE Deletes records. Demo

Data Control Language (DCL)


Data Control Language (DCL) is used to control access to data stored in a database.

Command Description Demo

GRANT Gives a privilege to user Demo

REVOKE Takes back privileges granted from user. Demo

Why to Learn SQL?


SQL (Structured Query Language) is a MUST for the students and working professionals
to become a great Software Engineer specially when they are working in Software
Development Domain. SQL is the most common language used almost in every application
software including banking, finance, education, security etc. to store and manipulate data.
SQL is fairly easy to learn, so if you are starting to learn any programming language then
it is very much advised that you should also learn SQL and other Database related concepts
to become a complete Software Programmer. There are many good reasons which makes
SQL as the first choice of any programmer −
SQL is the standard language for any Relational Database System. All the Relational Data
Base Management Systems (RDBMS) like MySQL, MS Access, Oracle, Sybase, Informix,
Postgres and SQL Server use SQL as their standard database language.
Also, software industry is using different dialects of SQL, such as −
 MS SQL Server using T-SQL,
 Oracle using PL/SQL,
 MS Access version of SQL is called JET SQL (native format) etc.

iii
SQL Tutorial

SQL Applications
SQL is one of the most widely used Query Language over the databases. SQL provides
following functionality to the database programmers −
 Executes different database queries against a database.
 Defines the data in a database and manipulates that data.
 Creates data in a relational database management system.
 Accesses data from the relational database management system.
 Creates and drops databases and tables.
 Creates and maintains database users.
 Creates views, stored procedures, functions in a database.
 Sets permissions on tables, procedures and views.

Who Should Learn SQL


This SQL tutorial will help both students as well as working professionals who want to
develop applications based on some databases like banking systems, support systems,
information systems, web applications, websites, mobile apps or personal blogs etc. We
recommend reading this tutorial, in the sequence listed in the left side menu.
Today, SQL is an essential language to learn for anyone involved in the software
application development process including Software Developers, Software Designers, and
Project Managers etc.

Prerequisites to Learn SQL


Though we have tried our best to present the SQL concepts in a simple and easy way, still
before you start learning SQL concepts given in this tutorial, it is assumed that you are
already aware about some basic concepts of computer science, what is a database,
especially the basics of RDBMS and associated concepts.
This tutorial will give you enough understanding on the various concepts of SQL along with
suitable examples so that you can start your Software Development journey immediately
after finishing this tutorial.

SQL Online Quizzes


This SQL tutorial helps you prepare for technical interviews and certification exams. We
have provided various quizzes and assignments to check your learning level. Given quizzes
have multiple choice questions and their answers with short explanations.
Following is a sample quiz, try to attempt any of the given answers:
Show Answer
Q 1 - The SQL programming language was developed by which of the following:
A - Google in 1990s
B - Microsoft in 1980s
C - IBM in 1970s
D - None of the Above

iv
SQL Tutorial

Start your online quiz Start SQL Quiz.

SQL Jobs and Opportunities


SQL professionals are very much in high demand as the data turn out is increasing
exponentially. Almost every major company is recruiting IT professionals having good
experience with SQL.
Average annual salary for a SQL professional is around $150,000. Though it can vary
depending on the location. Following are the great companies who keep recruiting SQL
professionals like Database Administrator (DBA), Database Developer, Database Testers,
Data Scientist, ETL Developer, Database Migration Expert, Cloud Database Expert etc.:
 Google
 Amazon
 Netflix
 Infosys
 TCS
 Tech Mahindra
 Wipro
 Pinterest
 Uber
 Trello
 Many more...
So, you could be the next potential employee for any of these major companies. We have
developed a great learning material for SQL which will help you prepare for the technical
interviews and certification exams based on SQL. So, start learning SQL using our simple
and effective tutorial anywhere and anytime absolutely at your pace.

Frequently Asked Questions about SQL


There are some very Frequently Asked Questions(FAQ) about SQL. This section tries to
answer them briefly.

What are SQL skills?


SQL skills help software programmers and data experts maintain, create, and retrieve
information from relational databases like MySQL, Oracle, MS SQL Server etc., which store
data into columns and rows. It also allows them to access, update, manipulate, insert and
modify data in efficient way.
A relational database stores information in tabular form, with rows and columns
representing different data attributes and the various relationships between the data
values.

What are the 5 different types of SQL commands?


There are 5 main types of commands Listed below:
 DDL (Data Definition Language) commands
 DML (Data Manipulation Language) commands

v
SQL Tutorial

 DCL (Data Control Language) commands


 Transaction Control Language(TCL) commands
 Data Query Language(DQL) commands

How long should it take to learn SQL?


SQL is very easy to learn. You can learn SQL in as little as two to three weeks. However,
it can take months of practice before you feel comfortable using it. Determining how long
it takes to learn SQL also depends on how you plan to use it. Following this SQL tutorial
will give you enough confidence to work on any software development related to database.

What are the benefits of using SQL over Excel?


SQL queries are more flexible and powerful than Excel formulas. SQL is fast and can handle
large amount of data. Unlike Excel, SQL can handle well over one million fields of data
with ease.

How do I start learning SQL?


Here is the summarized list of tips which you can follow to start learning SQL.
 First and the most important is to make your mind to learn SQL.
 Install MySQL or MariaDB database on your computer system.
 Follow our tutorial step by step starting from very beginning.
 Read more articles, watch online courses or buy a book on SQL to enhance your
knowledge in SQL.
 Try to develop a small software using PHP or Python which makes use of database.

What are the 4 basic statements in SQL?


Following are four basic SQL Operations or SQL Statements.
 SELECT statement selects data from database tables.
 UPDATE statement updates existing data into database tables.
 INSERT statement inserts new data into database tables.
 DELETE statement deletes existing data from database tables.

What are data types in SQL?


Following are following three SQL data types.
 String Data types.
 Numeric Data types.
 Date and time Data types.

Which is the best place to learn SQL?

vi
SQL Tutorial

You can use our simple and the best SQL tutorial to learn SQL. We have removed all the
unnecessary complexity while teaching you SQL concepts. You can start learning it
now Start Learning SQL.

Copyright & Disclaimer


 Copyright 2025 by Tutorials Point (I) Pvt. Ltd.
All the content and graphics published in this e-book are the property of Tutorials Point (I)
Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish
any contents or a part of contents of this e-book in any manner without written consent
of the publisher.
We strive to update the contents of our website and tutorials as timely and as precisely as
possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt.
Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our
website or its contents including this tutorial. If you discover any errors on our website or
in this tutorial, please notify us at contact@tutorialspoint.com

vii
SQL Tutorial

Table of Contents
About the Tutorial ............................................................................................................................................ i

Prerequisites to Learn SQL ............................................................................................................................. iv

Copyright & Disclaimer.................................................................................................................................. vii

Table of Contents ......................................................................................................................................... viii

SQL TUTORIAL......................................................................................................... XIII

1. SQL - Roadmap.............................................................................................................................................. 14

2. SQL - Overview.............................................................................................................................................. 16

3. SQL - RDBMS Concepts ................................................................................................................................. 18

4. SQL Databases .............................................................................................................................................. 22

5. SQL - Syntax .................................................................................................................................................. 31

6. SQL - Data Types ........................................................................................................................................... 40

7. SQL - Operators............................................................................................................................................. 54

8. SQL - Expressions .......................................................................................................................................... 58

9. SQL - Comments............................................................................................................................................ 63

SQL DATABASE.........................................................................................................65

10. SQL - CREATE Database ................................................................................................................................ 66

11. SQL - DROP Database ................................................................................................................................... 68

12. SQL - SELECT Database, USE Statement....................................................................................................... 71

13. SQL - Rename Database ............................................................................................................................... 74

14. SQL - Show Databases .................................................................................................................................. 77

15. SQL Backup Database ................................................................................................................................... 81

SQL TABLE...............................................................................................................85

16. SQL - CREATE Table....................................................................................................................................... 86

17. SQL - Show Tables (Listing Tables) ............................................................................................................... 90

18. SQL - Rename Table...................................................................................................................................... 94

19. SQL - TRUNCATE TABLE ................................................................................................................................ 99

viii
SQL Tutorial

20. SQL - Clone Tables ...................................................................................................................................... 103

21. SQL - Temporary Tables.............................................................................................................................. 108

22. SQL - ALTER TABLE ...................................................................................................................................... 113

23. SQL - DROP Table........................................................................................................................................ 121

24. SQL - Delete Table....................................................................................................................................... 125

25. SQL - Constraints......................................................................................................................................... 130

SQL QUERIES ......................................................................................................... 134

26. SQL - INSERT Query..................................................................................................................................... 135

27. SQL - SELECT Query..................................................................................................................................... 142

28. SQL - Select Into Statement ....................................................................................................................... 147

29. SQL - Insert Into... Select Statement .......................................................................................................... 154

30. SQL - UPDATE Query................................................................................................................................... 159

31. SQL - DELETE Query .................................................................................................................................... 164

32. SQL - SORTING Results ............................................................................................................................... 170

SQL VIEWS ............................................................................................................ 175

33. SQL - CREATE View...................................................................................................................................... 176

34. SQL - UPDATE View..................................................................................................................................... 180

35. SQL - DROP or DELETE View ....................................................................................................................... 185

36. SQL - Rename View..................................................................................................................................... 189

SQL OPERATORS AND CLAUSES ................................................................................. 195

37. SQL - WHERE Clause ................................................................................................................................... 196

38. SQL - TOP Clause ......................................................................................................................................... 202

39. SQL - DISTINCT Keyword ............................................................................................................................ 209

40. SQL - ORDER BY Clause............................................................................................................................... 215

41. SQL - Group By Clause ................................................................................................................................ 222

42. SQL - Having Clause .................................................................................................................................... 229

43. SQL - AND and OR Conjunctive Operators................................................................................................. 234

ix
SQL Tutorial

44. SQL - BOOLEAN ........................................................................................................................................... 243

Filtering Boolean Data ................................................................................................................................. 244

45. SQL - Like Operator..................................................................................................................................... 246

46. SQL - IN Operator........................................................................................................................................ 255

47. SQL - ANY, ALL Operators ........................................................................................................................... 261

48. SQL - EXISTS Operator ................................................................................................................................ 267

49. SQL - CASE ................................................................................................................................................... 274

50. SQL - NOT Operator .................................................................................................................................... 284

51. SQL - NOT EQUAL ........................................................................................................................................ 291

52. SQL - IS NULL ............................................................................................................................................... 296

53. SQL - IS NOT NULL ....................................................................................................................................... 301

54. SQL - NOT NULL Constraint ........................................................................................................................ 306

55. SQL - BETWEEN Operator ........................................................................................................................... 311

56. SQL - UNION Operator................................................................................................................................ 318

57. SQL - UNION vs UNION ALL ........................................................................................................................ 327

58. SQL - INTERSECT.......................................................................................................................................... 332

59. SQL - EXCEPT ............................................................................................................................................... 338

60. SQL - Alias Syntax ....................................................................................................................................... 345

SQL JOINS ............................................................................................................. 351

61. SQL - Joins ................................................................................................................................................... 352

62. SQL - Inner Join ........................................................................................................................................... 356

63. SQL - Left Join.............................................................................................................................................. 363

64. SQL - Right Join ........................................................................................................................................... 370

65. SQL - Cross Join ........................................................................................................................................... 376

66. SQL - Full Join .............................................................................................................................................. 381

67. SQL - Self Join.............................................................................................................................................. 388

68. SQL - DELETE JOIN....................................................................................................................................... 394

69. SQL - UPDATE JOIN ..................................................................................................................................... 400

x
SQL Tutorial

70. Left Join vs Right Join ................................................................................................................................. 407

71. UNION vs JOIN ............................................................................................................................................ 410

SQL KEYS............................................................................................................... 415

72. SQL - Unique Key ........................................................................................................................................ 416

73. SQL - Primary Key ....................................................................................................................................... 421

74. SQL - Foreign Key ........................................................................................................................................ 426

75. The SQL Composite Key.............................................................................................................................. 431

76. SQL - Alternate Key..................................................................................................................................... 436

SQL INDEXES.......................................................................................................... 440

77. SQL - Indexes............................................................................................................................................... 441

78. SQL - Create Index ...................................................................................................................................... 443

79. SQL - Drop Index ......................................................................................................................................... 446

80. SQL - Show Indexes..................................................................................................................................... 451

81. SQL - Unique Indexes.................................................................................................................................. 454

82. SQL - Clustered Index.................................................................................................................................. 458

83. SQL - Non-Clustered Index ......................................................................................................................... 462

ADVANCED SQL...................................................................................................... 466

84. SQL - Wildcards ........................................................................................................................................... 467

85. SQL - Injection ............................................................................................................................................. 471

86. SQL - Hosting............................................................................................................................................... 473

87. SQL - MIN() - MAX() function ..................................................................................................................... 475

88. SQL - Null Functions.................................................................................................................................... 481

89. SQL - Check Constraint ............................................................................................................................... 487

90. SQL - Default Constraint ............................................................................................................................. 494

91. SQL - Stored Procedures............................................................................................................................. 498

92. SQL - NULL Values ....................................................................................................................................... 505

93. SQL - Transactions ...................................................................................................................................... 510

xi
SQL Tutorial

94. SQL Subqueries ........................................................................................................................................... 517

95. SQL - Handling Duplicates .......................................................................................................................... 523

96. SQL - Using Sequences................................................................................................................................ 526

97. SQL - Auto Increment ................................................................................................................................. 533

98. SQL - Date & Time....................................................................................................................................... 538

99. SQL - Cursors ............................................................................................................................................... 541

100. SQL - Common Table Expression (CTE) ...................................................................................................... 546

101. SQL - Group By vs Order By ........................................................................................................................ 552

102. SQL - IN vs EXISTS ....................................................................................................................................... 558

103. SQL - Database Tuning................................................................................................................................ 563

xii
SQL Tutorial

SQL Tutorial

xiii
1. SQL - Roadmap SQL Tutorial

This Roadmap will guide you to master SQL. You will learn core concepts, techniques, and
best practices by following mentioned topics. This step-by-step path will help you as a
beginner.

What is a Tutorial Roadmap?


Tutorial Roadmap typically covers the journey from beginner to advanced user, including
key concepts, practical applications, and best practices.

SQL Roadmap
This SQL roadmap is created to upgrade you from a SQL novice to a SQL expert. Whether
you're aspiring to become a data analyst, database administrator, or software developer,
this comprehensive guide will provide a structured path to master SQL.

How SQL Roadmap can help you?


This roadmap provides a structured approach to mastering SQL. Remember, expertise
comes from consistent practice, curiosity, and real-world problem-solving. Your journey
from a beginner to an SQL expert is a marathon, not a sprint. So keep practicing and
improve yourself.

14
2. SQL - Overview SQL Tutorial

What is SQL?
SQL (Structured Query Language) is a language to operate databases. It includes
Database Creation, Database Deletion, Fetching Data Rows, Modifying & Deleting Data
rows, etc.

SQL stands for Structured Query Language which is a computer language for storing,
manipulating and retrieving data stored in a relational database. SQL was developed in
the 1970s by IBM Computer Scientists and became a standard of the American National
Standards Institute (ANSI) in 1986, and the International Organization for Standardization
(ISO) in 1987.

Though SQL is an ANSI (American National Standards Institute) standard


language, but there are many different dialects of the SQL language like MS SQL
Server is using T-SQL and Oracle is using PL/SQL.

SQL is the standard language to communicate with Relational Database Systems. All the
Relational Database Management Systems (RDMS) like MySQL, MS Access, Oracle,
Sybase, Informix, Postgres and SQL Server use SQL as their Standard Database Language.

Why SQL?
SQL is widely popular because it offers the following advantages −

 Allows users to access data in the relational database management systems.

 Allows users to describe the data.

 Allows users to define the data in a database and manipulate that data.

 Allows to embed within other languages using SQL modules, libraries & pre-
compilers.

 Allows users to create and drop databases and tables.

 Allows users to create views, stored procedures, functions, etc. in a database.

 Allows users to set permissions on tables, procedures and views.

A Brief History of SQL


 1970 − Dr. Edgar F. "Ted" Codd of IBM is known as the father of relational
databases. He described a relational model for databases.

 1974 − Structured Query Language (SQL) appeared.

 1978 − IBM worked to develop Codd's ideas and released a product named
System/R.

15
SQL Tutorial

 1986 − IBM developed the first prototype of relational database and


standardized by ANSI. The first relational database was released by Relational
Software which later came to be known as Oracle.

 1987 − SQL became the part of the International Organization for


Standardization (ISO).

How SQL Works?


When you are executing an SQL command for any RDBMS, the system determines the
best way to carry out your request and SQL engine figures out how to interpret the task.

There are various components included in this process. These components are −

 Query Dispatcher

 Optimization Engines

 Classic Query Engine

 SQL Query Engine, etc.

A classic query engine handles all the non-SQL queries, but a SQL query engine won't
handle logical files. Following is a simple diagram showing the SQL Architecture −

16
3. SQL - RDBMS Concepts SQL Tutorial

What is RDBMS?
RDBMS stands for Relational 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.

A Relational database management system (RDBMS) is based on the relational model as


introduced by E. F. Codd in 1970.

What is a Table?
The data in an RDBMS is stored in database objects known as tables. This table is basically
a collection of related data entries and it consists of numerous columns and rows.

Remember, a table is the most common and simplest form of data storage in a relational
database. Following is an example of a CUSTOMERS table which stores customer's ID,
Name, Age, Salary, City and Country −

ID Name Age Salary City Country

1 Ramesh 32 2000.00 Hyderabad India

2 Mukesh 40 5000.00 New York USA

3 Sumit 45 4500.00 Muscat Oman

4 Kaushik 25 2500.00 Kolkata India

5 Hardik 29 3500.00 Bhopal India

6 Komal 38 3500.00 Saharanpur India

7 Ayush 25 3500.00 Delhi India

8 Javed 29 3700.00 Delhi India

17
SQL Tutorial

What is a Field?
Every table is broken up into smaller entities called fields. A field is a column in a table
that is designed to maintain specific information about every record in the table.

For example, our CUSTOMERS table consists of different fields like ID, Name, Age, Salary,
City and Country.

What is a Record or a Row?


A record is also called as a row of data is each individual entry that exists in a table. For
example, there are 7 records in the above CUSTOMERS table. Following is a single row of
data or record in the CUSTOMERS table −

ID Name Age Salary City Country

1 Ramesh 32 2000.00 Hyderabad India

A record is a horizontal entity in a table.

What is a Column?
A column is a vertical entity in a table that contains all information associated with a
specific field in a table.

For example, our CUSTOMERS table have different columns to represent ID, Name, Age,
Salary, City and Country.

What is a NULL Value?


A NULL value in a table is a value in a field that appears to be blank, which means a field
with a NULL value is a field with no value.

It is very important to understand that a NULL value is different than a zero value or a
field that contains spaces. A field with a NULL value is the one that has been left blank
during a record creation. Following table has three records where first record has NULL
value for the salary and second record has a zero value for the salary.

ID Name Age Salary City Country

18
SQL Tutorial

1 Ramesh 32 Hyderabad India

2 Mukesh 40 00.00 New York USA

3 Sumit 45 4500.00 Muscat Oman

SQL Constraints
Constraints are the rules enforced on data columns on a table. These are used to limit the
type of data that can go into a table. This ensures the accuracy and reliability of the data
in the database.

Constraints can either be column level or table level. Column level constraints are applied
only to one column whereas, table level constraints are applied to the entire table.

Following are some of the most commonly used constraints available in SQL −

S.No. Constraints

NOT NULL Constraint


1
Ensures that a column cannot have a NULL value.

DEFAULT Constraint
2
Provides a default value for a column when none is specified.

UNIQUE Key
3
Ensures that all the values in a column are different.

PRIMARY Key
4
Uniquely identifies each row/record in a database table.

FOREIGN Key
5
Uniquely identifies a row/record in any other database table.

CHECK Constraint
6
Ensures that all values in a column satisfy certain conditions.

19
SQL Tutorial

INDEX Constraint
7
Used to create and retrieve data from the database very quickly.

Data Integrity
The following categories of data integrity exist with each RDBMS −

 Entity Integrity − This ensures that there are no duplicate rows in a table.

 Domain Integrity − Enforces valid entries for a given column by restricting the
type, the format, or the range of values.

 Referential integrity − Rows cannot be deleted, which are used by other records.

 User-Defined Integrity − Enforces some specific business rules that do not fall
into entity, domain or referential integrity.

Database Normalization
Database normalization is the process of efficiently organizing data in a database. There
are two reasons of this normalization process −

 Eliminating redundant data, for example, storing the same data in more than one
table.

 Ensuring data dependencies make sense.

Both these reasons are worthy goals as they reduce the amount of space a database
consumes and ensures that data is logically stored. Normalization consists of a series of
guidelines that help guide you in creating a good database structure.

Normalization guidelines are divided into normal forms; think of a form as the format or
the way a database structure is laid out. The aim of normal forms is to organize the
database structure, so that it complies with the rules of first normal form, then second
normal form and finally the third normal form.

It is your choice to take it further and go to the Fourth Normal Form, Fifth Normal Form
and so on, but in general, the Third Normal Form is more than enough for a normal
Database Application.

 First Normal Form (1NF)

 Second Normal Form (2NF)

 Third Normal Form (3NF)

20
4. SQL Databases SQL Tutorial

SQL Databases
SQL or Relational databases are used to store and manage the data objects that are related
to one another, i.e. the process of handling data in a relational database is done based on
a relational model.

This relational model is an approach to manage data in a structured way (using tables). A
system used to manage these relational databases is known as Relational Database
Management System (RDBMS).

SQL Database Table Structure


SQL database server stores data in table form. Tables are database objects used to collect
data in Row and Column format. Rows represent the entities whereas columns define the
attributes of each entity in a table.

Columns: Columns are vertical elements in a table. Each column in a table holds specific
attribute information, and column properties such as column name and data types
(Integer, Char, String, etc.).

Rows: Rows are horizontal elements in a table and users can add data or retrieve by
executing SQL queries.

Types of SQL Databases


There are many popular RDBMS available to work with. Some of the most popular RDBMS
are listed below −

 MySQL

 MS SQL Server

 ORACLE

 MS ACCESS

 PostgreSQL

 SQLite

This SQL databases tutorial gives a brief overview of these RDBMS specified above. This
would help you to compare their basic features.

MySQL
MySQL is an open source SQL database, which is developed by a Swedish company, MySQL
AB. MySQL is pronounced as "my ess-que-ell," in contrast with SQL, pronounced "sequel."

MySQL is supporting different platforms including Microsoft Windows, the major Linux
distributions, UNIX, and Mac OS X.

21
SQL Tutorial

MySQL has free and paid versions, depending on its usage (non-commercial/commercial)
and features. MySQL comes with a very fast, multi-threaded, multi-user and robust SQL
database server.

History

 1994 - Development of MySQL by Michael Widenius & David Axmark beginning in


1994.

 1995 - First internal released on 23rd May 1995.

 1998 - Windows Version was released on the 8 th January 1998 for Windows 95 and
NT.

 2001 - Version 3.23 released beta from June 2000, and production released in
January 2001.

 2003 - Version 4.0 was released on August 2002 as beta, and as production
released in March 2003 (unions).

 2004 - Version 4.1 was released on June 2004 as beta, and as production released
in October 2004.

 2005 - Version 5.0 was released on March 2005 as beta, and as a production
released in October 2005.

 2008 - Sun Microsystems acquired MySQL AB on the 26 th February 2008, and


Oracle Version 5.1 had its production released on 27th November 2008.

 2010 - Oracle acquired Sun Microsystems on 27 th January 2010 and general


availability of version 5.5 was released on 3rd December 2010.

 2013 - General availability of Version 5.6 was enabled on 5 th February 2013

 2015 - General availability of Version 5.7 was enabled on 21 st October 2015

 2018 - General availability of Version 8.0 was enabled on 19th April 2018, and is
the latest version of MySQL.

Features

 High Performance.

 High Availability.

 Scalability and Flexibility Run anything.

 Robust Transactional Support.

 Web and Data Warehouse Strengths.

 Strong Data Protection.

 Comprehensive Application Development.

 Management Ease.

 Open Source Freedom and 24 x 7 Support.

 Lowest Total Cost of Ownership.

22
SQL Tutorial

MS SQL Server
MS SQL Server is a Relational Database Management System developed by Microsoft Inc.
Its primary query languages are −

 T-SQL

 ANSI SQL

History

 1987 - Sybase releases SQL Server for UNIX.

 1988 - Microsoft, Sybase, and Aston-Tate ported SQL Server to OS/2.

 1989 - Microsoft, Sybase, and Aston-Tate released SQL Server 1.0 for OS/2.

 1990 - SQL Server 1.1 is released with support for Windows 3.0 clients.

 2000 - Microsoft released SQL Server 2000.

 2001 - Microsoft released XML for SQL Server Web Release 1 (download).

 2002 - Microsoft released SQLXML 2.0 (renamed from XML for SQL Server).

 2002 - Microsoft released SQLXML 3.0.

 2006 - Microsoft released SQL Server 2005 on January 14, 2006.

 2008 - Microsoft released SQL Server 2008 on November 6, 2008 and R2 version
was released on July 20, 2010.

 2012 - Microsoft released SQL Server 2012 on May 20, 2012.

 2014 - Microsoft released SQL Server 2014 on June 5, 2014.

 2016 - Microsoft released SQL Server 2016 on June 1, 2016.

 2017 - Microsoft released SQL Server 2017 on September 29, 2017.

 2019 - Microsoft released SQL Server 2019 on November 4, 2019.

 2022 - Microsoft released SQL Server 2022 on November 16, 2022.

Features

 High Performance

 High Availability

 Database mirroring

 Database snapshots

 CLR integration

 Service Broker

 DDL triggers

 Ranking functions

 Row version-based isolation levels

23
SQL Tutorial

 XML integration

 TRY...CATCH

 Database Mail

ORACLE
Oracle is a very large multi-user based database management system developed by
'Oracle Corporation'.

Oracle works to efficiently manage its resources, a database of information among the
multiple clients requesting and sending data in the network.

It is an excellent database server choice for client/server computing. Oracle supports all
major operating systems for both clients and servers, including MSDOS, NetWare,
UnixWare, OS/2 and most UNIX flavors.

History

Oracle began in 1977 and celebrating its 46 wonderful years in the industry (from 1977 to
2023).

 1977 - Larry Ellison, Bob Miner and Ed Oates founded Software Development
Laboratories to undertake development work.

 1979 - Version 2.0 of Oracle was released and it became first commercial relational
database and first SQL database. The company changed its name to Relational
Software Inc. (RSI).

 1981 - RSI started developing tools for Oracle.

 1982 - RSI was renamed to Oracle Corporation.

 1983 - Oracle released version 3.0, rewritten in C language and ran on multiple
platforms.

 1984 - Oracle version 4.0 was released. It contained features like concurrency
control - multi-version read consistency, etc.

 2007 - Oracle released Oracle11g. The new version focused on better partitioning,
easy migration, etc.

 2013 - Oracle Database 12c R1 version was released in July, 2013; and R2 version
was released on cloud in August 2016, and released on-premise in March 2017.

 2018 - Oracle Database 18c version was initially released in July 2018.

 2019 - Oracle Database 19c version was released in February 2019.

 2020 - Oracle Database 21c version was released in December 2020.

 2023 - Oracle Database 23c version was released in April 2023.

Features

 Concurrency

 Read Consistency

 Locking Mechanisms

24
SQL Tutorial

 Quiesce Database

 Portability

 Self-managing database

 SQL*Plus

 ASM

 Scheduler

 Resource Manager

 Data Warehousing

 Materialized views

 Bitmap indexes

 Table compression

 Parallel Execution

 Analytic SQL

 Data mining

 Partitioning

MS ACCESS
Microsoft Access is one of the most popular Microsoft products. It is an entry-level
database management software. It is not only inexpensive but also a powerful database
for small-scale projects.

MS Access uses the Jet database engine, which utilizes a specific SQL language dialect
(sometimes referred to as Jet SQL). It comes with the professional edition of MS Office
package. MS Access has easy to-use intuitive graphical interface.

 1992 - Access version 1.0 was released.

 1993 - Access 1.1 released to improve compatibility with inclusion the Access Basic
programming language.

 The most significant transition was from Access 97 to Access 2000.

 2007 - Access 2007, a new database format was introduced ACCDB which supports
complex data types such as multi valued and attachment fields.

 2010 - Microsoft Access 2010 introduced a new version of the ACCDB format
supported hosting Access Web services on a SharePoint 2010 server.

 2013 - Microsoft Access 2013 offers traditional Access desktop applications plus a
significantly updated SharePoint 2013 web service

 2021 - Microsoft Access is no longer included in one-time purchase version of


Microsoft Office 2021, but remains within the Microsoft 365 counterpart.

Features

25
SQL Tutorial

 Users can create tables, queries, forms and reports and connect them together with
macros.

 Option of importing and exporting the data to many formats including Excel,
Outlook, ASCII, dBase, Paradox, FoxPro, SQL Server, Oracle, ODBC, etc.

 There is also the Jet Database format (MDB or ACCDB in Access 2007), which can
contain the application and data in one file. This makes it very convenient to
distribute the entire application to another user, who can run it in disconnected
environments.

 Microsoft Access offers parameterized queries. These queries and Access tables can
be referenced from other programs like VB6 and .NET through DAO or ADO.

 The desktop editions of Microsoft SQL Server can be used with Access as an
alternative to the Jet Database Engine.

 Microsoft Access is a file server-based database. Unlike the client-server relational


database management systems (RDBMS), Microsoft Access does not implement
database triggers, stored procedures or transaction logging.

PostgreSQL
PostgreSQL is object relational database management system (ORDBMS) that supports
both relational (SQL) and non-relational (JSON) query. It is a highly stable database that
is developed based on the POSTGRES, version 4.2 released by the Computer Science
Department in University of Berkeley, California. This database is a popular database or
data warehouse for many applications.

History

 1970s - Ingres was being developed in Computer Science department of University


of Berkeley as a research project which ended in 1985.

 1985 - A post-Ingres project, namely POSTGRES, has been initiated to address the
issues in the older database systems. This project aimed to fully support datatypes
and define them to establish relationships between the objects of the database.
POSTGRES was also able to retrieve data using rules.

 1989 - POSTGRES Version 1 was released to the small number of users.

 1990 - POSTGRES Version 2 was released again with rewritten rules.

 1994 - With the increase in users, POSTGRES Version 4.2 was released, ending the
project with it.

 1994 - Andrew Yu and Jolly Chen, students of University of Berkeley, replaced the
POSTQUEL query language that run POSTGRES, with the SQL language, creating
Postgres95.

 1995 - Postgres95's first version was released with a more liberal license.

 1996 - The project was renamed to PostgreSQL to support SQL.

 1997 - The first version of PostgreSQL version 6.0 was released.

 Since then, next versions of the project are released as free and open-source
software PostgreSQL License.

26
SQL Tutorial

 2000 - PostgreSQL version 7.0 was released on July 8th, 2000. This version had
the most changes in features until then. Major changes made are as follows:

o foreign keys were implemented

o optimizer had been improved

o psql had been updated

o JOIN syntax is now supported.

 2005 - The version 8.0 was released on January 19th, 2005. Changes in this version
include, the server can now be run on Microsoft natively, savepoints were
introduced, Point-in-time recovery, tablespaces, improved buffer management,
checkpoints, changing column types was introduced, etc.

 2010 - PostgreSQL version 9.0 was released on 20th September, 2010.

 2017 - Version 10.0 was released on 5th October, 2017. Major improvements
include: logical replication, declarative table partitioning, improved query
parallelism, significant improvements in general performance, etc.

 2018 - PostgreSQL version 11.0 was released on 18th October, 2018.

 2019 - PostgreSQL version 12.0 was released on 3rd October, 2019.

 2020 - PostgreSQL version 13.0 was released on 24th September, 2020.

 2021 - PostgreSQL version 14.0 was released on 30th September, 2021.

 2022 - PostgreSQL version 15.0 was released on 13th October, 2022.

Features

 PostgreSQL supports advanced data types.

 It possesses high levels of resilience, integrity and correctness of the data.

 It contains Multi-Version Concurrency Control (MVCC)

 Point in time recovery

 Granular Access Controls

 Asynchronous Replication

 Nested transactions

 Online backups

 Refined query optimizer

 Write ahead logging

 It supports international character sets, multi-byte character encodings, Unicode.

 It is locale-aware for sorting, case-sensitivity, and formatting.

 Highly scalable.

SQLite

27
SQL Tutorial

SQLite is an embedded relational database system. It is referred to as a lightweight


database as it is not more than 500kB in size, which is way less than other relational
databases. This database is an in-memory open source library; which is why it can access
the files stored in it directly and the source code for it is available in the public domain.

History

 2000 - SQLite 1.0 was released with GNU Database Manager. Dr. Richard Hipp
designed it in the same year to create a database that requires no administration.

 2001 - SQLite 2.0 was released which contained a custom B-Tree implementation
instead of GNU Database Manager, adding transaction capability to the database.

 2003 - SQLite 3.0 was released with major improvements like internalization,
manifest typing etc.

 2011 - Hipp announced his plans to introduce a non-relational interface to SQLite.

 2018 - SQLite adopted the Code of Conduct from the Rule of Saint Benedict which
was later renamed as Code of Ethics due to some controversies.

 Despite such controversies, newer versions of SQLite 3.x are being released
continuously with better features and improvements.

 2023 - The latest version of SQLite is 3.42.0 which was released on 16th July,
2023.

Features

 SQLite is an open source library written in ANSI C.

 It works on cross-platforms, making it easier to port to other systems.

 The source code for SQLite is available in public domain.

 Transactions in SQLite are atomic, consistent, isolated and durable even when the
system crashes for any reason.

 This database does not need any configuration or administration.

 SQLite is server less, unlike other relational databases. It is linked with application
that accesses it. The application directly interacts with the SQLite to read and write
on files stored in the disk.

 It has a simple and easy to use API.

 In some cases, SQLite is faster than directs filesystem I/O operations.

 SQLite is self-contained, i.e. it is not dependent on any external libraries or


operating systems.

 Uses a stand-alone command line interface (CLI) client to administer SQLite.

Benefits of using SQL Database


Relational databases are the most popular and preferred databases used for data storage.
There are many benefits to using SQL database, including:

Enhanced Flexibility
28
SQL Tutorial

Relational databases utilize Data Definition Language (DDL) to modify data stored in tables
in real time. The most important thing users can easily add are new tables and columns,
rename, and implement various changes without disrupting ongoing database operations.

Data Consistency
Data Consistency is another important benefit of using SQL databases because it maintains
data consistency across applications and server instances.

Minimum Data Redundancy


Relational Database Management Systems (RDBMS) use the normalization process to
reduce data redundancy. This approach eliminates anomalies in Data stored in the
Database.

Optimized Performance
Relational databases offer a range of value-added features that boast minimal memory
usage, reduced storage costs, and high processor speed.

Higher Compatibility
Relational databases offer higher compatibility for integration with modern technologies.

Scalability
Higher scalability is another feature that makes Relational databases most preferred.

==========
End of ebook preview
If you liked what you saw…
Buy it from our store @ https://www.tutorialspoint.com/index.htm

29

You might also like