User:Rushilrr121/sandbox

= Query =

Definition - What does Query mean?
A query is a request for data or information from a database table or combination of tables. This data may be generated as results returned by Structured Query Language (SQL) or as pictorials, graphs or complex results, e.g., trend analyses from data-mining tools.

One of several different query languages may be used to perform a range of simple to complex database queries. SQL, the most well-known and widely-used query language, is familiar to most database administrators (DBAs).

The query database feature is equal in necessity to data storage capability. Thus, a number of query languages have been developed for different database engines and purposes, but SQL is by far the most ubiquitous and well-known. In fact, rookie database administrators often are surprised when they learn about the existence of other query languages, somewhat akin to how native English-speaking children are perplexed when hearing a foreign language for the first time. The element of surprise in both scenarios leads to a better understanding of other languages.

Query languages generate different data types according to function. For example, SQL returns data in neat rows and columns and is very similar to Microsoft Excel in appearance.

= Introduction to SQL = Structure Query Language(SQL) is a database query language used for storing and managing data in Relational DBMS. SQL was the first commercial language introduced for E.F Codd's Relational model of database. Today almost all RDBMS(MySql, Oracle, Infomix, Sybase, MS Access) use SQL as the standard database query language. SQL is used to perform all types of data operations in RDBMS.

SQL Command
SQL defines following ways to manipulate data stored in an RDBMS.

DDL: Data Definition Language
This includes changes to the structure of the table like creation of table, altering table, deleting a table etc.

All DDL commands are auto-committed. That means it saves all the changes permanently in the database.  Syntax for these commands are as follows :

1) Create Statement:

 * Creating a database:


 * Creating a table: Note: Constraints(such as primary key, null, not null, etc.) are optional and not necessary for table creations whereas column name and its datatype must be defined for each column you enter while using the create statement.

2) Alter statement:

 * Altering a table by adding a column to it:
 * Altering a table by altering/modifying (changing datatype of) a column in it. Note: Oracle(prior to version 10G ) and MySQL have the keyword MODIFY COLUMN instead of ALTER COLUMN and Oracle version 10G onward has the keyword MODIFY instead of ALTER COLUMN.
 * Altering a table by dropping/deleting a column: Note: Some database systems don't allow column deletion.

3) Truncate statement:

 * Delete data from table but not the table itself:

4) Drop statement:

 * Removes the entire table:

5) Rename statement:

 * Rename a table:

DML: Data Manipulation Language
DML commands are used for manipulating the data stored in the table and not the table itself.

DML commands are not auto-committed. It means changes are not permanent to database, they can be rolled back.


 * Select specific columns from a table:
 * Select specific columns from a table:

2) Insert statement:

 * Inserting values for all columns in table:
 * Inserting values in specific columns:

3) Update statement:

 * Modify existing records in a table: Note: If the WHERE clause is not mentioned; all the values of the column will be changed.

4)Delete Statement:

 * Delete an existing row/record from a table: Note: If the WHERE clause is not mentioned; all the records will be deleted.

TCL: Transaction Control Language
These commands are to keep a check on other commands and their affect on the database. These commands can annul changes made by other commands by rolling the data back to its original state. It can also make any temporary change permanent.  Syntax for these commands are as follows: 

1) Commit Statement:

 * To save changes permanently:

2) Rollback statement:

 * To undo changes:

3) Savepoint statement:

 * Rollback to a certain savepoint instead of rolling back all the prior changes:

DCL: Data Control Language
Data control language are the commands to grant and take back authority from any database user.

DQL: Data Query Language
Data query language is used to fetch data from tables based on conditions that we can easily apply.

1) Select statement:

 * Select all columns from a table:


 * Select specific columns from a table: