Sql Bag 1 Ddl

  • Uploaded by: Euis Marlina
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Sql Bag 1 Ddl as PDF for free.

More details

  • Words: 493
  • Pages: 11
SQL (Structure Query Language) – MySQL (Bagian 1 : DDL)

 Perintah

SQL untuk membuat database di Windows dan Linux adalah sama.  SQL-nya: create database nama_database; 

Misalnya kita akan membuat database pegawai, maka perintahnya : create database pegawai;

 Databases

store data in tables.  A database can have many tables. In simplest terms, tables consist of rows and columns/field.  Each column defines data of a particular type.  Each rows contain individual records.

 SQL-nya:

CREATE TABLE ( nama_field_1 nama_field_2 nama_field_3 nama_field_n );

nama_tabel tipe_data_1, tipe_data_2, tipe_data_3, tipe_data_n

In MySQL, commands and column names are not case-sensitive; however, table and database names might be sensitive to case depending on the platform (as in Linux). You can thus, use create table instead of CREATE TABLE.

 The

three major types of column types used in MySQL are: 1. Integer : 2. Text 3. Date

 Choosing

a column data type is very important in order to achieve speed, effective storage and retrieval.



      

Each integer type can take also be UNSIGNED and/or AUTO_INCREMENT.

TINYINT: very small numbers; suitable for ages. Actually, we should have used this data type for employee ages and number of children. Can store numbers between 0 to 255 if UNSIGNED clause is applied, else the range is between -128 to 127. SMALLINT: Suitable for numbers between 0 to 65535 (UNSIGNED) or -32768 to 32767. MEDIUMINT: 0 to 16777215 with UNSIGNED clause or -8388608 to 8388607. INT: UNSIGNED integers fall between 0 to 4294967295 or -2147683648 to 2147683647. BIGINT: Huge numbers. (-9223372036854775808 to 9223372036854775807) FLOAT: Floating point numbers (single precision) DOUBLE: Floating point numbers (double precision) DECIMAL:Floating point numbers represented as strings.

          

CHAR(x): where x can range from 1 to 255. VARCHAR(x): x ranges from 1 - 255 TINYTEXT: small text, case insensitive TEXT: slightly longer text, case insensitive MEDIUMTEXT: medium size text, case insensitive LONGTEXT: really long text, case insensitive TINYBLOB: Blob means a Binary Large OBject. You should use blobs for case sensitive searches. BLOB: slightly larger blob, case sensitive. MEDIUMBLOB: medium sized blobs, case sensitive. LONGBLOB: really huge blobs, case sensitive. ENUM: Enumeration data type have fixed values and the column can take only one value from the given set. The values are placed in parenthesis following ENUM declaration. An example, is the marital status.

 DATE:

YYYY-MM-DD (Four digit year followed by two digit month and date)  TIME: hh:mm:ss (Hours:Minutes:Seconds)  DATETIME: YYYY-MM-DD hh:mm:ss (Date and time separated by a space character)  TIMESTAMP: YYYYMMDDhhmmss

 Pada

database pegawai, kita membuat tabel data_pegawai dengan field/column id_pegawai, nama_pegawai, alamat_pegawai. Perintah SQL-nya adalah:

CREATE TABLE data_pegawai (

id_pegawai int unsigned not null auto_increment primary key, nama_pegawai varchar(20), alamat_pegawai varchar(20) );

 Untuk

menghapus semua isi tabel : DELETE from nama_tabel;

 Untuk

menghapus tabel: DROP TABLE nama_tabel;

 Misalnya

: DELETE from data_pegawai; DROP TABLE data_pegawai;

Related Documents

Sql Bag 1 Ddl
May 2020 7
Ddl
November 2019 17
Ddl
May 2020 17
Sql Bag 2 Dml
May 2020 13
Sql Bag 3 Join Tabel
May 2020 21

More Documents from "Euis Marlina"