0% found this document useful (0 votes)
11 views5 pages

Modul 3 MBD

The document shows SQL commands used to create databases and tables in MariaDB. It creates databases called db_universitas and pegawai_018, and within pegawai_018 creates tables called pribadi, pekerjaan, and bagian to store employee data. It then alters the tables by changing column names and types.

Uploaded by

mohammadhasan90
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views5 pages

Modul 3 MBD

The document shows SQL commands used to create databases and tables in MariaDB. It creates databases called db_universitas and pegawai_018, and within pegawai_018 creates tables called pribadi, pekerjaan, and bagian to store employee data. It then alters the tables by changing column names and types.

Uploaded by

mohammadhasan90
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Microsoft Windows [Version 10.0.17134.

648]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\Asus>cd/xampp/mysql/bin

C:\xampp\mysql\bin>mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.1.10-MariaDB mariadb.org binary distribution

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE database db_universitas;


Query OK, 1 row affected (0.07 sec)

MariaDB [(none)]> show databases;


+--------------------+
| Database |
+--------------------+
| bress |
| db_universitas |
| information_schema |
| mysql |
| performance_schema |
| phpmyadmin |
| test |
+--------------------+
7 rows in set (0.02 sec)

MariaDB [(none)]> DROP database db_universitas;


Query OK, 0 rows affected (0.09 sec)

MariaDB [(none)]> show databases;


+--------------------+
| Database |
+--------------------+
| bress |
| information_schema |
| mysql |
| performance_schema |
| phpmyadmin |
| test |
+--------------------+
6 rows in set (0.00 sec)

MariaDB [(none)]> CREATE database pegawai_018;


Query OK, 1 row affected (0.01 sec)

MariaDB [(none)]> show databases;


+--------------------+
| Database |
+--------------------+
| bress |
| information_schema |
| mysql |
| pegawai_018 |
| performance_schema |
| phpmyadmin |
| test |
+--------------------+
7 rows in set (0.00 sec)

MariaDB [(none)]> use pegawai_018;


Database changed
MariaDB [pegawai_018]> CREATE TABLE pribadi (Nip(6) NOT NULL PRIMARY KEY,Nama
VARCHAR(35) not NULL,Tgl_lahir DATE NOT NULL,Sex ENUM('P','W'),Alamat
VARCHAR(35),KOTA VARCHAR(15));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near '(6)
NOT NULL PRIMARY KEY,Nama VARCHAR(35) not NULL,Tgl_lahir DATE NOT NULL,Sex E' at
line 1
MariaDB [pegawai_018]> Create TABLE Pribadi (NIP(6) NOT NULL PRIMARY KEY,
-> Nama VARCHAR(35) NOT NULL,
-> Tgl_lahir DATE,
-> SEX ENUM('P','W'),
-> Alamat VARCHAR(35),
-> KOTA VARCHAR(15));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near '(6)
NOT NULL PRIMARY KEY,
Nama VARCHAR(35) NOT NULL,
Tgl_lahir DATE,
SEX ENUM('P' at line 1
MariaDB [pegawai_018]> Create TABLE Pribadi (NIP char(6) NOT NULL PRIMARY KEY,
-> Nama VARCHAR(35) NOT NULL,
-> Tgl_lahir DATE,
-> SEX ENUM('P','W'),
-> Alamat VARCHAR(35),
-> KOTA VARCHAR(15));
Query OK, 0 rows affected (0.30 sec)

MariaDB [pegawai_018]> desc table pribadi;


ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near 'table
pribadi' at line 1
MariaDB [pegawai_018]> desc table pribadi;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near 'table
pribadi' at line 1
MariaDB [pegawai_018]> show tables;
+-----------------------+
| Tables_in_pegawai_018 |
+-----------------------+
| pribadi |
+-----------------------+
1 row in set (0.00 sec)

MariaDB [pegawai_018]> desc pribadi;


+-----------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------------+------+-----+---------+-------+
| NIP | char(6) | NO | PRI | NULL | |
| Nama | varchar(35) | NO | | NULL | |
| Tgl_lahir | date | YES | | NULL | |
| SEX | enum('P','W') | YES | | NULL | |
| Alamat | varchar(35) | YES | | NULL | |
| KOTA | varchar(15) | YES | | NULL | |
+-----------+---------------+------+-----+---------+-------+
6 rows in set (0.04 sec)

MariaDB [pegawai_018]> create table pekerjaan (


-> Nip char(6) NOT NULL PRIMARY KEY,
-> Tgl_masuk DATE,
-> Kode_bag CHAR(10) NOT NULL,
-> Gaji INT);
Query OK, 0 rows affected (0.30 sec)

MariaDB [pegawai_018]> SHOW TABLES;


+-----------------------+
| Tables_in_pegawai_018 |
+-----------------------+
| pekerjaan |
| pribadi |
+-----------------------+
2 rows in set (0.00 sec)

MariaDB [pegawai_018]> desc pekerjaan;


+-----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------+------+-----+---------+-------+
| Nip | char(6) | NO | PRI | NULL | |
| Tgl_masuk | date | YES | | NULL | |
| Kode_bag | char(10) | NO | | NULL | |
| Gaji | int(11) | YES | | NULL | |
+-----------+----------+------+-----+---------+-------+
4 rows in set (0.03 sec)

MariaDB [pegawai_018]> Create Table Bagian (


-> Kode_bag CHAR(5) Not NULL PRIMARY KEY,
-> Nama_bag VARCHAR(20) NOT NULL,
-> );
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near ')' at
line 4
MariaDB [pegawai_001]> Create Table Bagian (
-> Kode_bag CHAR(5) Not NULL PRIMARY KEY,
-> Nama_bag VARCHAR(20) NOT NULL);
Query OK, 0 rows affected (0.27 sec)

MariaDB [pegawai_018]> show tables;


+-----------------------+
| Tables_in_pegawai_018 |
+-----------------------+
| bagian |
| pekerjaan |
| pribadi |
+-----------------------+
3 rows in set (0.00 sec)

MariaDB [pegawai_018]> desc bagian;


+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| Kode_bag | char(5) | NO | PRI | NULL | |
| Nama_bag | varchar(20) | NO | | NULL | |
+----------+-------------+------+-----+---------+-------+
2 rows in set (0.03 sec)

MariaDB [pegawai_018]> ALTER table pribadi CHANE sex kelamin ENUM('P','W');


ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near 'sex
kelamin ENUM('P','W')' at line 1
MariaDB [pegawai_018]> ALTER table pribadi CHANgE sex kelamin ENUM('P','W');
Query OK, 0 rows affected (0.16 sec)
Records: 0 Duplicates: 0 Warnings: 0

MariaDB [pegawai_018]> desc pribadi;


+-----------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------------+------+-----+---------+-------+
| NIP | char(6) | NO | PRI | NULL | |
| Nama | varchar(35) | NO | | NULL | |
| Tgl_lahir | date | YES | | NULL | |
| kelamin | enum('P','W') | YES | | NULL | |
| Alamat | varchar(35) | YES | | NULL | |
| KOTA | varchar(15) | YES | | NULL | |
+-----------+---------------+------+-----+---------+-------+
6 rows in set (0.03 sec)

MariaDB [pegawai_018]> Alter table pribadi CHANGE kota KOTA VARCHAR(20);


Query OK, 0 rows affected (0.58 sec)
Records: 0 Duplicates: 0 Warnings: 0

MariaDB [pegawai_018]> desc pribadi;


+-----------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------------+------+-----+---------+-------+
| NIP | char(6) | NO | PRI | NULL | |
| Nama | varchar(35) | NO | | NULL | |
| Tgl_lahir | date | YES | | NULL | |
| kelamin | enum('P','W') | YES | | NULL | |
| Alamat | varchar(35) | YES | | NULL | |
| KOTA | varchar(20) | YES | | NULL | |
+-----------+---------------+------+-----+---------+-------+
6 rows in set (0.03 sec)

MariaDB [pegawai_018]> Alter table pribadi change kelamin kelamin ENUM('P','W')


default 'P';
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0

MariaDB [pegawai_018]> desc pribadi;


+-----------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------------+------+-----+---------+-------+
| NIP | char(6) | NO | PRI | NULL | |
| Nama | varchar(35) | NO | | NULL | |
| Tgl_lahir | date | YES | | NULL | |
| kelamin | enum('P','W') | YES | | P | |
| Alamat | varchar(35) | YES | | NULL | |
| KOTA | varchar(20) | YES | | NULL | |
+-----------+---------------+------+-----+---------+-------+
6 rows in set (0.03 sec)
MariaDB [pegawai_018]>

You might also like