Database Chapters.

Slides:



Advertisements
Similar presentations
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizards Guide to PHP by David Lash.
Advertisements

LIS651 lecture 2 mySQL and PHP mySQL functions Thomas Krichel
LIS651 lecture 2 mySQL and PHP mySQL function Thomas Krichel
LIS651 lecture 2 mySQL and PHP mySQL function Thomas Krichel
PHP II Interacting with Database Data. The whole idea of a database-driven website is to enable the content of the site to reside in a database, and to.
Widhy Hayuhardhika NP, S.Kom. Overview of database structure Connecting to MySQL database Selecting the database to use Using the require_once statement.
9 Copyright © 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
Creating Tables Unit 9 - Databases.
CIT 613: Relational Database Development using SQL Revision of Tables and Data Types.
Session 2Introduction to Database Technology Data Types and Table Creation.
Creating Tables, Setting Constraints, and Datatypes What is a constraint and why do we use it? What is a datatype? What does CHAR mean? Page 97 in Course.
MS-Access XP Lesson 1. Introduction to MS-Access Database Management System Software (DBMS) Store data in databases Database is a collection of table.
Fundamentals of Database Systems Fourth Edition El Masri & Navathe
VTYS 2012 Mehmet Emin KORKUSUZ Ders  Create  Alter  Drop Data Defination Language.
MySQL. To start go to Login details: login: labuser password:macimd15 – There.
Day 3 - Basics of MySQL What is MySQL What is MySQL How to make basic tables How to make basic tables Simple MySQL commands. Simple MySQL commands.
MySQL-Database Teppo Räisänen Oulu University of Applied Sciences School of Business and Information Management.
Representing Data Elements Gayatri Gopalakrishnan.
1 A GUIDE TO ORACLE8 CHAPTER 2: Creating and ModifyingDatabaseTables 2.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 9: Data Definition Language.
Introduction to Structured Query Language (SQL)
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
1 CSE 480: Database Systems Lecture 9: SQL-DDL Reference: Read Chapter of the textbook.
Copyright © Curt Hill SQL The Data Definition Language.
Basis Data Terapan Yoannita. SQL Server Data Types Character strings: Data typeDescriptionStorage char(n)Fixed-length character string. Maximum 8,000.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
Creating Databases with MySQL Workbench Build the Forums database in Ullman’s Chapter 6.
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.
Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”
Introduction to MySQL Lab no. 10 Advance Database Management System.
CSC 2720 Building Web Applications Database and SQL.
Sizing Basics  Why Size?  When to size  Sizing issues:  Bits and Bytes  Blocks (aka pages) of Data  Different Data types  Row Size  Table Sizing.
1 SQL Tarek El-Shishtawy Professor Ass. Of Computer Engineering.
11 3 / 12 CHAPTER Databases MIS105 Lec15 Irfan Ahmed Ilyas.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
MySQL More… 1. More on SQL In MySQL, the Information Schema is the “Catalog” in the SQL standard SQL has three components: Data definition Data manipulation.
Advanced Web 2012 Lecture 3 Sean Costain What is a Database? Sean Costain 2012 A database is a structured way of dealing with structured information.
Visual Programing SQL Overview Section 1.
Data types  CHAR (size): This data type is used to store character strings values of fixed length. The size in brackets determines the number of characters.
Fox MIS Spring 2011 Database Week 6 ERD and SQL Exercise.
Sql DDL queries CS 260 Database Systems.
IMS 4212: Data Modeling—Attributes and Domains 1 Dr. Lawrence West, Management Dept., University of Central Florida Attributes and Domains.
Introduction to MySQL Lab no. 9 Advance Database Management System.
©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
Class 3Intro to Databases Class 4 Simple Example of a Database We’re going to build a simple example of a database, which will allow us to register users.
Relational Databases and MySQL. Relational Databases Relational databases model data by storing rows and columns in tables. The power of the relational.
Academic Year 2015 Autumn. MODULE CC2006NI: Data Modelling and Database Systems Academic Year 2015 Autumn.
Introduction to MySQL Ullman Chapter 4. Introduction MySQL most popular open-source database application Is commonly used with PHP We will learn basics.
Creating Database Objects
CS 3630 Database Design and Implementation
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Understanding SQL Statements
Data Definition and Data Types
MySQL-Database Jouni Juntunen Oulu University of Applied Sciences
Data Definition and Data Types
Attributes and Domains
Database systems Lecture 2 – Data Types
CIS 136 Building Mobile Apps
Creating Tables & Inserting Values Using SQL
Attributes and Domains
Chapter # 7 Introduction to Structured Query Language (SQL) Part I.
Chapter 4 Introduction to MySQL.
Kirkwood Center for Continuing Education
Creating Database Objects
Database Instructor: Bei Kang.
SQL (Structured Query Language)
Presentation transcript:

Database Chapters

Data Types Data type selection is usually dictated by nature of data and by intended use MySQL Supported data type categories: Numeric Date and time String Database Systems, 10th Edition

MySQL Numeric Data Types from http://www. tutorialspoint INT - You can specify a width of up to 11 digits. FLOAT(M,D) - A floating-point number that cannot be unsigned. You can define the display length (M) and the number of decimals (D). This is not required and will default to 10,2, where 2 is the number of decimals and 10 is the total number of digits (including decimals). Decimal precision can go to 24 places for a FLOAT. DOUBLE(M,D) - A double precision floating-point number that cannot be unsigned. You can define the display length (M) and the number of decimals (D). This is not required and will default to 16,4, where 4 is the number of decimals. Decimal precision can go to 53 places for a DOUBLE. REAL is a synonym for DOUBLE. DECIMAL(M,D) - An unpacked floating-point number that cannot be unsigned. In unpacked decimals, each decimal corresponds to one byte. Defining the display length (M) and the number of decimals (D) is required. NUMERIC is a synonym for DECIMAL. Database Systems, 10th Edition

MySQL String Data Types from http://www. tutorialspoint CHAR(M) - A fixed-length string between 1 and 255 characters in length (for example CHAR(5)), right-padded with spaces to the specified length when stored. Defining a length is not required, but the default is 1. VARCHAR(M) - A variable-length string between 1 and 255 characters in length; for example VARCHAR(25). You must define a length when creating a VARCHAR field. BLOB or TEXT - A field with a maximum length of 65535 characters. BLOBs are "Binary Large Objects" and are used to store large amounts of binary data, such as images or other types of files. Fields defined as TEXT also hold large amounts of data; the difference between the two is that sorts and comparisons on stored data are case sensitive on BLOBs and are not case sensitive in TEXT fields. You do not specify a length with BLOB or TEXT. ENUM - An enumeration, which is a fancy term for list. When defining an ENUM, you are creating a list of items from which the value must be selected (or it can be NULL). For example, if you wanted your field to contain "A" or "B" or "C", you would define your ENUM as ENUM ('A', 'B', 'C') and only those values (or NULL) could ever populate that field. Database Systems, 10th Edition

MySQL Date & Time Data Types from http://www. tutorialspoint DATE - A date in YYYY-MM-DD format, between 1000-01-01 and 9999-12-31. For example, December 30th, 1973 would be stored as 1973-12-30. DATETIME - A date and time combination in YYYY-MM-DD HH:MM:SS format, between 1000- 01-01 00:00:00 and 9999-12-31 23:59:59. For example, 3:30 in the afternoon on December 30th, 1973 would be stored as 1973-12-30 15:30:00. TIMESTAMP - A timestamp between midnight, January 1, 1970 and sometime in 2037. This looks like the previous DATETIME format, only without the hyphens between numbers; 3:30 in the afternoon on December 30th, 1973 would be stored as 19731230153000 ( YYYYMMDDHHMMSS ). TIME - Stores the time in HH:MM:SS format. YEAR(M) - Stores a year in 2-digit or 4-digit format. If the length is specified as 2 (for example YEAR(2)), YEAR can be 1970 to 2069 (70 to 69). If the length is specified as 4, YEAR can be 1901 to 2155. The default length is 4. Database Systems, 10th Edition

Creating Table Structures Use one line per column (attribute) definition Use spaces to line up attribute characteristics and constraints Table and attribute names are case sensitive NOT NULL specification UNIQUE specification Database Systems, 10th Edition

SQL Constraints AUTO_INCREMENT constraint NOT NULL constraint Applied to INT: assign the next available integer NOT NULL constraint Ensures that column does not accept nulls UNIQUE constraint Ensures that all values in column are unique Database Systems, 10th Edition

Creating tables General format: CREATE TABLE tablename ( column1 datatype, column2 datatype, PRIMARY KEY (…..), FOREIGN KEY (column1 REFERENCES tablename) );

Example 1 CREATE TABLE CUSTOMER ( CUS_CODE INT PRIMARY KEY, CUS_LNAME VARCHAR(15) NOT NULL, CUS_FNAME VARCHAR(15) NOT NULL, CUS_INITIAL CHAR(1), CUS_AREACODE CHAR(3) DEFAULT '615' NOT NULL CHECK(CUS_AREACODE IN ('615','713','931')), CUS_PHONE CHAR(8) NOT NULL, CUS_BALANCE DECIMAL(9,2) DEFAULT 0.00 ); Database Systems, 10th Edition

Example 2 CREATE TABLE SF_users ( user_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT, username VARCHAR(30) NOT NULL, pass CHAR(40) NOT NULL, first_name VARCHAR(20) NOT NULL, last_name VARCHAR(40) NOT NULL, email VARCHAR(60) NOT NULL, registration_date DATETIME NOT NULL, PRIMARY KEY (user_id), UNIQUE (username), UNIQUE (email), INDEX login (pass, email) ) ENGINE = INNODB; Notes: Default storage type is MyISAM: Doesn't support foreign key constraints, transactions, or row-level locking. Does support FULLTEXT indexes and searches Use storage type INNODB unless you need transactions or FULLTEXT.

Inserting data INSERT INTO SF_users (username, pass, first_name, last_name, email, registration_date) VALUES ('troutster', SHA1('lu@example.commypass'), 'Larry', 'Ullman', 'lu@example.com', NOW()), ('funny man', SHA1('db@example.commonkey'), 'David', 'Brent', 'db@example.com', NOW()), ('Gareth', SHA1('gk@example.comasstmgr'), 'Gareth', 'Keenan', 'gk@example.com', NOW()); SHA1() : Secure Hash Algorithm 1 – calculates a hash value for the string and returns a 40-character hex value. It provides one-way encryption. **This is not a recommended function for real-world encryption but is simple enough for learning purposes only. Adding, say, the email address to the password improves the password seed by making it longer. Now() is a handy function for getting the current date and time from the server.