Database 31-11-2024
# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.4.32-MariaDB mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| indomart |
| information_schema |
| mysql |
| penjualan |
| performance_schema |
| phpmyadmin |
+--------------------+
6 rows in set (0.001 sec)
MariaDB [(none)]> use database penjualan;
ERROR 1049 (42000): Unknown database 'database'
MariaDB [(none)]> use penjualan;
Database changed
MariaDB [penjualan]> create table barang;
ERROR 1050 (42S01): Table 'barang' already exists
MariaDB [penjualan]> use penjualan;
Database changed
MariaDB [penjualan]> show databases;
+--------------------+
| Database |
+--------------------+
| indomart |
| information_schema |
| mysql |
| penjualan |
| performance_schema |
| phpmyadmin |
+--------------------+
6 rows in set (0.001 sec)
MariaDB [penjualan]> create database coba;
Query OK, 1 row affected (0.001 sec)
MariaDB [penjualan]> show databases;
+--------------------+
| Database |
+--------------------+
| coba |
| indomart |
| information_schema |
| mysql |
| penjualan |
| performance_schema |
| phpmyadmin |
+--------------------+
7 rows in set (0.001 sec)
MariaDB [penjualan]> use coba
Database changed
MariaDB [coba]> create table barang (
-> id_brg int (11) primary key auto_increment,
-> nama_brg varchar (30),
-> stok int (11),
-> harga int (11));
Query OK, 0 rows affected (0.017 sec)
MariaDB [coba]> create table penjualan (
-> id_brg int(11) primary key auto_increment,
-> nama_brg varchar (30),
-> jumblah int(11),
-> total int
-> total int(11));
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 'int(11))' at line 6
MariaDB [coba]> create table penjualan (
-> id_brg int(11) primary key auto_increment,
-> nama_brg varchar (30),
-> jumblah int(11),
-> total int(11));
Query OK, 0 rows affected (0.012 sec)
MariaDB [coba]> alter table barang add index(nama_brg);
Query OK, 0 rows affected (0.013 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [coba]> ALTER TABLE barang ADD FOGEIGN KEY (nama_brg) REFERENCES barang
(nama_brg) ON DELETE CASCADE ON UPDATE CASCADE;
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 'KEY (nama_brg) REFERENCES barang
(nama_brg) ON DELETE CASCADE ON UPDATE CASCADE' at line 1
MariaDB [coba]> ALTER TABLE penjualan ADD FOGEIGN KEY (nama_brg) REFERENCES
barang(nama_brg) ON DELETE CASCADE ON UPDATE CASCADE;
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 'KEY (nama_brg) REFERENCES
barang(nama_brg) ON DELETE CASCADE ON UPDATE CASCADE' at line 1
MariaDB [coba]> show tables;
+----------------+
| Tables_in_coba |
+----------------+
| barang |
| penjualan |
+----------------+
2 rows in set (0.001 sec)
MariaDB [coba]> desc barang;
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| id_brg | int(11) | NO | PRI | NULL | auto_increment |
| nama_brg | varchar(30) | YES | MUL | NULL | |
| stok | int(11) | YES | | NULL | |
| harga | int(11) | YES | | NULL | |
+----------+-------------+------+-----+---------+----------------+
4 rows in set (0.017 sec)
MariaDB [coba]> desc penjualan;
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| id_brg | int(11) | NO | PRI | NULL | auto_increment |
| nama_brg | varchar(30) | YES | | NULL | |
| jumblah | int(11) | YES | | NULL | |
| total | int(11) | YES | | NULL | |
+----------+-------------+------+-----+---------+----------------+
4 rows in set (0.032 sec)
MariaDB [coba]> alter table barang add index(nama_brg);
Query OK, 0 rows affected, 1 warning (0.011 sec)
Records: 0 Duplicates: 0 Warnings: 1
MariaDB [coba]> alter table penjualan add index(nama_brg);
Query OK, 0 rows affected (0.019 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [coba]> ALTER TABLE penjualan ADD FOGEIGN KEY (nama_brg) REFERENCES
barang(nama_brg) ON DELETE CASCADE ON UPDATE CASCADE;
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 'KEY (nama_brg) REFERENCES
barang(nama_brg) ON DELETE CASCADE ON UPDATE CASCADE' at line 1
MariaDB [coba]> ALTER TABLE penjualan ADD FOREIGN KEY (nama_brg) REFERENCES
barang(nama_brg) ON DELETE CASCADE ON UPDATE CASCADE;
Query OK, 0 rows affected (0.057 sec)
Records: 0 Duplicates: 0 Warnings: 0