Your cart is currently empty!
Category: sql
-
Khóa học miễn phí SQL – Home nhận dự án làm có lương
SQL Tutorial
Table of content
SQL 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 a 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
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 .
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 a computer language which is used to create and modify the structure of database objects which include tables, views, schemas, and indexes etc.
Command Description Demo CREATE Creates a new table, a view of a table, or other object in the database. ALTER Modifies an existing database object, such as a table. DROP Deletes an entire table, a view of a table or other objects in the database. TRUNCATE Truncates the entire table in a go. Demo Data Manipulation Language (DML)
A Data Manipulation Language (DML) is a computer programming language which is used for adding, deleting, and modifying data in a database.
Command Description Demo SELECT Retrieves certain records from one or more tables. INSERT Creates a record. UPDATE Modifies records. DELETE Deletes records. Data Control Language (DCL)
Data Control Language (DCL) is a computer programming language which 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.
SQL Applications
SQL is one of the most widely used Query Language over the databases. SQL provides following functionality to the database programmers −
-
Execute different database queries against a database.
-
Define the data in a database and manipulate that data.
-
Create data in a relational database management system.
-
Access data from the relational database management system.
-
Create and drop databases and tables.
-
Create and maintain database users.
-
Create view, stored procedure, functions in a database.
-
Set 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 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 applicatipon 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 type of questions and their answers with short explanation.
Following is a sample quiz, try to attempt any of the given answers:
Q 1 – The SQL programming language was developed by which of the following:
Answer : C
Explanation
The SQL programming language was developed in the 1970s by IBM researchers Raymond Boyce and Donald Chamberlin.
Start your online 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:
- Amazon
- Netflix
- Infosys
- TCS
- Tech Mahindra
- Wipro
- 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.
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.
There are 5 main types of commands. DDL (Data Definition Language) commands, DML (Data Manipulation Language) commands, and DCL (Data Control Language) commands, Transaction Control Language(TCL) commands and Data Query Language(DQL) commands.
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.
SQL queries are also more flexible and powerful than Excel formulas and SQL is fast which can handle large amount of data. Unlike Excel, SQL can handle well over one million fields of data with ease.
Here are 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 begining.
- 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.
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.
Following are following three SQL data types.
- String Data types.
- Numeric Data types.
- Date and time Data types.
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 .
Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc
-
Khóa học miễn phí SQL – RDBMS Concepts nhận dự án làm có lương
SQL – RDBMS Concepts
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 a database management system (DBMS) that 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 |
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 |
---|---|---|---|---|---|
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 |
---|---|
1 |
Ensures that a column cannot have a NULL value. |
2 |
Provides a default value for a column when none is specified. |
3 |
Ensures that all the values in a column are different. |
4 |
Uniquely identifies each row/record in a database table. |
5 |
Uniquely identifies a row/record in any another database table. |
6 |
Ensures that all values in a column satisfy certain conditions. |
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.
Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc