Bani Tugas1 Basis Data

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

Jawaban No.

1
MariaDB [(none)]> create database dbpegawai;
Query OK, 1 row affected (0.002 sec)

Jawaban No.2
MariaDB [(none)]> use dbpegawai;
Database changed

Jawaban No.3
MariaDB [dbpegawai]> create table divisi(id int primary key auto_increment,nama
VARCHAR(30) NOT NULL UNIQUE);
Query OK, 0 rows affected (0.023 sec)

Jawaban No.4
MariaDB [dbpegawai]> desc divisi;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| nama | varchar(30) | NO | UNI | NULL | |
+-------+-------------+------+-----+---------+----------------+
2 rows in set (0.010 sec)

Jawaban No.5
MariaDB [dbpegawai]> create table jabatan(id int primary key auto_increment,nama
VARCHAR(30) NOT NULL UNIQUE);
Query OK, 0 rows affected (0.020 sec)

Jawaban No.6
MariaDB [dbpegawai]> desc jabatan;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| nama | varchar(30) | NO | UNI | NULL | |
+-------+-------------+------+-----+---------+----------------+
2 rows in set (0.011 sec)(id int primary key auto_increment,nama VARCHAR(30) NOT
NULL UNIQUE);
Query OK, 0 rows affected (0.020 sec)

Jawaban No.7
MariaDB [dbpegawai]> create table pegawai(id INT PRIMARY KEY AUTO_INCREMENT,nip
CHAR(5) NOT NULL UNIQUE,nama VARCHAR(30) NOT NULL,gender ENUM('Laki-
Laki','Perempuan') NOT NULL,tmp_lahir VARCHAR(30) NOT NULL,tgl_lahir DATE NOT
NULL,iddivisi INT NOT NULL,idjabatan INT NOT NULL,alamat TEXT,FOREIGN KEY
(iddivisi) REFERENCES divisi(id),FOREIGN KEY (idjabatan) REFERENCES jabatan(id));
Query OK, 0 rows affected (0.022 sec)

Jawaban No.8
MariaDB [dbpegawai]> desc pegawai;
+-----------+-------------------------------+------+-----+---------
+----------------+
| Field | Type | Null | Key | Default | Extra
|
+-----------+-------------------------------+------+-----+---------
+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment
|
| nip | char(5) | NO | UNI | NULL |
|
| nama | varchar(30) | NO | | NULL |
|
| gender | enum('Laki-Laki','Perempuan') | NO | | NULL |
|
| tmp_lahir | varchar(30) | NO | | NULL |
|
| tgl_lahir | date | NO | | NULL |
|
| iddivisi | int(11) | NO | MUL | NULL |
|
| idjabatan | int(11) | NO | MUL | NULL |
|
| alamat | text | YES | | NULL |
|
+-----------+-------------------------------+------+-----+---------
+----------------+
9 rows in set (0.011 sec)

Jawaban No.9
MariaDB [dbpegawai]> show tables from dbpegawai;
+---------------------+
| Tables_in_dbpegawai |
+---------------------+
| divisi |
| jabatan |
| pegawai |
+---------------------+
3 rows in set (0.001 sec)

Jawaban No.10
MariaDB [dbpegawai]> insert into divisi (nama) values ('SDM'), ('Keuangan'),
('Marketing'), ('IT');
Query OK, 4 rows affected (0.002 sec)
Records: 4 Duplicates: 0 Warnings: 0

Jawaban No.11
MariaDB [dbpegawai]> select * from divisi;
+----+-----------+
| id | nama |
+----+-----------+
| 4 | IT |
| 2 | Keuangan |
| 3 | Marketing |
| 1 | SDM |
+----+-----------+
4 rows in set (0.000 sec)

Jawaban No.12
MariaDB [dbpegawai]> insert into jabatan (nama) values ('Direktur'), ('Manajer'),
('Asisten Manajer'), ('Staff');
Query OK, 4 rows affected (0.003 sec)
Records: 4 Duplicates: 0 Warnings: 0

Jawaban No.13
MariaDB [dbpegawai]> select * from jabatan;
+----+-----------------+
| id | nama |
+----+-----------------+
| 3 | Asisten Manajer |
| 1 | Direktur |
| 2 | Manajer |
| 4 | Staff |
+----+-----------------+
4 rows in set (0.000 sec)

Jawaban No.14
## iddivisi 1 = SDM
MariaDB [dbpegawai]> insert into pegawai (nip, nama, gender, tmp_lahir, tgl_lahir,
iddivisi, idjabatan, alamat)
-> values
-> ('12345', 'Kairi', 'Laki-Laki', 'Jakarta', '2000-01-01', 1, RAND()*4+1,
'Tapos'),
-> ('23456', 'Kayes', 'Perempuan', 'Jakarta', '2000-02-02', 1, RAND()*4+1,
'Depok'),
-> ('34567', 'SANG ERROR', 'Laki-Laki', 'Jakarta', '2000-03-03', 1,
RAND()*4+1, 'Kelapa Dua'),
-> ('45678', 'MURID ERROR', 'Perempuan', 'Depok', '2000-04-04', 1,
RAND()*4+1, 'Kelapa Gading'),
-> ('56789', 'Rejoice', 'Laki-Laki', 'Ujung Aspal', '2000-05-05', 1,
RAND()*4+1, 'Banten');
Query OK, 5 rows affected (0.008 sec)
Records: 5 Duplicates: 0 Warnings: 0

## iddivisi 2 = Marketing
MariaDB [dbpegawai]> insert into pegawai (nip, nama, gender, tmp_lahir, tgl_lahir,
iddivisi, idjabatan, alamat)
-> values
-> ('67890', 'Nama6', 'Perempuan', 'Tempat6', '2000-06-06', 2, RAND()*4+1,
'Alamat6'),
-> ('78901', 'Nama7', 'Laki-Laki', 'Tempat7', '2000-07-07', 2, RAND()*4+1,
'Alamat7'),
-> ('89012', 'Nama8', 'Perempuan', 'Tempat8', '2000-08-08', 2, RAND()*4+1,
'Alamat8'),
-> ('90123', 'Nama9', 'Laki-Laki', 'Tempat9', '2000-09-09', 2, RAND()*4+1,
'Alamat9'),
-> ('01234', 'Nama10', 'Perempuan', 'Tempat10', '2000-10-10', 2,
RAND()*4+1, 'Alamat10');
Query OK, 5 rows affected (0.005 sec)
Records: 5 Duplicates: 0 Warnings: 0

## iddivisi 3 = Keuangan
MariaDB [dbpegawai]> insert into pegawai (nip, nama, gender, tmp_lahir, tgl_lahir,
iddivisi, idjabatan, alamat)
-> values
-> ('02291', 'Nama11', 'Laki-Laki', 'Tempat11', '2000-11-11', 3,
RAND()*4+1, 'Alamat11'),
-> ('02231', 'Nama12', 'Perempuan', 'Tempat12', '2000-12-12', 3,
RAND()*4+1, 'Alamat12'),
-> ('02292', 'Nama13', 'Laki-Laki', 'Tempat13', '2000-01-13', 3,
RAND()*4+1, 'Alamat13'),
-> ('02290', 'Nama14', 'Perempuan', 'Tempat14', '2000-02-14', 3,
RAND()*4+1, 'Alamat14'),
-> ('02234', 'Nama15', 'Laki-Laki', 'Tempat15', '2000-03-15', 3,
RAND()*4+1, 'Alamat15');
Query OK, 5 rows affected (0.004 sec)
Records: 5 Duplicates: 0 Warnings: 0

## iddivisi 4 = IT
MariaDB [dbpegawai]> insert into pegawai (nip, nama, gender, tmp_lahir, tgl_lahir,
iddivisi, idjabatan, alamat)
-> values
-> ('09212', 'Nama16', 'Perempuan', 'Tempat16', '2000-04-16', 4,
RAND()*4+1, 'Alamat16'),
-> ('23491', 'Nama17', 'Laki-Laki', 'Tempat17', '2000-05-17', 4,
RAND()*4+1, 'Alamat17'),
-> ('40342', 'Nama18', 'Perempuan', 'Tempat18', '2000-06-18', 4,
RAND()*4+1, 'Alamat18'),
-> ('00991', 'Nama19', 'Laki-Laki', 'Tempat19', '2000-07-19', 4,
RAND()*4+1, 'Alamat19'),
-> ('12299', 'Nama20', 'Perempuan', 'Tempat20', '2000-08-20', 4,
RAND()*4+1, 'Alamat20');
Query OK, 5 rows affected (0.003 sec)
Records: 5 Duplicates: 0 Warnings: 0

Jawaban No.15
MariaDB [dbpegawai]> select * from pegawai;
+----+-------+-------------+-----------+-------------+------------+----------
+-----------+---------------+
| id | nip | nama | gender | tmp_lahir | tgl_lahir | iddivisi |
idjabatan | alamat |
+----+-------+-------------+-----------+-------------+------------+----------
+-----------+---------------+
| 1 | 12345 | Kairi | Laki-Laki | Jakarta | 2000-01-01 | 1 |
3 | Tapos |
| 2 | 23456 | Kayes | Perempuan | Jakarta | 2000-02-02 | 1 |
3 | Depok |
| 3 | 34567 | SANG ERROR | Laki-Laki | Jakarta | 2000-03-03 | 1 |
3 | Kelapa Dua |
| 4 | 45678 | MURID ERROR | Perempuan | Depok | 2000-04-04 | 1 |
2 | Kelapa Gading |
| 5 | 56789 | Rejoice | Laki-Laki | Ujung Aspal | 2000-05-05 | 1 |
4 | Banten |
| 11 | 67890 | Nama6 | Perempuan | Tempat6 | 2000-06-06 | 2 |
3 | Alamat6 |
| 12 | 78901 | Nama7 | Laki-Laki | Tempat7 | 2000-07-07 | 2 |
3 | Alamat7 |
| 13 | 89012 | Nama8 | Perempuan | Tempat8 | 2000-08-08 | 2 |
3 | Alamat8 |
| 14 | 90123 | Nama9 | Laki-Laki | Tempat9 | 2000-09-09 | 2 |
3 | Alamat9 |
| 15 | 01234 | Nama10 | Perempuan | Tempat10 | 2000-10-10 | 2 |
3 | Alamat10 |
| 26 | 02291 | Nama11 | Laki-Laki | Tempat11 | 2000-11-11 | 3 |
1 | Alamat11 |
| 27 | 02231 | Nama12 | Perempuan | Tempat12 | 2000-12-12 | 3 |
3 | Alamat12 |
| 28 | 02292 | Nama13 | Laki-Laki | Tempat13 | 2000-01-13 | 3 |
4 | Alamat13 |
| 29 | 02290 | Nama14 | Perempuan | Tempat14 | 2000-02-14 | 3 |
3 | Alamat14 |
| 30 | 02234 | Nama15 | Laki-Laki | Tempat15 | 2000-03-15 | 3 |
4 | Alamat15 |
| 36 | 09212 | Nama16 | Perempuan | Tempat16 | 2000-04-16 | 4 |
2 | Alamat16 |
| 37 | 23491 | Nama17 | Laki-Laki | Tempat17 | 2000-05-17 | 4 |
3 | Alamat17 |
| 38 | 40342 | Nama18 | Perempuan | Tempat18 | 2000-06-18 | 4 |
1 | Alamat18 |
| 39 | 00991 | Nama19 | Laki-Laki | Tempat19 | 2000-07-19 | 4 |
3 | Alamat19 |
| 40 | 12299 | Nama20 | Perempuan | Tempat20 | 2000-08-20 | 4 |
4 | Alamat20 |
+----+-------+-------------+-----------+-------------+------------+----------
+-----------+---------------+
20 rows in set (0.002 sec)

Jawaban No.16
MariaDB [dbpegawai]> update pegawai set nama = 'NamaBaru1', gender = 'Perempuan',
alamat = 'AlamatBaru1'where id = 1;
Query OK, 1 row affected (0.002 sec)
Rows matched: 1 Changed: 1 Warnings: 0

MariaDB [dbpegawai]> update pegawai set nama = 'NamaBaru2', gender = 'Perempuan',


alamat = 'AlamatBaru2'where id = 2;
Query OK, 1 row affected (0.003 sec)
Rows matched: 1 Changed: 1 Warnings: 0

MariaDB [dbpegawai]> update pegawai set nama = 'NamaBaru3', gender = 'Perempuan',


alamat = 'AlamatBaru3'where id = 3;
Query OK, 1 row affected (0.004 sec)
Rows matched: 1 Changed: 1 Warnings: 0

MariaDB [dbpegawai]> update pegawai set nama = 'NamaBaru4', gender = 'Perempuan',


alamat = 'AlamatBaru4'where id = 4;
Query OK, 1 row affected (0.004 sec)
Rows matched: 1 Changed: 1 Warnings: 0

MariaDB [dbpegawai]> update pegawai set nama = 'NamaBaru5', gender = 'Perempuan',


alamat = 'AlamatBaru5'where id = 5;
Query OK, 1 row affected (0.003 sec)
Rows matched: 1 Changed: 1 Warnings: 0

Jawaban No.17
MariaDB [dbpegawai]> delete from pegawai order by id desc limit 2;
Query OK, 2 rows affected (0.004 sec)

Jawaban No.18
MariaDB [dbpegawai]> alter table pegawai add column berat_badan float not null;
Query OK, 0 rows affected (0.010 sec)
Records: 0 Duplicates: 0 Warnings: 0

MariaDB [dbpegawai]> update pegawai set berat_badan = ROUND(RAND() * (100 - 40) +


40, 2);
Query OK, 18 rows affected (0.007 sec)
Rows matched: 18 Changed: 18 Warnings: 0

Jawaban No.19

You might also like