Top Banner
SQL Overview Visual Programing Section 1
27

SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

Dec 13, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

SQL Overview

Visual Programing

Section 1

Page 2: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

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 and SQL Server use SQL as standard database language.

Page 3: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

What is SQL ?

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.

Page 4: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

Why SQL?

Allows users to access data in relational database management systems.

Allows users to describe the data. Allows users to define the data in database and manipulate

that data. Allows users to create and drop databases and tables. Allows users to create stored procedure, functions in a

database. Allows users to set permissions on tables, procedures

Page 5: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

What is RDBMS (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 

DBMS:A database management system (DBMS) is a collection of programs that enables you to store, modify, and extract information from a database

Page 6: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

Database Table

A relational database system contains one or more objects called tables. The data or information for the database are stored in these tables. Tables are uniquely identified by their names and are comprised of columns and rows.

Remember, a table is the most common and simplest form of data storage in a relational database.

Page 7: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

Example

Here is a sample table called "weather".

Table

It’s Column

It’s Row or Record

Page 8: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

Is everything Legal ?

No, you can use SQL Constraints

SQL Constraints: Constraints are the rules enforced on data columns on 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.

Page 9: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

Common SQL Constraints:

NOT NULL Constraint DEFAULT Constraint UNIQUE Constraint. PRIMARY Key FOREIGN Key. CHECK Constraint

Page 10: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

Data Types

Exact Numeric Data Types Approximate Numeric Data Types

Date and Time Data Types

Page 11: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

Data Types(cont.)

Binary Data TypesCharacter Strings Data Types

Page 12: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

Now ….. Let’s Start !

Page 13: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

CREATE DATABASE

Syntax:

CREATE DATABASE DatabaseName;

Example:

SQL> CREATE DATABASE testDB;

Test:

SQL> SHOW DATABASES;

Page 14: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

 DROP DATABASE

Syntax:

DROP DATABASE DatabaseName;

Example:

DROP DATABASE testDB;

Page 15: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

SELECT Database (USE Statement)

When you have multiple databases in your SQL Schema, then before starting your operation, you would need to select a database where all the operations would be performed.

USE DatabaseName;

Page 16: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

CREATE Table

Syntax:CREATE TABLE table_name(

column1 datatype,

column2 datatype,

column3 datatype,

.....

columnN datatype,

PRIMARY KEY( one or more columns )

);

Page 17: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

CREATE Table(cont.)

Example:CREATE TABLE CUSTOMERS(

ID INT NOT NULL,

NAME VARCHAR (20) NOT NULL,

AGE INT NOT NULL,

ADDRESS CHAR (25) ,

SALARY DECIMAL (18, 2),

PRIMARY KEY (ID)

);

Page 18: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

DROP or DELETE Table

The SQL DROP TABLE statement is used to remove a table definition and all data, indexes, triggers, constraints, and permission specifications for that table.

Syntax:

DROP TABLE table_name;

Page 19: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

INSERT Query

SyntaxINSERT INTO TABLE_NAME (column1, column2, column3,...columnN)]

VALUES (value1, value2, value3,...valueN);

OR

INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN);

Page 20: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

INSERT Query(cont.)

Example: INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)

VALUES (1, 'Ramesh', 32, 'Ahmedabad', 2000.00 );

INSERT INTO CUSTOMERS

VALUES (7, 'Muffy', 24, 'Indore', 10000.00 );

Page 21: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

SELECT Query

Syntax:

SELECT column1, column2, columnN FROM table_name;

SELECT * FROM table_name;

Example:

SELECT ID, NAME, SALARY FROM CUSTOMERS;

Page 22: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

WHERE Clause

The SQL WHERE clause is used to specify a condition while fetching the data from single table or joining with multiple tables.

Syntax:SELECT column1, column2, columnN

FROM table_name

WHERE [condition]

Example:SELECT ID, NAME, SALARY

FROM CUSTOMERS

WHERE SALARY > 2000;

Page 23: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

AND and OR Conjunctive Operators

The AND Operator Syntax:

SELECT column1, column2, columnN

FROM table_name

WHERE [condition1] AND [condition2]...AND [conditionN];

Example: SELECT ID, NAME, SALARY

FROM CUSTOMERS

WHERE SALARY > 2000 AND age < 25;

Page 24: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

AND and OR Conjunctive Operators(cont.)

The OR Operator: Syntax:

SELECT column1, column2, columnN

FROM table_name

WHERE [condition1] OR [condition2]...OR [conditionN]

Example: SELECT ID, NAME, SALARY

FROM CUSTOMERS

WHERE SALARY > 2000 OR age < 25;

Page 25: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

UPDATE Query

Syntax:UPDATE table_name

SET column1 = value1, column2 = value2...., columnN = valueN

WHERE [condition];

Example:UPDATE CUSTOMERS

SET ADDRESS = 'Pune'

WHERE ID = 6;

Page 26: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

Thanks

Page 27: SQL Overview Visual Programing Section 1. What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving.

Questions