SQL Example, Codes and Tutorials
Collection of SQL tutorials for beginners and advance programmers. We have developed many tutorials and examples on SQL. Here you will find everything to get started with SQL and then learn the advance concepts of SQL. The Standard Query Language or SQL for short is standard language to interact with the database. SQL allows you to create, delete, update tables and data stored in the table. SQL provides everything to help the programmer to interact with database and develop enterprise applications.
In this tutorial you will learn how to you user SQL to interact with database. We have used MySQL database to make the process simple. You can easily download MySQL from mysql.com and install on your machine to experiment and learn the SQL concepts.
The Tutorial brings a unique introduction on SQL for beginners, who want to learn and understand SQL.
|SQL: A brief Introduction
SQL stands for Structured Query Language. It is easy and allows us to create a database.
|SQL Join||Mysql Alter|
|Online Mysql Training||SQL Functions|
|MySql Example||MySql Remove|
|MySql Table||MySql Update|
General SQL Concepts:
Following articles/examples are used frequently while interacting with the databases. Learn SQL concepts by reading the following tutorials.
- Data Normalization
In this section we will learn about the concepts of data normalization. The most important thing in database designing is to make sure that the data get properly distributed among the tables.
- Create a database
we can create a database by using the Database name. In SQL the key word 'Show databases' finds the existing databases. You may create your own or use an existing one after that create connection with database.
- The INSERT INTO Statement
To insert records into a table, use the key word insert into 'table name', just write a list of column names separated by commas, followed by a closing parenthesis then using keyword values, write the list of values enclosed in parenthesis.
- The UPDATE Statement
The UPDATE statement is used to modify the data in the database table in a specified manner. In the syntax of update statement the keyword 'set' is used to assign a new value to a selected column. The statement is accomplished by a where clause.
- The DELETE Statement
The DELETE statement is used to delete rows in a table. database will update that is why deletion and insertion of data will be done.
SELECT key word is used to select data from a table. The tabular result is stored in a result set. SELECT column_name give the path FROM table_name
The WHERE Clause
WHERE clause is used with the SELECT keyword. 'Where' is a clause which is used for searching the data with a particular condition.
- The Aggregate Functions
In this section we are going to illustrate aggregate function, with the help of which we can use many arithmetic operation like average, count, maximum and many more in SQL.
- SQL % Wildcards
SQL wildcards used for searching one or more characters from data in a database.
- SQL UNIQUE Constraint
The UNIQUE constraint uniquely identifies each record in a database table.
- SQL UNION ALL Operator
The SQL UNION ALL Operator is used to list all records from two or more select statements.
- SQL UNION Operator
The UNION operator is used to combine the result-set of two or more SELECT statements.
- SQL Right JOIN
The RIGHT JOIN keyword returns you all rows from the right table (table_name1), incase if there are no matches in the left table (table_name2).
- SQL IN Operator
SQL IN Operator helps you to specify multiple values in a WHERE Clause.
- SQl Date
The SQL Date is used when you are working with dates. This include the format of data ,the insert value matches the format of the data column in the database.
- SQL Create View
A View is a imaginary and virtual table in SQL. In SQL, a view is defined as a virtual table outcome as a result of an SQL statement.
- SQL BETWEEN Operator
The SQL Between Operator works where you want to select a range of data between two values.
- SQL as Keyword
The SQL Key word used in SQL are createTable,Insert into,select,delete,update,etc.
- SQL And Statement
The SQL AND operator is used to show you the filter records based upon conditions
- SQL AND Operators
The AND operator displays records if both conditions are true.
- SQL AND Like Operator
The SQL AND Like Operator work with WHERE clause to find and search for a specified pattern in a column of table.
- SQL Alter View
In SQL Alter View is used to modify a previous created view.
- SQL Alter Table Name
SQL Alter Table Name is used to change or modify name of the existing table.
- SQL Alter Column type
Alter Column type in SQL is used to change or recreate the data type of existing column.
- SQL Alter Column Size
Alter Column Size modify the Column Size. The SQL Alter Column Size is used when you want to change the data type size.
- SQL Alter Column Not Null
The Column Not Null in SQL is used when you want the column should not be null in your table.
- SQL Alter Column Name
Alter Column Name in SQL is used to change or modify the name of column in a table.
- SQL Alter Column Default
Alter Column Default Value in SQL Server is used with Create Table Statement. The default value will be set as per specified column.
- SQL Alter Column
SQL Alter Column modifies the existing table and add a column.
- SQL Alias
SQL Alias is the another name given to the existing table and the column.
- SQL Add Column Position
SQL Add Column Position is used to add the column at the specific position.
- SQL Add Column Int
SQL Add Column Int is used to add new column, whose field data type is integer.
- SQL add column default value
Add a Column default value is used in SQL, When create statement Query is performed in SQL .Usually, the default value is given to the column ,when no value is inserted to the column .
- SQL Add Column
SQL Add Column is used to add a new column in the existing table.
- SQL _ Wildcards
SQL wildcards used for searching one or more characters from data in a database.
- LIKE Operator
The LIKE operator is used for searching a specified pattern in the column.
- SQL SELECT DISTINCT
In this example we will show you the usage of Distinct clause with the select statement. The SQL Distinct clause is used with the Select statement to show all unique records from database.
- SQL LEFT JOIN
The LEFT JOIN keyword retrieve all rows from the left table (table_name1), even if there are no matches in the right table (table_name2).
- SQL NOT NULL Constraint
The NOT NULL constraint enforces a column to NOT accept NULL values.
- SQL ORDER BY
The ORDER BY keyword is used to sort the table result set by a specified column. If you want to sort the records in ascending order, you can use the ASC keyword.
- SQL OR Operators
The OR operator displays records if any of the conditions is true.
- SQL PRIMARY KEY Constraint
The PRIMARY KEY constraint is used to uniquely identifies each record in a database table.
- SQL INNER Joins
The JOIN keyword is used in SQL statement to query data from two or more tables, based on a relationship between certain columns in these tables.
- SQL Alias
In SQL we can give a table or column another name by using an Alias.
- Using while loop to loop through a cursor
Cursor in SQL is used to define a set of data rows and perform complex logic on each row by row basis.
- Variables Scope in SQL Procedure
Variable Scope in SQL Procedure is used to define the scope of a variable used in SQL.
- Use DEFAULT Statement in Procedure
The Tutorial illustrate an example 'Use DEFAULT Statement in Procedure'.
- Use DECLARE Statement in Procedure
Use DECLARE Statement in Procedure is used to define variable and its data type.
- Until Loop In a Procedure
Until Loop In a Procedure is used to execute a set of statements repeatedly until a certain condition is reached.
- SQL IN Parameters
A parameter is a placeholder that accept a user-defined value, whenever stored procedure is executed.
- SQL Out Parameter
SQL Out Parameter allows the stored procedure to the pass data value back to the invoker.
- SQL Bulk Insert Example
SQL Bulk Insert Example is used to insert a bulk record to the table.
- SQL Backup Table
The Select Statement is used to create backup copies of tables.
- SQL Backup query with where statement
The Where Clause in Backup query return you the restricted records into stu_tab_ Backup specified in table 'Stu_Table'.
- Simple Procedure to display Hello World
Procedure is a set of SQL statement enclosed in 'BEGIN' and 'END' statement and executed under one name.
- Insert Data From File
Insert Data From File is used to insert data from file.
- Use HANDLER Statement in Cursors
Use HANDLER Statement in Cursor is used to define a set of data rows where we perform operation on a row by row basis.
- Close Cursors in SQL
Close Cursor is used to close the cursor temporary when it is not required.
- Declare Cursors in SQL
Declare Cursors in SQL is used to define cursor and its characteristics.
- Creating Cursors in SQL
Creating Cursor in SQL is used to create a cursor in SQL.
- Close Cursors in SQL
Close Cursors is used to close the Cursor temporary, when the open cursor is not required.
- Use if statement with LOOP statement
Conditional if statements in SQL are used to perform different actions based on different conditions.
- SQL UCASE Function
The UCASE function help you to converts the fields value into the uppercase.
SQL Simple LOOP
Simple LOOP in Procedure is a series of statement that are executed repeatedly until it push the flow of control to outside of the loop.
- SQL ROUND Function
Round Function in SQL is used to round a numeric field to the nearest decimals specified.
- SQL NOW() Function
NOW ( ) Function provides you the current date and time according to your computer's system date and time.
- SQL Length Function
Length Function in SQL is used to return the length of a column, string or variable in bytes or characters.
- SQL LCASE Function
The LCASE function converts the fields value into the lowercase.
- SQL HAVING Clause
Having clause is used with the select clause to specify a search condition for a group or aggregate.
- SQL Between Timestamp
A timestamp is used to catch the dates and times.
- SQL Between Datetime
The Date Time structure tell you an instant in time, hold both date and a time.
- SQL Between Date
The Tutorial help you to understand SQL Between Date.
- SQL Begin End
Begin End in SQL include the set of select statement executed within these blocks.
- SQL Avg Group By
SQL Avg Group By helps you to find out average value of numeric field in a table.
- SQL Average Count
Average Count in SQL is used to count the aggregate sum of any field in a table.
- SQL Alter Table Primary Key
Alter a Table Primary Key in SQL modifies the existing table and adds a primary key.
- SQL Alter Table Add Multiple Columns
Alter Table Add Multiple Columns in SQL modifies the table and add columns to the existing table.
- SQL Aggregate Sum
The SQL Aggregate Sum Function is a part of Aggregate Function that is used to compute sum of the numeric field in a table.
- SQL Aggregate Max
SQL Aggregate Max is used to find the highest value of the column in a table.
- SQL Aggregate Functions Group By
SQL Aggregate Functions Group By return the aggregate functions (like SUM) of the different numeric field for each individual group of column values.
- SQL Aggregate Functions First
SQL Aggregate Function First, that performs calculation of data. The SQL aggregate function retrieve a single value, by calculate from values in a column.
- SQL Aggregate Functions In Where Clause
SQL Aggregate Function In Where Clause return the maximum conditional value of the record from a table.
- SQL Aggregate Concatenate
SQL Aggregate Concatenate provides you a concatenated record of the field based on the conditional operator WHERE clause.
- Drop Table
Drop Table in SQL get rid of an object or table from the database.
- Drop Index
Drop Index is used to remove one or more indexes from the current database.
- Create After Update Trigger in SQL
After Trigger in SQL is fired before update the column in the table.
- Create a Simple Procedure
Simple Procedure is a set of SQL statement which are executed under one name.
- Create Delete Trigger in SQL
Create Delete Trigger in SQL fire this trigger before the DELETE operation is executed.
- Create Before Update Trigger in SQL
Create Before Update Trigger in SQL is used in SQL, if a trigger monitoring for changes to a column of the table.
- Create Before Insert Trigger in SQL
The Create Before Insert Trigger in SQL fires the trigger before we insert the value into the table.
- Create After Insert Trigger in SQL
Create a Trigger is a special kind of stored procedure, that fires when we perform modification on the specific data on the specified table.
- Call Procedure
Procedure is a set of SQL statement that perform a logical unit and task.
- Backup selected records into txt file
Backup selected records into txt file is used to copies the selected records or rows from a table into text file.
- Backup Into txt File
Backup Into txt File is used to put the backup file from a table into a text File.
- Backup File With Separator
Backup File With Separator in SQL is used to indicate line and record separator.