CS242 SQL. What is SQL? SQL:  stands for Structured Query Language  allows you to access a database  is an ANSI standard computer language  can execute.

Slides:



Advertisements
Similar presentations
NMED 3850 A Advanced Online Design February 25, 2010 V. Mahadevan.
Advertisements

Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
Database Management System LICT 3011 Eyad H. Elshami.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
Programming with php By: Seth Larson. A little bit about PHP  PHP stands for PHP:  Hypertext Preprocessor  PHP is a widely-used general-purpose server-side.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
1 Working with MS SQL Server Textbook Chapter 14.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with MSSQL Server Code:G0-C# Version: 1.0 Author: Pham Trung Hai CTD.
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Introduction to MySQL Lab no. 10 Advance Database Management System.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
11 3 / 12 CHAPTER Databases MIS105 Lec15 Irfan Ahmed Ilyas.
Chapter 10: The Data Tier We discuss back-end data storage for Web applications, relational data, and using the MySQL database server for back-end storage.
Features of SQL SQL is an English-like language . It uses words such as select , insert , delete as part of its commend set. SQL is an a non-procedural.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
What’s a database? Data stored in a structured format that lends itself to easy manipulation and recall.
Visual Programing SQL Overview Section 1.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
CSC 405: Web Application Engineering II8.1 Web programming using PHP What have we learnt? What have we learnt? Underlying technologies of database supported.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Basic SQL*Plus edit and execute commands SQL*Plus buffer and built-in editor holds the last SQL statement Statements are created in free-flow style and.
Web Systems & Technologies
Web Database Programming Using PHP
Fundamentals of DBMS Notes-1.
Web Systems & Technologies
Databases.
CS 3630 Database Design and Implementation
Chapter 5 Introduction to SQL.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
CS320 Web and Internet Programming SQL and MySQL
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Web Database Programming Using PHP
Unix System Administration
Data Definition and Data Types
Introduction to Web programming
ORACLE SQL Developer & SQLPLUS Statements
ISC440: Web Programming 2 Server-side Scripting PHP 3
DATABASE MANAGEMENT SYSTEM
STRUCTURED QUERY LANGUAGE
SQL data definition using Oracle
Structured Query Language
Introduction To Structured Query Language (SQL)
SQL-1 Week 8-9.
Database Applications
Introduction To Structured Query Language (SQL)
Structured Query Language
CS3220 Web and Internet Programming SQL and MySQL
Web Programming– UFCFB Lecture
MySQL Database System Installation Overview SQL summary
PHP Forms and Databases.
CS3220 Web and Internet Programming SQL and MySQL
Database Connections.
Introduction to Web programming
SQL (Structured Query Language)
Presentation transcript:

CS242 SQL

What is SQL? SQL:  stands for Structured Query Language  allows you to access a database  is an ANSI standard computer language  can execute queries against a database  can retrieve data from a database  can insert new records in a database  can delete records from a database  can update records in a database  is easy to learn

SQL SQL works with database programs like MS Access, DB2, Informix, MS SQL Server, Oracle, Sybase,

Relational Database  Comprised of “tables”  Tables comprised of “rows” or records  Rows contain columns or fields of data  Columns have types associated with them  Data is accessed with queries

Relational Database  Multiple tables  Reduces redundancy  Require few assumptions about how data is related  Adaptive

Adaptive Legal values for a given field can grow City Name column 1) create a table for the city name 2) change the city name column to index into table 3) as new city names appear in interface, add them to the table

Flat File Database  Simple database scheme  Single table  “spreadsheet”

SQL DDL (data definition language)  CREATE table  ALTER table  DROP table

CREATE TABLE Column definitions: Column name, data type, required data, default value CREATE TABLE persons (lastName char(50), firstName char(50), Address char(50), City char(50), State char(2))

SQL Data Types AccessSQL-ServerOracleMySQLPostgreSQL booleanYes/NoBitByteN/ABoolean integer Number (integer) IntNumber Int Integer (synonyms) Integer Int float Number (single) Float Real NumberFloatNumeric currencyCurrencyMoneyN/AN/AMoney string (fixed) N/ACharCharCharChar string (variable) Text (<256) Memo (65k+) Varchar Varchar Varch ar2 VarcharVarchar binary object OLE Object Memo Binary (fixed up to 8K) Varbinary (<8K) Image (<2GB) Long Raw Blob Text Binary Varbina ry

Adding Data  INSERT – insert a row of data  UPDATE – update one or more coumns in selected rows  DELETE – delete selected rows of data

Queries SELECT SELECT returns a result set – a table of data as described in the query SELECT lastName FROM persons SELECT firstName FROM persons WHERE lastName = ‘woodley’ SELECT firstName FROM persons WHERE lastName LIKE ‘%woo%’

Primary Key  Uniquely identifies a single record  Either a value that is guaranteed to be unique OR  Automatically generated by the DBMS to BE unique

Retrieving from a database // connect $db = mysql_connect("localhost", "root"); // select the database mysql_select_db("mydb",$db); // retrieve data from table $result = mysql_query("SELECT * FROM employees",$db);

Results of a Query odbc_fetch_array $result = odbc_exec($db,$query); if ($myrow = odbc_fetch_array($result)) { // output HTML code here to begin the table //echo " \n"; do{ printf(" %s %s %s % s %s \n", $myrow ["date"], $myrow["time"], $myrow["Slot 1"], $myrow["Slot 2"], $myrow["Slot 3"]); $myrow = odbc_fetch_array($result); } while ($myrow["date"]!=""); // end the table started above //echo " "; }

Result Sets <?php // make a table with a row labeling the columns echo " \n Name Position \n"; // open a connection to the database $db = mysql_connect("localhost", "root"); mysql_select_db("mydb",$db); // retrieve entire table of data $result = mysql_query("SELECT * FROM employees",$db); // get and process a row at a time while ($myrow = mysql_fetch_row($result)) { // output a table row and insert the fields into the cells printf(" %s %s %s \n", $myrow[1], $myrow[2], $myrow[3]); } echo " \n"; ?>

PHP and Form Data Google: php form data Decent tutorial on retrieving and processing form data using PHP: rms1.php

GET and POST  $_GET: When using the $_GET variable all variable names and values are displayed in the URL.When using the $_GET variable all variable names and values are displayed in the URL. ( This would include password information.) Has a max of 100 charactersHas a max of 100 characters

GET and POST  $_POST: The $_POST variable is an array of variable names and values sent by the HTTP POST method.The $_POST variable is an array of variable names and values sent by the HTTP POST method. Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.

SQL Injection Example SQL statement: SELECT FROM persons WHERE lastName = ‘” + formUserName + “’; If you enter into the username box on your form the string: a’ or ‘t’=‘t (No beginning nor ending quote.) You get: SELECT FROM persons WHERE lastName = ‘a or ‘t’=‘t’ Will return a valid username.

Multiple SQL Statements SQL statement: SELECT FROM persons WHERE lastName = ‘” + formUserName + “’; If you enter into the username box on your form the string: a';DROP TABLE persons; SELECT * FROM data WHERE name LIKE '% You get: SELECT FROM persons WHERE lastName = ‘a’; DROP TABLE persons; SELECT * FROM data where NAME LIKE ‘%’

SQL Injection Video: NJjh4jORY NJjh4jORY Attacks by example:  injection.html

Do not use form data directly Check and sanitize the form data before putting it in your SQL query statement.