0% found this document useful (0 votes)
93 views

Basdat

The document shows the steps of connecting to a MariaDB database named "indoalfa" using MySQL, viewing the existing tables, and modifying the structure of the "promo" table to add a foreign key constraint linking it to the "barang" table. Key events include: - Connecting to the MariaDB server and selecting the "indoalfa" database - Viewing the existing tables, including "barang", "kasir", "promo", and "supplier" - Describing the structure of each table - Dropping and recreating the "promo" table with a foreign key constraint - Inserting sample data into the "kasir" and "supplier" tables

Uploaded by

Ganis Praban's
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)
93 views

Basdat

The document shows the steps of connecting to a MariaDB database named "indoalfa" using MySQL, viewing the existing tables, and modifying the structure of the "promo" table to add a foreign key constraint linking it to the "barang" table. Key events include: - Connecting to the MariaDB server and selecting the "indoalfa" database - Viewing the existing tables, including "barang", "kasir", "promo", and "supplier" - Describing the structure of each table - Dropping and recreating the "promo" table with a foreign key constraint - Inserting sample data into the "kasir" and "supplier" tables

Uploaded by

Ganis Praban's
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/ 3

Microsoft Windows [Version 10.0.17763.

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

C:\Users\ASUS>cd c:\xampp\mysql\bin

c:\xampp\mysql\bin>mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 244
Server version: 10.4.6-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)]> use indoapril;


ERROR 1049 (42000): Unknown database 'indoapril'
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| indoalfa |
| information_schema |
| mysql |
| ojekonline |
| performance_schema |
| phpmyadmin |
| test |
+--------------------+
7 rows in set (0.001 sec)

MariaDB [(none)]> use indoalfa;


Database changed
MariaDB [indoalfa]> show tables;
+--------------------+
| Tables_in_indoalfa |
+--------------------+
| barang |
| kasir |
| promo |
| supplier |
+--------------------+
4 rows in set (0.001 sec)

MariaDB [indoalfa]> desc promo;


+-------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------+------+-----+---------+-------+
| kode barang | int(10) | NO | | NULL | |
| kode promo | int(10) | NO | PRI | NULL | |
+-------------+---------+------+-----+---------+-------+
2 rows in set (0.007 sec)

MariaDB [indoalfa]> desc barang;


+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| jenis_barang | varchar(20) | NO | | NULL | |
| kode_barang | int(11) | NO | PRI | NULL | |
| nama_barang | varchar(20) | NO | | NULL | |
| merk | varchar(20) | NO | | NULL | |
| harga | int(11) | NO | | NULL | |
| stok | int(11) | NO | | NULL | |
+--------------+-------------+------+-----+---------+-------+
6 rows in set (0.007 sec)

MariaDB [indoalfa]> desc kasir;


+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| no_pegawai | int(11) | NO | PRI | NULL | |
| nama_pegawai | varchar(20) | NO | | NULL | |
| pass | int(11) | NO | | NULL | |
+--------------+-------------+------+-----+---------+-------+
3 rows in set (0.008 sec)

MariaDB [indoalfa]> desc supplier;


+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| nama_supplier | varchar(20) | NO | | NULL | |
| no_supplier | int(11) | NO | PRI | NULL | |
+---------------+-------------+------+-----+---------+-------+
2 rows in set (0.007 sec)

MariaDB [indoalfa]> desc barang;


+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| jenis_barang | varchar(20) | NO | | NULL | |
| kode_barang | int(11) | NO | PRI | NULL | |
| nama_barang | varchar(20) | NO | | NULL | |
| merk | varchar(20) | NO | | NULL | |
| harga | int(11) | NO | | NULL | |
| stok | int(11) | NO | | NULL | |
+--------------+-------------+------+-----+---------+-------+
6 rows in set (0.011 sec)

MariaDB [indoalfa]> alter table promo


-> add constraint fk_kode_barang FOREIGN KEY (kode_barang) REFERENCES barang
(kode_barang);
ERROR 1072 (42000): Key column 'kode_barang' doesn't exist in table
MariaDB [indoalfa]> add constraint fk_kode barang FOREIGN KEY (kode barang)
REFERENCES barang (kode_barang);
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 'add
constraint fk_kode barang FOREIGN KEY (kode barang) REFERENCES barang (kode_' at
line 1
MariaDB [indoalfa]> add constraint fk_kodebarang FOREIGN KEY (kodebarang)
REFERENCES barang (kode_barang);
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 'add
constraint fk_kodebarang FOREIGN KEY (kodebarang) REFERENCES barang (kode_ba' at
line 1
MariaDB [indoalfa]> alter table kode barang change kode_barang int (10);
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 'change
kode_barang int (10)' at line 1
MariaDB [indoalfa]> alter table kode barang change kode_barang;
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 'change
kode_barang' at line 1
MariaDB [indoalfa]> drop table promo;
Query OK, 0 rows affected (0.016 sec)

MariaDB [indoalfa]> create table promo(


-> kode_barang int (10) not null,
-> kode_promo int (10) not null primary key);
Query OK, 0 rows affected (0.014 sec)

MariaDB [indoalfa]> ADD CONSTRAINT fk_kode_barang FOREIGN KEY (kode_barang)


REFERENCES barang (kode_barang);
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 'ADD
CONSTRAINT fk_kode_barang FOREIGN KEY (kode_barang) REFERENCES barang (kode_' at
line 1
MariaDB [indoalfa]> alter table promo
-> ADD CONSTRAINT fk_kode_barang FOREIGN KEY (kode_barang) REFERENCES barang
(kode_barang);
Query OK, 0 rows affected (0.055 sec)
Records: 0 Duplicates: 0 Warnings: 0

MariaDB [indoalfa]> insert into kasir


-> values('001','Ganis Dwiarum','Ganis00'),
-> ('002','Amalia Cahya','Amalia123'),
-> ('003','Atania Harfiani','Atan123'),
-> ('004','Indah Kurnia','Kurkur'),
-> ('005','Prabandari','Dari123');
Query OK, 5 rows affected, 5 warnings (0.004 sec)
Records: 5 Duplicates: 0 Warnings: 5

MariaDB [indoalfa]> INSERT INTO supplier VALUES


-> ('Indofood','123456'),
-> ('kurniafood','123457'),
-> (''abayagiri','1234568'),
'> ;
'>

You might also like