Data types in MySQL. Kathleen Durant CS 3200

Similar documents
MS ACCESS DATABASE DATA TYPES

A list of data types appears at the bottom of this document. String datetimestamp = new java.sql.timestamp(system.currenttimemillis()).

sqlite driver manual

Database Migration from MySQL to RDM Server

A table is a collection of related data entries and it consists of columns and rows.

How To Create A Table In Sql (Ahem)

Financial Data Access with SQL, Excel & VBA

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

4 Logical Design : RDM Schema Definition with SQL / DDL

Porting from Oracle to PostgreSQL

SQL Server Array Library László Dobos, Alexander S. Szalay

MySQL+HandlerSocket=NoSQL

Netezza SQL Class Outline

Pemrograman Dasar. Basic Elements Of Java

Chapter 2: Elements of Java

MySQL 5.1 INTRODUCTION 5.2 TUTORIAL

Database Administration with MySQL

IT2305 Database Systems I (Compulsory)

Introduction to Microsoft Jet SQL

Number Representation

Using SQL Server Management Studio

IT2304: Database Systems 1 (DBS 1)

Instant SQL Programming

This section describes how LabVIEW stores data in memory for controls, indicators, wires, and other objects.

Computer Science 281 Binary and Hexadecimal Review

MYSQL DATABASE ACCESS WITH PHP

Comparison of Open Source RDBMS

DDL is short name of Data Definition Language, which deals with database schemas and descriptions, of how the data should reside in the database.

Oracle SQL. Course Summary. Duration. Objectives

Programming with SQL

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

C++ Language Tutorial

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

3.GETTING STARTED WITH ORACLE8i

!"# $ %& '( ! %& $ ' &)* + ! * $, $ (, ( '! -,) (# *&23. mysql> select * from from clienti;

SOME EXCEL FORMULAS AND FUNCTIONS

Advance DBMS. Structured Query Language (SQL)

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Key Functions in Oracle SQL

The release notes provide details of enhancements and features in Cloudera ODBC Driver for Impala , as well as the version history.

Handling Missing Values in the SQL Procedure

Firebird. Embedded SQL Guide for RM/Cobol

Information and Computer Science Department ICS 324 Database Systems Lab#11 SQL-Basic Query

SQL - QUICK GUIDE. Allows users to access data in relational database management systems.

Microsoft SQL Server Connector for Apache Hadoop Version 1.0. User Guide

Language Reference Guide

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

Guide to SQL Programming: SQL:1999 and Oracle Rdb V7.1

ODBC Client Driver Help Kepware, Inc.

Oracle Database: SQL and PL/SQL Fundamentals

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

T-SQL STANDARD ELEMENTS

Informatica e Sistemi in Tempo Reale

Microsoft Access 3: Understanding and Creating Queries

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

SQL Server An Overview

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

Title. Syntax. stata.com. odbc Load, write, or view data from ODBC sources. List ODBC sources to which Stata can connect odbc list

Best Practices in SQL Programming. Madhivanan

A methodology for Data Migration between Different Database Management Systems

Variables, Constants, and Data Types

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

Storing Measurement Data

MySQL Command Syntax

Teradata Database. SQL Reference. Data Types and Literals

FileMaker 13. SQL Reference

Oracle Database: SQL and PL/SQL Fundamentals

not at all a manual simply a quick how-to-do guide

History of SQL. Relational Database Languages. Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG)

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

Chapter 3. if 2 a i then location: = i. Page 40

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

10+ tips for upsizing an Access database to SQL Server

Binary Representation

Introduction to Java

IBM Unica Macros for IBM Unica Marketing Version 8 Release 6 May 25, User's Guide

High-Precision C++ Arithmetic

UNLEASHED. The Field Calculator. By Tom Neer, EDAW, Inc.

A Brief Introduction to MySQL

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

Systems I: Computer Organization and Architecture

Decimal to Binary Conversion

Oracle Database: SQL and PL/SQL Fundamentals NEW

Advanced Tutorials. The Dark Side of the Transparent Moon

2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA

Oracle Database: Introduction to SQL

Introduction to SQL for Data Scientists

Spring,2015. Apache Hive BY NATIA MAMAIASHVILI, LASHA AMASHUKELI & ALEKO CHAKHVASHVILI SUPERVAIZOR: PROF. NODAR MOMTSELIDZE

SQL: joins. Practices. Recap: the SQL Select Command. Recap: Tables for Plug-in Cars

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June Dr.-Ing.

ERserver. DB2 Universal Database for iseries SQL Programming with Host Languages. iseries. Version 5

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011

Microsoft SQL Server to Infobright Database Migration Guide

DNA Data and Program Representation. Alexandre David

Solution for Homework 2

Outline Basic concepts of Python language

Positional Numbering System

=

Oracle Database 12c: Introduction to SQL Ed 1.1

Transcription:

Data types in MySQL Kathleen Durant CS 3200

Supported data type classes Numeric Data Types Date & Time String

Numeric data types Bit(M) Number of bits Integer Comes in different sizes (tinyint, smallint, mediumint, int, largeint) Boolean = tinyint(1) Decimal(M,D) specify M as the total number of digits (the precision) and D as the number of digits after the decimal point (the scale). Example Decimal(4,2) for dollars amounts from -$99.99 to $99.99 Float : four bytes for single-precision values Double: eight bytes for double-precision values The FLOAT and DOUBLE types represent approximate numeric data values. Can use unsigned with integer, float, double, decimal

Numeric Type Limitations Data type Limitations, Size Examples BIT[N] 64 BIT(5) BOOL,BOOLEAN Alias for TINYINT TRUE=1, FALSE = 0 TINYINT -127 to 127 MEDIUMINT signed range is -8,388,608 to 838,8607 INTEGER, INT -2,147,483,648 to 2,147,483,647 BIGINT -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 DECIMAL(M,D) DECIMAL(65,30) DECIMAL(5,2) FLOAT(M,D) DOUBLE(M,D) 38 DECIMAL PLACES Accurate to ~7 decimal places 308 DECIMAL PLACES Accurate to ~15 decimal places FLOAT(15,10) DOUBLE(30,10)

String data types CHAR(n) n from 0 to 255 length indicates the number of characters you want to store VARCHAR(n) n from 0 to 65,535 length indicates the maximum number of characters you want to store BINARY(b) n from 0 to 255 contain binary strings rather than character strings VARBINARY(n) n from 0 to 65,535 BLOB: TINYBLOB from 0 to 255, BLOB from 0 to 65,535, MEDIUMBLOB a maximum length of 16,777,215, LONGBLOB maximum length of 4GB TEXT: TINYTEXT from 0 to 255, TEXT 0 to 65,535, MEDIUMTEXT maximum length of 16,777,215, LONGTEXT maximum length of 4GB ENUM Value chosen from a list of permitted values that are listed in the column specification at table creation time Example: size ENUM('x-small', 'small', 'medium', 'large') The index of each value is as shown: Value = Index NULL = NULL = 0 x-small = 1 small = 2 medium = 3 large = 4 SET string object that can have zero or more values, each of which must be chosen from a list of permitted values specified when the table is created members separated by commas

Date & Time DATE The supported range is '1000-01-01' to '9999-12-31 DATETIME supported range is '1000-01-01 00:00:00.000000' to '9999-12-31 23:59:59.999999' TIMESTAMP The range is '1970-01-01 00:00:01.000000' UTC to '2038-01-19 03:14:07.999999' UTC Stored as the number of seconds since the epoch ('1970-01-01 00:00:00' UTC) TIME displayed as [HH:MM:SS] Range is from -838:59:59.000000' to '838:59:59.000000' YEAR Range is from 1901 to 2051

Functions Aggregate Numeric String NULL Date & Time Casting and Conversion

Numeric functions Simple arithmetic operations The arithmetic operators: +, -, *, / DIV() return value has same data result as the input values MOD for the remainder of division or use the modulo key % POWER(BASE, EXPONENT), synonym POW power function ABS(N) - absolute value function SIGN(N) returns the sign of the provided number n Base arithmetic CONV(NUMBER, BASE, NEWBASE) convert a number from one base to another. Current My SQL limitation is BASE 36 Rounding Functions ROUND(n) round a number to a whole number ROUND(N, NUMDIGITS) round specify number of digits TRUNCATE(N,NUMDIGITS) limit value of n to numdigits CEILING(N) - round the number n up FLOOR(N) round a number n down Random number generator RAND() generate a random number RAND(seed) generate a random number seeded with the number seed will generate the same collection of numbers for each run Trigonometric functions, log functions Complete list: http://dev.mysql.com/doc/refman/5.6/en/mathematical-functions.html

String functions Length number of bytes in a string Char_length number of characters in string Left (string,num) extract the left most num characters from string Right(string,num) extract the rightmost num characters from string Mid(string,start,num) extract num characters from string starting at position num Concat(string1,string2) concatentate strings together Concat_ws(delimited, string1, string2) concatenate string2 to string1 using the delimited string as a separator Locate(substring,string) returns the character position of substring in string Upper(string), Lower(string) change string to the corresponding case Reverse(string) reverse the order of the characters in string Complete list http://dev.mysql.com/doc/refman/5.7/en/string-functions.html

Regular Expressions Specifies a pattern for a complex search. Clause: expression REGEXP format Returns 1 if the format matches the expression else 0 Special characters for matching ^ matches the beginning of a string $ matches the end of a string. Match any character a* match any sequence of zero of more a characters a+ match any sequence of one of more a characters a? match either zero or one a character de abc match either sequence de or abc (abc)* match zero or more instances of the sequence abc a{m,n} match m to n instances of a 2 backslashes allow you to match a special character \\.

NULL related functions COALESCE(EXPR1, EXPR2,,EXPRN) returns the first expression from the list that is not NULL IFNULL(expr1, expr2) returns expr1 if expr1 is not NULL if it is NULL returns expr2 NULLIF(expr1, expr2) compares exp1 to exp2. If they are equal returns NULL, if they are not equal returns exp1 NULL SAFE equality operator <=> (MYSQL specific) SELECT NULL <=> NULL ; -- returns TRUE; A complete set of comparison and NULL related functions http://dev.mysql.com/doc/refman/5.6/en/comparisonoperators.html

Common Date functions NOW() returns the current date and time Dayname(date) return the day of the provided date Sunday Saturday Dayofmonth() return the day of the month values 1 12 Dayofyear() return the day of the year where Jan 1 = 1 Dayofweek() returns the day name number Monday = 2 Monthname(now()) return the month of the provided date Adddate( 2015-12-31, INTERVAL exp unit); - add a specific interval to a date Example: Adddate( 2010-12-31, INTERVAL 31 day) 31 days after Dec 31, 2010 SUBDATE( 2015-01-02, INTERVAL exp unit); - subtract a specific interval to a date List of interval formats formats https://dev.mysql.com/doc/refman/5.6/en/date-and-timefunctions.html#function_date-add DATE_FORMAT(date, %W, %D OF %M %Y) format a date using the provided format List of interval formats formats https://dev.mysql.com/doc/refman/5.6/en/date-and-timefunctions.html#function_date-add Complete list of functions https://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html

Time functions Time_to_sec( 00:30:00 ) return the seconds portion of a time variable Sec_to_time() convert seconds variable to a time variable To_char(date, fmt_specifer) convert a date to a character string %d the day of the month, %M the long name of the month, %Y the year Addtime(time1,time2) add time together Subtime( time1,time2) subtract time Complete list of functions https://dev.mysql.com/doc/refman/5.6/en/date-and-timefunctions.html

Conversion functions BINARY string convert a string to binary Short hand notation for CAST(string as binary) CAST(expr as type ) cast expression to type CONVERT(expr, type) ODBC syntax CONVERT(expr USING type) convert expression to type Can specify a particular character set Standard SQL syntax Full description http://dev.mysql.com/doc/refman/5.6/en/castfunctions.html#function_cast

AGGREGATE FUNCTIONS Counting functions COUNT count records, COUNT(DISTINCT) count distinct values Statistical functions SUM, MIN, MAX, AVG, STD, STDDEV,VARIANCE Sample and Population variance and standard deviation STDDEV_SAMP, STDDEV_POP VAR_POP, VAR_SAMP Bit function operations BIT_AND, BIT_OR, BIT_XOR One text function GROUP_CONCAT Concatenate strings based on groups Complete list http://dev.mysql.com/doc/refman/5.6/en/group-by-functions.html