VTYS 2012 Mehmet Emin KORKUSUZ Ders - 03.  Create  Alter  Drop Data Defination Language.

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
Database Chapters.
MySQL. To start go to Login details: login: labuser password:macimd15 – There.
Pertemuan ke 2 Tipe data & ERD Kurniawan Eka Permana.
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.
SLIDE 1IS 257 – Fall 2010 Physical Database Design and Referential Integrity University of California, Berkeley School of Information IS 257:
Fall 2001Arthur Keller – CS 1808–1 Schedule Today Oct. 18 (TH) Schemas, Views. u Read Sections u Project Part 3 extended to Oct. 23 (T). Oct.
CIT 381 Data Types - data types - create table statement - constraints.
IMS1907 Database Systems Summer Semester 2004/2005 Lecture 9 Structured Query Language – SQL Data Definition Language - DDL.
Winter 2002Arthur Keller – CS 1808–1 Schedule Today: Jan. 29 (T) u Modifications, Schemas, Views. u Read Sections Assignment 3 due. Jan. 31 (TH)
Basic SQL types String –Char(n): fixed length. Padded –Varchar(n): variable length Number –Integer: 32 bit –Decimal(5,2): –Real, Double: 32 bit,
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
SQL Basics+ Brandon Checketts. Why SQL? Structured Query Language Structured Query Language Frees programmers from dealing with specifics of data persistence.
Database Design (for IQ-M). Introduction This section has been re-vamped for the course I have removed all the design bits that are not absolutely.
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.
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.
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
Copyright © Curt Hill SQL The Data Definition Language.
Lecture 9 – MYSQL and PHP (Part1) SFDV3011 – Advanced Web Development 1.
Frank Hilhorst President Progressive Consulting Inc. Open Source Data Sharing.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
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 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
CHAPTER 8 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”
CSC 2720 Building Web Applications Database and SQL.
SQL Data Definition Language (DDL) Using Microsoft SQL Server 1SDL Data Definition Language (DDL)
1 Introduction to MySQL & SQL. 2 MySQL Relational Database Management System Competitors –Oracle –IBM DB2 –MS SQL-Server –These offer more facilities.
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.
Fox MIS Spring 2011 Database Week 6 ERD and SQL Exercise.
Sql DDL queries CS 260 Database Systems.
Introduction to MySQL Lab no. 9 Advance Database Management System.
1 CS 430 Database Theory Winter 2005 Lecture 10: Introduction to SQL.
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
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.
LECTURE FOUR Introduction to SQL DDL with tables DML with tables.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Intro to MySQL.
Lecture 1.21 SQL Introduction Steven Jones, Genome Sciences Centre.
CC ICT-SUD Installation and configuration
Data Model / Database Implementation Jeffery S. Horsburgh Hydroinformatics Fall 2015 This work was funded by National Science Foundation Grants EPS
Database commands : DDL
Database Applications and Web-Enabled Databases
Relational Algebra and Calculus: Introduction to SQL
Michal Kvet Lucia Fidesová
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Data Definition and Data Types
MySQL-Database Jouni Juntunen Oulu University of Applied Sciences
DBW – Data & Databases DBW2017.
Module 2: Creating Data Types and Tables
MYSQL INTERVIEW QUESTIONS AND ANSWERS
Lecture 6 Data Model Design (continued)
Attributes and Domains
Data Resources Management
Database systems Lecture 2 – Data Types
CIS 136 Building Mobile Apps
Chapter 4 Introduction to MySQL.
Data.
MySQL Database System Installation Overview SQL summary
Kirkwood Center for Continuing Education
Database Instructor: Bei Kang.
SQL (Structured Query Language)
Presentation transcript:

VTYS 2012 Mehmet Emin KORKUSUZ Ders - 03

 Create  Alter  Drop Data Defination Language

 Database  Table  Procedure ve Function  Index  View  Trigger Create

CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name [create_specification]... create_specification: [DEFAULT] CHARACTER SET [=] charset_name | [DEFAULT] COLLATE [=] collation_name Create Database

create database if not exist Bilgi_Sistemi char set utf8 collate utf8_turkish_ci; Default create database if not exist Bilgi_Sistemi default char set utf8 default collate utf8_turkish_ci;

CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name (create_definition,...) [table_options] Create Table CREATE TABLE ornek( id INT, data VARCHAR(100) );

 {ENGINE|TYPE} [=] engine_name  AUTO_INCREMENT [=] value |  AVG_ROW_LENGTH [=] value  [DEFAULT] CHARACTER SET [=] charset_name  CHECKSUM [=] {0 | 1}  [DEFAULT] COLLATE [=] collation_name  COMMENT [=] 'string'  CONNECTION [=] 'connect_string'  DATA DIRECTORY [=] 'absolute path to directory'  DELAY_KEY_WRITE [=] {0 | 1} Table Options

 INDEX DIRECTORY [=] 'absolute path to directory'  INSERT_METHOD [=] { NO | FIRST | LAST } | MAX_ROWS [=] value | MIN_ROWS [=] value | PACK_KEYS [=] {0 | 1 | DEFAULT} | PASSWORD [=] 'string' | ROW_FORMAT [=] {DEFAULT|DYNAMIC|FIXED|COMPRESSED|REDUNDAN T|COMPACT} | UNION [=] (tbl_name[,tbl_name]...) Table Options

Storage EngineDescription InnoDBTransaction-safe tables with row locking and foreign keys. The default storage engine for new tables. See Section 13.2, “The InnoDB Storage Engine”, and in particular Section , “InnoDB as the Default MySQL Storage Engine” if you have MySQL experience but are new to InnoDB.Section 13.2, “The InnoDB Storage Engine”Section , “InnoDB as the Default MySQL Storage Engine” MyISAMThe binary portable storage engine that is primarily used for read-only or read- mostly workloads. See Section 13.3, “The MyISAM Storage Engine”.Section 13.3, “The MyISAM Storage Engine” MEMORYThe data for this storage engine is stored only in memory. See Section 13.4, “The MEMORY Storage Engine”.Section 13.4, “The MEMORY Storage Engine” CSVTables that store rows in comma-separated values format. See Section 13.5, “The CSV Storage Engine”.Section 13.5, “The CSV Storage Engine” ARCHIVEThe archiving storage engine. See Section 13.6, “The ARCHIVE Storage Engine”.Section 13.6, “The ARCHIVE Storage Engine” EXAMPLEAn example engine. See Section 13.10, “The EXAMPLE Storage Engine”.Section 13.10, “The EXAMPLE Storage Engine” FEDERATEDStorage engine that accesses remote tables. See Section 13.9, “The FEDERATED Storage Engine”.Section 13.9, “The FEDERATED Storage Engine” HEAPThis is a synonym for MEMORY. MERGEA collection of MyISAM tables used as one table. Also known as MRG_MyISAM. See Section 13.8, “The MERGE Storage Engine”.Section 13.8, “The MERGE Storage Engine” ISAM(OBSOLETE)Not available in MySQL 5.6. If you are upgrading to MySQL 5.6 from a previous version, you should convert any existing ISAM tables to MyISAM beforeperforming the upgrade.

Data Type  BIT[(length)]  TINYINT[(length)] [UNSIGNED] [ZEROFILL]  SMALLINT[(length)] [UNSIGNED] [ZEROFILL]  MEDIUMINT[(length)] [UNSIGNED] [ZEROFILL]  INT[(length)] [UNSIGNED] [ZEROFILL]  INTEGER[(length)[UNSIGNED] [ZEROFILL]  BIGINT[(length)] [UNSIGNED] [ZEROFILL]  REAL[(length,decimals)] [UNSIGNED] [ZEROFILL]  DOUBLE[(length,decimals)] [UNSIGNED] [ZEROFILL]  FLOAT[(length,decimals)] [UNSIGNED] [ZEROFILL  DECIMAL[(length[,decimals])] [UNSIGNED] [ZEROFILL]  NUMERIC[(length[,decimals])] [UNSIGNED] [ZEROFILL]

integer TypeStorageMinimum ValueMaximum Value (Bytes)(Signed/Unsigned)Signed/Unsigned) TINYINT SMALLINT MEDIUMINT INT BIGINT

 DATE  TIME  TIMESTAMP  DATETIME  YEAR  CHAR[(length)] [CHARACTER SET charset_name] [COLLATE collation_name]  VARCHAR(length) [CHARACTER SET charset_name] [COLLATE collation_name]  BINARY[(length)] | VARBINARY(length) Data Type

Date-Time Data Type“Zero” Value DATE' ' TIME'00:00:00' DATETIME' :00:00' TIMESTAMP' :00:00' YEAR0000

Char - Varchar ValueCHAR(4)Storage Required VARCHAR( 4) Storage Required ''' 4 bytes''1 byte 'ab' 4 bytes'ab'3 bytes 'abcd' 4 bytes'abcd'5 bytes 'abcdefgh''abcd'4 bytes'abcd'5 bytes

 TINYBLOB  BLOB  MEDIUMBLOB  LONGBLOB  TINYTEXT [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name]  TEXT [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name]  MEDIUMTEXT [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name]  LONGTEXT [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name]

 ENUM(value1,value2,value3,...) [CHARACTER SET charset_name] [COLLATE collation_name]  SET(value1,value2,value3,...) [CHARACTER SET charset_name] [COLLATE collation_name]

enum  CREATE TABLE sizes ( name ENUM('small', 'medium', 'large') );  ENUM('one', 'two', 'three') ValueIndex NULL ''0 'one'1 'two'2 'three'3

set  CREATE TABLE myset (col SET('a', 'b', 'c', 'd'));  INSERT INTO myset (col) VALUES -> ('a,d'), ('d,a'), ('a,d,a'), ('a,d,d'), ('d,a,d');

CHAR(M)M × w bytes, 0 <= M <= 255, where w is the number of bytes required for the maximum-length character in the character set BINARY(M)M bytes, 0 <= M <= 255 VARCHAR(M), VARBINARY(M)L + 1 bytes if column values require 0 – 255 bytes, L + 2 bytes if values may require more than 255 bytes TINYBLOBTINYBLOB, TINYTEXTTINYTEXTL + 1 bytes, where L < 2 8 BLOBBLOB, TEXTTEXTL + 2 bytes, where L < 2 16 MEDIUMBLOBMEDIUMBLOB, MEDIUMTEXTMEDIUMTEXTL + 3 bytes, where L < 2 24 LONGBLOBLONGBLOB, LONGTEXTLONGTEXTL + 4 bytes, where L < 2 32 ENUM('value1','value2',...)1 or 2 bytes, depending on the number of enumeration values (65,535 values maximum) SET('value1','value2',...)1, 2, 3, 4, or 8 bytes, depending on the number of set members (64 members maximum)

Diğer tipler Other Vendor TypeMySQL Type BOOLTINYINT BOOLEANTINYINT CHARACTER VARYING(M)VARCHAR(M) FIXEDDECIMAL FLOAT4FLOAT FLOAT8DOUBLE INT1TINYINT INT2SMALLINT INT3MEDIUMINT INT4INT INT8BIGINT LONG VARBINARYMEDIUMBLOB LONG VARCHARMEDIUMTEXT LONGMEDIUMTEXT MIDDLEINTMEDIUMINT NUMERICDECIMAL

Mevcut Tabloyu Kopyalamak  CREATE TABLE new_tbl SELECT * FROM orig_tbl;  CREATE TABLE new_tbl LIKE orig_tbl;

Alter database  ALTER {DATABASE | SCHEMA} [db_name] alter_specification...  ALTER {DATABASE | SCHEMA} db_name UPGRADE DATA DIRECTORY NAME  alter_specification: [DEFAULT] CHARACTER SET [=] charset_name | [DEFAULT] COLLATE [=] collation_name

Alter table  ALTER [IGNORE] TABLE tbl_name [alter_specification [, alter_specification]...] [partition_options]

 Add  Change  Modify  Drop  Rename  Order by

 ALTER TABLE Example ADD ID INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (ID);  ALTER TABLE Example ADD UNIQUE (URL);  ALTER TABLE testalter_tbl DROP i;  ALTER TABLE testalter_tbl ADD i INT FIRST;  ALTER TABLE testalter_tbl DROP i;  ALTER TABLE testalter_tbl ADD i INT AFTER c;

 ALTER TABLE testalter_tbl MODIFY c CHAR(10);  ALTER TABLE testalter_tbl CHANGE i j BIGINT;  ALTER TABLE testalter_tbl CHANGE j j INT;  ALTER TABLE testalter_tbl MODIFY j BIGINT NOT NULL DEFAULT 100;

 ALTER TABLE testalter_tbl engine= MYISAM;  SHOW TABLE STATUS LIKE 'testalter_tbl‘;  ALTER TABLE testalter_tbl RENAME TO alter_tbl;  ALTER TABLE testalter_tbl ORDER BY name;

rename  RENAME TABLE old_table TO backup_table, new_table TO old_table;

truncate  Truncate old_friends;

 DROP {DATABASE | SCHEMA} [IF EXISTS] db_name  Drop if exists veritabani;  DROP [TEMPORARY] TABLE [IF EXISTS] tbl_name [, tbl_name]... [RESTRICT | CASCADE]  Drop tablo; Drop

Veri Girişi Load data, insert

LOAD DATA INFILE

[LOCAL] [LOW_PRIORITY | CONCURRENT]  [LOCAL] ifadesi veri alınacak dosyanın yerelde yani bu bilgisayarda olduğunu ifade eder.  [LOW_PRIORITY] Veri tabanından bilgi istenirken işlem önceliğinin olmayacağını belirten bir komuttur.  [CONCURRENT] ifadesi ise veri tabanında bilgi istenildiği zaman eş zamanlı olarak çağırmak içindir.

LOAD DATA [LOCAL] INFILE “C:/Users/Desktop/açık_dosya_adı” INTO TABLE tablo_ad COLUMNS ESCAPED BY “,” LINES TERMINATED BY “-”;

Select into outfile Select into outfile load data infile komutunun tam tersini yapmaktadır. Tablodaki verileri harici bir dosyaya yazdırmaya yarar. SELECT * INTO OUTFILE “dosya_yolu” [FIELDS | COLUMNS] [TERMINATED | ESCAPED] BY “karekter” LINES [TERMINATED | STARTING] BY “karakter” FROM tablo_adı;

UYGULAMA SELECT * INTO OUTFILE “C:/Users/Desktop/dosya_adı_ve_uzantısı ” INTO TABLE tablo_adı COLUMNS ESCAPED BY “,” LINES TERMINATED BY “-” FROM tablo_ad; SELECT alan1,alan2,alan7 INTO OUTFILE “C:/Users/Desktop/dosya_adı_ve_uzantısı” INTO TABLE tablo_adı COLUMNS ESCAPED BY “;” LINES TERMINATED BY “\n” FROM tablo_ad;