TINYINT[(M)] [UNSIGNED] [ZEROFILL] A very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255.

Similar documents
Lab # 2 Hands-On. DDL Basic SQL Statements Institute of Computer Science, University of Tartu, Estonia

CSCI-UA: Database Design & Web Implementation. Professor Evan Sandhaus

CSCI-UA: Database Design & Web Implementation. Professor Evan Sandhaus

General References on SQL (structured query language) SQL tutorial.

Data and Tables. Bok, Jong Soon

Chapter 3 Introduction to relational databases and MySQL

Chapter 8 How to work with data types

Data Types in MySQL CSCU9Q5. MySQL. Data Types. Consequences of Data Types. Common Data Types. Storage size Character String Date and Time.

Introduction to SQL on GRAHAM ED ARMSTRONG SHARCNET AUGUST 2018

The M in LAMP: MySQL CSCI 470: Web Science Keith Vertanen Copyright 2014

Lab # 4. Data Definition Language (DDL)

Overview of MySQL Structure and Syntax [2]

Tool/Web URL Features phpmyadmin. More on phpmyadmin under User Intefaces. MySQL Query Browser

Data Definition Language with mysql. By Kautsar

Basis Data Terapan. Yoannita

Model Question Paper. Credits: 4 Marks: 140

Oracle SQL Developer. Supplementary Information for MySQL Migrations Release 2.1 E

Careerarm.com. 1. What is MySQL? MySQL is an open source DBMS which is built, supported and distributed by MySQL AB (now acquired by Oracle)

Lab # 2. Data Definition Language (DDL) Eng. Alaa O Shama

Basic SQL. Basic SQL. Basic SQL

GridDB Advanced Edition SQL reference

DB Programming. Database Systems

Standard Query Language: Current standard Logical Schema Design: Schema Definition with SQL (DDL)

MySQL Command Syntax

Full file at

SQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Introduction to IBM DB2

CIS 363 MySQL. Chapter 4 MySQL Connectors Chapter 5 Data Types Chapter 6 Identifiers

3.2.4 Enforcing constraints

Create Basic Databases and Integrate with a Website Lesson 1

Information Systems Engineering. SQL Structured Query Language DDL Data Definition (sub)language

GridDB Advanced Edition SQL reference

Basic SQL. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation

Acknowledgments About the Authors


SQL Data Definition Language: Create and Change the Database Ray Lockwood

MySQL 5.0 Certification Study Guide

Deepak Bhinde PGT Comp. Sc.

Programming and Database Fundamentals for Data Scientists

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement

SQL Functionality SQL. Creating Relation Schemas. Creating Relation Schemas

SQL Data Definition and Data Manipulation Languages (DDL and DML)

Exact Numeric Data Types

*this is a guide that was created from lecture videos and is used to help you gain an understanding of what is mysql used for.

MySQL: an application

SQL Commands & Mongo DB New Syllabus

Mysql Information Schema Update Time Null >>>CLICK HERE<<< doctrine:schema:update --dump-sql ALTER TABLE categorie

The Top 20 Design Tips

MySQL Introduction. By Prof. B.A.Khivsara

Chapter 9: Working with MySQL

More MySQL ELEVEN Walkthrough examples Walkthrough 1: Bulk loading SESSION

ALTER TABLE Improvements in MARIADB Server. Marko Mäkelä Lead Developer InnoDB MariaDB Corporation

Advanced SQL. Nov 21, CS445 Pacific University 1

1 INTRODUCTION TO EASIK 2 TABLE OF CONTENTS

Chapter 13 : Informatics Practices. Class XI ( As per CBSE Board) SQL Commands. New Syllabus Visit : python.mykvs.in for regular updates

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

Course Outline and Objectives: Database Programming with SQL

Lecture 5: SQL s Data Definition Language

Data Definition and Data Manipulation. Lecture 5: SQL s Data Definition Language CS1106/CS5021/CS6503 Introduction to Relational Databases

HOW TO CREATE AND MAINTAIN DATABASES AND TABLES. By S. Sabraz Nawaz Senior Lecturer in MIT FMC, SEUSL

ASSIGNMENT NO 2. Objectives: To understand and demonstrate DDL statements on various SQL objects

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210

CIS 363 MySQL. Chapter 10 SQL Expressions Chapter 11 Updating Data

MariaDB 10.3 vs MySQL 8.0. Tyler Duzan, Product Manager Percona

COSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan

SQL: Data Definition Language

A Practical Guide to Migrating from Oracle to MySQL. Robin Schumacher

Why we re excited about MySQL 8

Constraints. Primary Key Foreign Key General table constraints Domain constraints Assertions Triggers. John Edgar 2

INTRODUCTION TO DATABASE

What s New in MariaDB Server Max Mether VP Server

Data Definition Language (DDL)

5. SQL Query Syntax 1. Select Statement. 6. CPS: Database Schema

Department of Computer Science University of Cyprus. EPL342 Databases. Lab 2

Full file at

Introduction to Computer Science and Business

Oracle 1Z0-882 Exam. Volume: 100 Questions. Question No: 1 Consider the table structure shown by this output: Mysql> desc city:

Mastering phpmyadmiri 3.4 for

Db2 Alter Table Alter Column Set Data Type Char

MySQL 8.0: Atomic DDLs Implementation and Impact

Optional SQL Feature Summary

Installing and Configuring Oracle GoldenGate for MySQL 12c (12.1.2)

Oracle GoldenGate MySQL Installation and Setup Guide 11g Release 1 (11.1.1) E October 2010

Percona XtraDB: Compressed Columns with Dictionaries an alternative to InnoDB table compression. Yura Sorokin, Senior Software Engineer at Percona

High Performance MySQL Practical Tuesday, April 01, :45

Department of Computer Science University of Cyprus. EPL342 Databases. Lab 1. Introduction to SQL Server Panayiotis Andreou

Backing up or Exporting Databases Using mysqldump

Course Topics. Microsoft SQL Server. Dr. Shohreh Ajoudanian. 01 Installing MSSQL Server Data types

STRUCTURED QUERY LANGUAGE (SQL)

Provider: MySQLAB Web page:

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Functional Logic Programming with Databases

user specifies what is wanted, not how to find it

Senturus Analytics Connector. User Guide Cognos to Tableau Senturus, Inc. Page 1

UNIT-IV (Relational Database Language, PL/SQL)

Data Storage and Query Answering. Data Storage and Disk Structure (4)

Selections. Lecture 4 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 22, 2014

Documentation Accessibility. Access to Oracle Support. Supported Browsers

SAS/ACCESS Supplement for MySQL. SAS/ACCESS for Relational Databases

Transcription:

MySQL: Data Types 1. Numeric Data Types ZEROFILL automatically adds the UNSIGNED attribute to the column. UNSIGNED disallows negative values. SIGNED (default) allows negative values. BIT[(M)] A bit-field type. M indicates the number of bits per value, from 1 to 64. The default is 1 if M is omitted. TINYINT[(M)] [UNSIGNED] [ZEROFILL] A very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255. BOOL, BOOLEAN These types are synonyms for TINYINT(1). A value of zero is considered false. Nonzero values are considered true. The values TRUE and FALSE are merely aliases for 1 and 0 SMALLINT[(M)] [UNSIGNED] [ZEROFILL] A small integer. The signed range is -32768 to 32767. The unsigned range is 0 to 65535. MEDIUMINT[(M)] [UNSIGNED] [ZEROFILL] A medium-sized integer. The signed range is -8388608 to 8388607. The unsigned range is 0 to 16777215. INT[(M)] [UNSIGNED] [ZEROFILL] A normal-size integer. The signed range is -2147483648 to 2147483647. The unsigned range is 0 to 4294967295. INTEGER[(M)] [UNSIGNED] [ZEROFILL] This type is a synonym for INT. BIGINT[(M)] [UNSIGNED] [ZEROFILL] A large integer. The signed range is -9223372036854775808 to 9223372036854775807. The unsigned range is 0 to 18446744073709551615. 1

MySQL: Data Types (2) SERIAL is an alias for BIGINT UNSIGNED NOT NULL AUTO INCREMENT UNIQUE. FLOAT[(M,D)] [UNSIGNED] [ZEROFILL] A small (single-precision) floating-point number. Permissible values are -3.402823466E+38 to -1.175494351E-38, 0, and 1.175494351E-38 to 3.402823466E+38. M is the total number of digits and D is the number of digits following the decimal point. DOUBLE[(M,D)] [UNSIGNED] [ZEROFILL] A normal-size (double-precision) floating-point number. Permissible values are -1.7976931348623157E+308 to -2.2250738585072014E-308, 0, and 2.2250738585072014E-308 to 1.7976931348623157E+308. DOUBLE PRECISION[(M,D)] [UNSIGNED] [ZEROFILL], REAL[(M,D)] [UNSIGNED] [ZEROFILL] These types are synonyms for DOUBLE. FLOAT(p) [UNSIGNED] [ZEROFILL] A floating-point number. p represents the precision in bits, but MySQL uses this value only to determine whether to use FLOAT or DOUBLE for the resulting data type. If p is from 0 to 24, the data type becomes FLOAT with no M or D values. If p is from 25 to 53, the data type becomes DOUBLE with no M or D values. DECIMAL[(M[,D])] [UNSIGNED] [ZEROFILL] For MySQL 5.0.3 and above: A packed exact fixed-point number. M is the total number of digits (the precision) and D is the number of digits after the decimal point (the scale). The decimal point and (for negative numbers) the - sign are not counted in M. If D is 0, values have no decimal point or fractional part. Before MySQL 5.0.3: An unpacked fixed-point number. Behaves like a CHAR column; unpacked means the number is stored as a string, using one character for each digit of the value. 2

MySQL: Data Types (3) DEC[(M[,D])] [UNSIGNED] [ZEROFILL], NUMERIC[(M[,D])] [UNSIGNED] [ZEROFILL], FIXED[(M[,D])] [UNSIGNED] [ZEROFILL] These types are synonyms for DECIMAL. The FIXED synonym is available for compatibility with other database systems. 2. Date and time types * DATE A date. The supported range is 1000-01-01 to 9999-12-31. MySQL displays DATE values in YYYY-MM-DD format, but permits assignment of values to DATE columns using either strings or numbers. DATETIME A date and time combination. The supported range is 1000-01-01 00:00:00 to 9999-12-31 23:59:59. MySQL displays DATETIME values in YYYY-MM-DD HH:MM:SS format, but permits assignment of values to DATETIME columns using either strings or numbers. TIMESTAMP A timestamp. The range is 1970-01-01 00:00:01 UTC to 2038-01-19 03:14:07 UTC. TIMESTAMP values are stored as the number of seconds since the epoch ( 1970-01-01 00:00:00 UTC). A TIMESTAMP cannot represent the value 1970-01-01 00:00:00 because that is equivalent to 0 seconds from the epoch and the value 0 is reserved for representing 0000-00-00 00:00:00, the zero TIMESTAMP value. TIME A time. The range is -838:59:59 to 838:59:59. MySQL displays TIME values in HH:MM:SS format, but permits assignment of values to TIME columns using either strings or numbers. YEAR[(2 4)] A year in two-digit or four-digit format. The default is four-digit format. In four-digit format, the permissible values are 1901 to 2155, and 0000. In twodigit format, the permissible values are 70 to 69, representing years from 1970 to 2069. MySQL displays YEAR values in YYYY format, but permits assignment of values to YEAR columns using either strings or numbers. 3

3. String types MySQL: Data Types (4) CHARACTER SET attribute specifies the character set. Specifying the binary attribute causes the column to be created as the corresponding binary data type: CHAR becomes BINARY VARCHAR becomes VARBINARY TEXT becomes BLOB ENUM and SET data typesare unaffected ASCII is shorthand for CHARACTER SET latin1. UNICODE is shorthand for CHARACTER SET ucs2. CHARSET is a synonym for CHARACTER SET. COLLATE attribute specifies a collation for the character set. BINARY is shorthand for specifying the binary collation of the column character set. [NATIONAL] CHAR[(M)] [CHARACTER SET charset name] [COL- LATE collation name] A fixed-length string that is always right-padded with spaces to the specified length when stored. M represents the column length in characters. The range of M is 0 to 255. If M is omitted, the length is 1. Trailing spaces are removed when CHAR values are retrieved. NCHAR Shorthand for NATIONAL CHAR. [NATIONAL] VARCHAR(M) [CHARACTER SET charset name] [COLLATE collation name] Shorthand for CHARACTER VARYING. A variable-length string. M represents the maximum column length in characters. NVARCHAR is shorthand for NATIONAL VARCHAR. BINARY(M) The BINARY type is similar to the CHAR type, but stores binary byte strings rather than nonbinary character strings. M represents the column length in bytes. 4

MySQL: Data Types (5) VARBINARY(M) The VARBINARY type is similar to the VARCHAR type, but stores binary byte strings rather than nonbinary character strings. M represents the maximum column length in bytes. TINYBLOB A BLOB column with a maximum length of 255 (28 1) bytes. TINYTEXT [CHARACTER SET charset name] [COLLATE collation name] A TEXT column with a maximum length of 255 (28 1) characters. BLOB[(M)] A BLOB column with a maximum length of 65,535 (216 1) bytes. An optional length M can be given for this type. If this is done, MySQL creates the column as the smallest BLOB type large enough to hold values M bytes long. TEXT[(M)] [CHARACTER SET charset name] [COLLATE collation name] A TEXT column with a maximum length of 65,535 (216 1) characters. An optional length M can be given for this type. If this is done, MySQL creates the column as the smallest TEXT type large enough to hold values M characters long. MEDIUMBLOB A BLOB column with a maximum length of 16,777,215 (224 1) bytes. MEDIUMTEXT [CHARACTER SET charset name] [COLLATE collation name] A TEXT column with a maximum length of 16,777,215 (224 1) characters. LONGBLOB A BLOB column with a maximum length of 4,294,967,295 or 4GB (232 1) bytes. 5

MySQL: Data Types (6) LONGTEXT [CHARACTER SET charset name] [COLLATE collation name] A TEXT column with a maximum length of 4,294,967,295 or 4GB (232 1) characters. ENUM( value1, value2,...) [CHARACTER SET charset name] [COL- LATE collation name] An enumeration. A string object that can have only one value, chosen from the list of values value1, value2,..., NULL or the special error value. An ENUM column can have a maximum of 65,535 distinct values. SET( value1, value2,...) [CHARACTER SET charset name] [COL- LATE collation name] A set. A string object that can have zero or more values, each of which must be chosen from the list of values value1, value2,... A SET column can have a maximum of 64 members. 6

MySQL: Command Summary 1. DDL ALTER DATABASE ALTER EVENT ALTER FUNCTION ALTER PROCEDURE ALTER SERVER ALTER TABLE ALTER VIEW CREATE DATABASE CREATE EVENT CREATE FUNCTION CREATE INDEX CREATE PROCEDURE CREATE SERVER CREATE TABLE CREATE TRIGGER CREATE VIEW DROP DATABASE DROP EVENT DROP FUNCTION DROP INDEX DROP PROCEDURE DROP SERVER DROP TABLE DROP TRIGGER DROP VIEW RENAME TABLE TRUNCATE TABLE 2. DML CALL DELETE DO HANDLER INSERT LOAD DATA INFILE LOAD XML REPLACE SELECT UPDATE 3. Transaction control COMMIT LOCK TABLES UNLOCK TABLES ROLLBACK ROLLBACK TO SAVEPOINT SAVEPOINT SET TRANSACTION START TRANSACTION 4. Administration (account, table management, etc.) (a) User management CREATE USER DROP USER GRANT RENAME USER REVOKE SET PASSWORD (b) Table management ANALYZE TABLE CHECK TABLE CHECKSUM TABLE OPTIMIZE TABLE REPAIR TABLE (c) Functions CREATE FUNCTION DROP FUNCTION INSTALL PLUGIN UNINSTALL PLUGIN 7

MySQL: Command Summary (2) (d) Additional BINLOG CACHE INDEX FLUSH KILL LOAD INDEX INTO CACHE RESET (e) Utility DESCRIBE EXPLAIN HELP SET SHOW USE 8

CREATE TABLE command MySQL: SQL Variants 1. CREATE TABLE [IF NOT EXISTS]table... (... ) ENGINE = engine_name where engine name can be MyISAM, MEMORY, InnoDB (plus others) 2. Column constraints/specs AUTO_INCREMENT [= n] COMMENT = string INSERT command 1. INSERT INTO... VALUES (val_list) [, (val_list)]... 2. INSERT INTO... SET col_name = value [, col_name = value]... 9

The SHOW statement Syntax: MySQL: Metadata and the Catalog SHOW {DATABASES CREATE DATABASE db_name TABLES [FROM db_name] CREATE TABLE tbl_name COLUMNS FROM tbl_name INDEX FROM tbl_name TABLE STATUS [FROM db_name] } Several of the above allow a LIKE clause: SHOW arg FROM tbl name LIKE pattern Versions that accept the LIKE clause also accept a WHERE clause Directly accessing the catalog The catalog consists of the INFORMATION SCHEMA database Being a database, it consists of a a set of tables The following are a subset of what is available: 1. COLUMNS 2. COLUMN PRIVILEGES 3. ENGINES 4. SCHEMATA 5. SCHEMA PRIVILEGES 6. STATISTICS 7. TABLES 8. TABLE CONSTRAINTS 9. TABLE PRIVILEGES 10. TRIGGERS 11. USER PRIVILEGES 12. VIEWS These are read only Metadata about these tables can be retrieved using SHOW where tbl name is INFORMATION SCHEMA.tbl name The data stored in these tables can be retrieved using SELECT 10

The DESCRIBE statement Syntax: MySQL: Metadata and the Catalog (2) DESCRIBE tbl_name [col_name] Equivalent to SHOW COLUMNS Displays info about the column(s) of the specified table To load data into a table from a file Syntax: LOAD DATA LOCAL INFILE file_path INTO TABLE tbl_name [FIELDS [TERMINATED BY string] [ENCLOSED BY char] [ESCAPED BY char]] By default, columns separated by tabs: LOAD DATA LOCAL INFILE home/sql/files/infile.txt INTO TABLE example 11