7
SQL tutorial gives unique learning on Structured Query Language and it helps to make practice on SQL commands which provides immediate results. SQL is a language of database, it includes database creation, deletion, fetching rows and modifying rows etc. SQL is an ANSI (American National Standards Institute) standard but there are many different versions of the SQL language. What is SQL? SQL is structured Query Language which is a computer language for storing, manipulating and retrieving data stored in relational database. SQL is the standard language for Relation Database System. All relational database management systems like MySQL, MS Access, Oracle, Sybase, Informix, postgres and SQL Server uses SQL as standard database language. Also they are using different dialects, Such as: MS SQL Server using T-SQL, Oracle using PL/SQL, MS Access version of SQL is called JET SQL (native format )etc Why SQL? Allow users to access data in relational database management systems. Allow users to describe the data. Allow users to define the data in database and manipulate that data. Allow to embed within other languages using SQL modules, libraries & pre- compilers. Allow users to create and drop databases and tables. Allow users to create view, stored procedure, functions in a database. Allow users to set permissions on tables, procedures, and views History: 1970 -- Dr. E.F. "Ted" of IBM is known as the father of relational databases. He described a relational model for databases. 1974 -- Structured Query Language appeared. 1978 -- IBM worked to develop Codd's ideas and released a product named System/R.

sql.doc

Embed Size (px)

Citation preview

SQL tutorial gives unique learning on Structured Query Language and it helps to make practice on SQL commandswhich provides immediate results. SQL is a language of database, it includes database creation, deletion, fetchingrows and modifying rows etc.SQL is an ANSI (American National Standards Institute) standard but there are many diferent versions of the SQLlanguage.What is SQL?SQL is structured Query Language which is a computer language for storing, manipulating and retrieving data storedin relational database.SQL is the standard language for Relation Database System. All relational database management systems likeMySQL, MS Access, Oracle, Sybase, Informix, postgres and SQL Server uses SQL as standard database language.Also they are using diferent dialects, Such as: MS SQL Server using T-SQL, Oracle using PL/SQL, MS Access version of SQL is called JET SQL (native format )etcWhy SQL? Allow users to access data in relational database management systems. Allow users to describe the data. Allow users to defne the data in database and manipulate that data. Allow to embed within other languages using SQL modules, libraries & pre-compilers. Allow users to create and drop databases and tables. Allow users to create view, stored procedure, functions in a database. Allow users to set permissions on tables, procedures, and viewsHistory: 1970 -- Dr. E.F. "Ted" of IBM is known as the father of relational databases. He described a relational modelfor databases. 1974 -- Structured Query Language appeared. 1978 -- IBM worked to develop Codd's ideas and released a product named System/R. 1986 -- IBM developed the frst prototype of relational database and standardized by ANSI. The frstrelational database was released by Relational Software and its later becoming Oracle.SQL Process:When you are executing an SQL command for any RDBMS, the system determines the best way to carry out yourrequest and SQL engine fgures out how to interpret the task.There are various components included in the process. These components are Query Dispatcher, Optimizationengines, Classic Query Engine and SQL query engine etc. Classic query engine handles all non-SQL queries butSQL query engine won't handle logical fles.Following is a simple digram showing SQL Architecture:SQL Commands:The standard SQL commands to interact with relational databases are CREATE, SELECT, INSERT, UPDATE,DELETE, and DROP. These commands can be classifed into groups based on their nature:DDL - Data Defnition Language:Command DescriptionCREATE Creates a new table, a view of a table, or other object in databaseALTER Modifes an existing database object, such as a table.DROP Deletes an entire table, a view of a table or other object in the database.DML - Data Manipulation Language:Command DescriptionINSERT Creates a recordUPDATE Modifes recordsDELETE Deletes recordsDCL - Data Control Language:Command DescriptionGRANT Gives a privilege to userREVOKE Takes back privileges granted from userDQL - Data Query Language:Command DescriptionSELECT Retrieves certain records from one or more tablesWhat is RDBMS?RDBMS stands for Relational Database Management System. RDBMS is the basis for SQL, and for all moderndatabase 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 onthe relational model as introduced by E. F. Codd. What is table ?The data in RDBMS is stored in database objects called tables. The table is a collection of related data entries and itconsists of columns and rows.Remember, a table is the most common and simplest form of data storage in a relational database. Following is theexample of a CUSTOMERS table:+----+----------+-----+-----------+----------+| ID | NAME | AGE | ADDRESS | SALARY |+----+----------+-----+-----------+----------+|1 | Ramesh |32 | Ahmedabad |2000.00 ||2 | Khilan |2 | Delhi |100.00 ||3 | !a"shi!|23 | K#$a|2000.00 ||% | &hai$ali |2 | M"mbai|'00.00 || | (a)di! |2* | +h#,al|-00.00 ||' | K#mal|22 | M.|%00.00 ||* | M"//0|2% | Ind#)e| 10000.00 |+----+----------+-----+-----------+----------+What is feld?Every table is broken up into smaller entities called felds. The felds in the CUSTOMERS table consist of ID, NAME,AGE, ADDRESS and SALARY.A feld is a column in a table that is designed to maintain specifc information about every record in the table.What is record, or row?A record, also called a row of data, is each individual entry that exists in a table. For example there are 7 records inthe above CUSTOMERS table. Following is a single row of data or record in the CUSTOMERS table:+----+----------+-----+-----------+----------+|1 | Ramesh |32 | Ahmedabad |2000.00 |+----+----------+-----+-----------+----------+A record is a horizontal entity in a table.What is column?A column is a vertical entity in a table that contains all information associated with a specifc feld in a table.For example, a column in the CUSTOMERS table is ADDRESS which represents location description and wouldconsist of the following:+-----------+| ADDRESS |+-----------+| Ahmedabad || Delhi || K#$a|| M"mbai|| +h#,al|| M.|| Ind#)e|+----+------+What is NULL value?A NULL value in a table is a value in a feld that appears to be blank which means A feld with a NULL value is a feldwith no value.It is very important to understand that a NULL value is diferent than a zero value or a feld that contains spaces. Afeld with a NULL value is one that has been left blank during record creation.SQL Constraints:Constraints are the rules enforced on data columns on table. These are used to limit the type of data that can go intoa table. This ensures the accuracy and reliability of the data in the database. Contraints could be column level or table level. Column level constraints are applied only to one column where astable level constraints are applied to the whole table.Following are commonly used constraints available in SQL: NOT NULL Constraint: Ensures that a column cannot have NULL value. DEFAULT Constraint : Provides a default value for a column when none is specifed. UNIQUE Constraint: Ensures that all values in a column are diferent. PRIMARY Key: Uniquely identifed each rows/records in a database table. FOREIGN Key: Uniquely identifed a rows/records in any another database table. CHECK Constraint: The CHECK constraint ensures that all values in a column satisfy certain conditions. INDEX: Use to create and retrieve data from the database very quickly.Data Integrity:The following categories of the data integrity exist with each RDBMS: Entity Integrity : 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 rangeof values. Referential integrity : Rows cannot be deleted, which are used by other records. User-Defned Integrity : Enforces some specifc business rules that do not fall into entity, domain, orreferential integrity.Database NormalizationDatabase normalization is the process of efciently organizing data in a database. There are two reasons of thenormalization process: Eliminating redundant data, for example, storing the same data in more than one tables. Ensuring data dependencies make sense.Both of these are worthy goals as they reduce the amount of space a database consumes and ensure that data islogically stored. Normalization consists of a series of guidelines that help guide you in creating a good databasestructure.Normalization guidelines are divided into normal forms; think of form as the format or the way a database structure islaid out. The aim of normal forms is to organize the database structure so that it complies with the rules of frst normalform, then second normal form, and fnally third normal form.It's your choice to take it further and go to fourth normal form, ffth normal form, and so on, but generally speaking,third normal form is enough. First Normal Form (1NF) Second Normal Form (2NF) Third Normal Form (3NF)