Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "VTYS 2012 Mehmet Emin KORKUSUZ Ders - 03.  Create  Alter  Drop Data Defination Language."— Presentation transcript:

1 VTYS 2012 Mehmet Emin KORKUSUZ Ders - 03

2  Create  Alter  Drop Data Defination Language

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

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

5 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;

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

7  {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

8  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

9 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.

10 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]

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

12  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

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

14 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

15  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]

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

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

18 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');

19 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)

20 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

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

22 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

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

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

25  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;

26  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;

27  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;

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

29 truncate  Truncate old_friends;

30  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

31 Veri Girişi Load data, insert

32 LOAD DATA INFILE

33 [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.

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

35 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ı;

36 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;


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

Similar presentations


Ads by Google