overview of sql basics part 1 - by software outsourcing company india
TRANSCRIPT
Prepared By:Mr. Dhrumil Patel
iFour Consultancy
Basics of SQL
Introduction to SQL
What is SQL?
SQL is a standard language for accessing databases. SQL stands for Structured Query Language. SQL lets you access and manipulate databases. Nonprocedural language. SQL is an ANSI (American National Standards Institute) standard.
•A markup language is a set of markup tags •A markup language is a set of markup tags
eCommerce Solution Provider In Indiahttp://www.ifourtechnolab.com
Database
A database is an organized collection of data, typically stored in electronic format:It allows you to input, manage, organize, and retrieve data quicklyTraditional databases are organized by records (rows), fields (columns) stored in tables
which are stored in the database filesDatabases support storage and manipulation of data. Databases make data management easy.
•A markup language is a set of markup tags •A markup language is a set of markup tags
eCommerce Solution Provider In Indiahttp://www.ifourtechnolab.com
Table in SQL
A database table is a collection of rows and columns that is used to organize information about a single topic. Each row within a table corresponds to a single record and contains several attributes that describe the row.
These tables are stored in databases.
eCommerce Solution Provider In Indiahttp://www.ifourtechnolab.com
SQL
Data Definition Language (DDL)SQL includes commands to:
Create database objects, such as tables, indexes, and viewsDefine access rights to those database objects
Data Manipulation Language (DML)Includes commands to insert, update, delete, and retrieve data within database tables
eCommerce Solution Provider In Indiahttp://www.ifourtechnolab.com
SQL (Cont.)
SQL Data Definition Commands:
COMMAND OR OPTION DESCRIPTIONCREATE SCHEMA AUTHORIZATION CREATE TABLE NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY DEFAULT CHECK CREATE INDEX CREATE VIEW ALTER TABLE CREATE TABLE AS DROP TABLE DROP INDEX DROP VIEW
Creates a database schema.Creates a new table in the user’s database schema.Ensures that a column will not have null values.Ensures that a column will not have duplicate values.Defines a primary key for a table.Defines a foreign key for a table.Defines a default value for a column (when no value is given).Constraint used to validate data in an attribute.Creates an index for a table.Creates a dynamic subset of rows/columns from one or more tables.Modifies a table's definition (adds, modifies, or deletes attributes or constraints).Creates a new table based on a query in the user's database schema.Permanently deletes a table (and thus its data).Permanently deletes an index.Permanently deletes a view.
eCommerce Solution Provider In Indiahttp://www.ifourtechnolab.com
SQL (Cont.) SQL Data Manipulation Commands:
COMMAND OR OPERATION DESCRIPTION
INSERT Inserts row(s) into a table.
SELECTWHEREGROUP BYHAVINGORDER BY
Selects attributes from rows in one or more tables or views.Restricts the selection of rows based on a conditional expression.Groups the selected rows based on one or more attributes.Restricts the selection of grouped rows based on a condition.Orders the selected rows based on one or more table’s rows.
UPDATE Modifies an attribute’s values in one or more table’s rows.
DELETE Deleted one or more rows from a table.
COMMIT Permanently saves data changes.
ROLLBACK Restores data to their original values.
eCommerce Solution Provider In Indiahttp://www.ifourtechnolab.com
SQL (Cont.)
COMPARISON OPERATION =,<,>,<=,>=,<> Used in conditional expressions.
LOGICAL OPERATION AND/OR/NOT Used in conditional expressions.
SPECIAL OPERATION BETWEEN IS NULL LIKE IN EXISTS DISTINCT
Used in conditional expressions.Checks whether an attribute value is within a range.Checks whether an attribute value is null.Checks whether an attribute value matches a given string pattern.Checks whether an attribute value matches any value within a value list.Checks whether a subquery returns any rows.Limits values to unique values.
Aggregate Functions COUNT MIN MAX SUM AVG
Used with SELECT to return mathematical summaries on columns.Returns the number of rows with non-null values for a given column.Returns the minimum attribute value found in a given column.Returns the maximum attribute value found in a given column.Returns the sum of all values for a given column.Returns the average of all values for a given column.
eCommerce Solution Provider In India
Data Types A data type defines what kind of value a column can contain. Data type selection is usually dictated by nature of data and by intended use Pay close attention to expected use of attributes for sorting and data retrieval purposes
eCommerce Solution Provider In Indiahttp://www.ifourtechnolab.com
Data Types (Cont.)
Character CHAR(L)
VARCHAR(L) orVARCHAR2(L)
Fixed-length character data for up to 255 characters. If you store strings that are not as long as the CHAR parameter value, the remaining spaces are left unused. Therefore, if you specify CHAR(25), strings such as "Smith" and "Katzenjammer" are each stored as 25 characters. However, a U.S. area code is always three digits long, so CHAR(3) would be appropriate if you wanted to store such codes.
Variable-length character data. The designation VARCHAR2(25) will let you store characters up to 25 characters long. However, VARCHAR will not leave unused spaces. Oracle users may use VARCHAR2 as well as VARCHAR.
Date DATE Stores dates in the Julian date format.
eCommerce Solution Provider In Indiahttp://www.ifourtechnolab.com
SQL Constraints
SQL constraints are used to specify rules for the data in a table. NOT NULL - Indicates that a column cannot store NULL value UNIQUE - Ensures that each row for a column must have a unique value PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Ensures that a column (or combination
of two or more columns) have an unique identity which helps to find a particular record in a table more easily and quickly. Most tables should have a primary key, and each table can have only ONE primary key.
FOREIGN KEY - Ensure the referential integrity of the data in one table to match values in another table. A FOREIGN KEY in one table points to a PRIMARY KEY in another table.
CHECK - Ensures that the value in a column meets a specific condition DEFAULT - Specifies a default value when specified none for this column
eCommerce Solution Provider In Indiahttp://www.ifourtechnolab.com
SQL Functions
SQL has many built-in functions for performing calculations on data. There are two types of SQL function:
SQL Aggregate functions SQL Scalar Functions
eCommerce Solution Provider In Indiahttp://www.ifourtechnolab.com
SQL Aggregate Functions
SQL aggregate functions return a single value, calculated from values in a column.
Useful aggregate functions:AVG() - Returns the average valueCOUNT() - Returns the number of rowsFIRST() - Returns the first valueLAST() - Returns the last valueMAX() - Returns the largest valueMIN() - Returns the smallest valueSUM() - Returns the sum
eCommerce Solution Provider In Indiahttp://www.ifourtechnolab.com
SQL Scalar functions
SQL scalar functions return a single value, based on the input value. Useful scalar functions:
UCASE() - Converts a field to upper caseLCASE() - Converts a field to lower caseMID() - Extract characters from a text fieldLEN() - Returns the length of a text fieldROUND() - Rounds a numeric field to the number of decimals specifiedNOW() - Returns the current system date and timeFORMAT() - Formats how a field is to be displayed
eCommerce Solution Provider In Indiahttp://www.ifourtechnolab.com
www.w3schools.com www.tutorialspoint.com
References
eCommerce Solution Provider In Indiahttp://www.ifourtechnolab.com
Thank you
Software development company indiahttp://www.ifourtechnolab.com