SQL – Data types.

Slides:



Advertisements
Similar presentations
CIT 613: Relational Database Development using SQL Revision of Tables and Data Types.
Advertisements

Database Chapters.
Structured Query Language - SQL Carol Wolf Computer Science.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Data types and variables
PZ04A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ04A - Scalar and composite data Programming Language.
Data Representation Kieran Mathieson. Outline Digital constraints Data types Integer Real Character Boolean Memory address.
Chapter 2 Data Types, Declarations, and Displays
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
Storing data Getting data out Data types Ruby as a foundation Program Variables Click icon to hear comments (the download may take a minute)
The Binary Number System
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
Basis Data Terapan Yoannita. SQL Server Data Types Character strings: Data typeDescriptionStorage char(n)Fixed-length character string. Maximum 8,000.
 Pearson Education, Inc. All rights reserved Formatted Output.
 2005 Pearson Education, Inc. All rights reserved Formatted Output.
Cis303a_chapt03-2a.ppt Range Overflow Fixed length of bits to hold numeric data Can hold a maximum positive number (unsigned) X X X X X X X X X X X X X.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
Lecture #5 Introduction to C++
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Variables and Data Types Data (information we're going to store) – Numbers – Text – Dates What types of data can JavaScript process? How do we store it?
Relational Databases. Relational database  data stored in tables  must put data into the correct tables  define relationship between tables  primary.
Conversion Functions.
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.
GLOBEX INFOTEK Copyright © 2013 Dr. Emelda Ntinglet-DavisSYSTEMS ANALYSIS AND DESIGN METHODSINTRODUCTORY SESSION EFFECTIVE DATABASE DESIGN for BEGINNERS.
Sql DDL queries CS 260 Database Systems.
Table Creation / Data Types. A Data type is... Specifies what kind of information a column will hold so that the system will know how the data is to be.
Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Signed Integers The highest bit indicates the sign. 1 = negative, 0 = positive.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Computers and Numbers. Types of Numbers Computers store two different types of numbers: Whole Numbers AKA Integers (mathematics) AKA Fixed Point Numbers.
1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
Academic Year 2015 Autumn. MODULE CC2006NI: Data Modelling and Database Systems Academic Year 2015 Autumn.
CHAPTER 9 File Storage Shared Preferences SQLite.
1 Scalar and composite data Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Scalar and composite data Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
The purpose of a CPU is to process data Custom written software is created for a user to meet exact purpose Off the shelf software is developed by a software.
28 Formatted Output.
Chapter 9 - Formatted Input/Output
Choosing Data Types Database Administration Fundamentals
Creating Database Objects
Introduction To Oracle
SQL – Python and Databases
Data Representation Binary Numbers Binary Addition
CIS 136 Building Mobile Apps
Unit 16 – Database Systems
TMF1414 Introduction to Programming
Case Statements and Functions
Attributes and Domains
SQL – Dates and Times.
SQL – Parameterized Queries
IDENTIFIERS CSC 111.
SQL – Python and Databases (Continued)
SQL data definition using Oracle
Database systems Lecture 2 – Data Types
CIS 136 Building Mobile Apps
Data type for fields in Access
Chapter 9 - Formatted Input/Output
Defining a Database Schema
C++ Data Types Data Type
Attributes and Domains
COMS 161 Introduction to Computing
Kirkwood Center for Continuing Education
CMSC-461 Database Management Systems
Data Types and Maths Programming Guides.
Creating Database Objects
Database Instructor: Bei Kang.
SQL (Structured Query Language)
Section 6 Primitive Data Types
Presentation transcript:

SQL – Data types

In sqlite, Is 1 the same as 1.0? Yes! Yes? No? No!

Huh? From https://www.sqlite.org/datatype3.html "As an internal optimization, small floating point values with no fractional component and stored in columns with REAL affinity are written to disk as integers in order to take up less space and are automatically converted back into floating point as the value is read out. This optimization is completely invisible at the SQL level and can only be detected by examining the raw bits of the database file." Cool!

NULL NULL is a legal value in any column. It is outside the domain of any data type. It normally represents an absence of information or inapplicable value. Other uses (bad practice): Nothing (Empty) False Example: CREATE TABLE states (name TEXT, admissionToUnion INTEGER); INSERT INTO states ('Puerto Rico', NULL);

INteger Signed integer up to 8 bytes long (64 bits) Example: From −170,141,183,460,469,231,731,687,303,715,884,105,728 to 170,141,183,460,469,231,731,687,303,715,884,105,727 Example: 1 http://imgur.com/gallery/pp4Za

REAL Signed 64 bit floating point From VERY BIG to VERY SMALL Can be specified as a decimal or exponential notation (using capital E) Examples: 1.0, 4.5, -6.0, .8 5.6E12.4, -0.05E-67

TEXT Text can be of any length, but it must be enclosed in single quotes Single quotes must be escaped with a single quote Example: '', 'I''m a string' Many other databases give you access to fixed length TEXT or variable length TEXT below a certain character limit, be happy we are working with the best DBMS.

What is the BEST database Management software? SQLite SQLite! SQLite!! MySQL... Just Kidding, SQLite!!! How much am I paying for this class again?

Date and Time TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS"). REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar. INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC. More info https://www.sqlite.org/lang_datefunc.html

BLOB Used to hold arbitrary binary data. Often images, video, or other non-text data. No storage limit. Example: X'012e2b041cc23f4a0549' Rarely used in text INSERT statements, more often used in parameterized queries using programming language APIs (like python's sqlite3 module) We'll be avoiding them in this class for simplicity http://tvtropes.org/pmwiki/pmwiki.php/Characters/XMenEvolution?from=Characters.X-MenEvolution

Numeric Techically SQLite has another type, NUMERIC "A column with NUMERIC affinity may contain values using all five storage classes. When text data is inserted into a NUMERIC column, the storage class of the text is converted to INTEGER or REAL (in order of preference) if such conversion is lossless and reversible. For conversions between TEXT and REAL storage classes, SQLite considers the conversion to be lossless and reversible if the first 15 significant decimal digits of the number are preserved. If the lossless conversion of TEXT to INTEGER or REAL is not possible then the value is stored using the TEXT storage class. No attempt is made to convert NULL or BLOB values." TL;DR NUMERIC can hold any number to any precision needed. But we won't be using it.

Non sqlite data types Memo – holds 65,536 characters Currency – 15 whole digits and 4 decimal places in base 10 Yes/No – Microsoft Access doesn't like scareing people with the word boolean Enum – Restricted text strings You an imitate any of these types with SQLite's default types (or extend your own with wrapper functions).