Вы находитесь на странице: 1из 3

Microsoft Windows [Version 10.0.

15063]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\user>cd c:\

c:\>"xampp/mysql/bin/mysql.exe" -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 62
Server version: 5.6.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

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

mysql> create database penjualan1;


Query OK, 1 row affected (0.00 sec)

mysql> show databases;


+--------------------+
| Database |
+--------------------+
| information_schema |
| cdcol |
| mysql |
| penjualan1 |
| performance_schema |
| phpmyadmin |
| test |
| webauth |
+--------------------+
8 rows in set (0.00 sec)

mysql> use penjualan1;


Database changed
mysql> create table barang (
-> kode varchar (5) not null,
-> nama varchar (20) not null,
-> harga integer not null,
-> primary key (kode)
-> );
Query OK, 0 rows affected (0.41 sec)

mysql> show tables;


+----------------------+
| Tables_in_penjualan1 |
+----------------------+
| barang |
+----------------------+
1 row in set (0.00 sec)

mysql> select * from barang;


Empty set (0.00 sec)

mysql> desc barang;


+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| kode | varchar(5) | NO | PRI | NULL | |
| nama | varchar(20) | NO | | NULL | |
| harga | int(11) | NO | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.08 sec)

mysql> alter table barang drop primary key;


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

mysql> desc barang;


+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| kode | varchar(5) | NO | | NULL | |
| nama | varchar(20) | NO | | NULL | |
| harga | int(11) | NO | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.06 sec)

mysql> alter table barang add primary key (kode);


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

mysql> desc barang;


+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| kode | varchar(5) | NO | PRI | NULL | |
| nama | varchar(20) | NO | | NULL | |
| harga | int(11) | NO | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.05 sec)

mysql> alter table barang add keterangan varchar (30) after harga;
Query OK, 0 rows affected (0.60 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc barang


-> desc barang;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'desc
barang' at line 2
mysql> desc barang;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| kode | varchar(5) | NO | PRI | NULL | |
| nama | varchar(20) | NO | | NULL | |
| harga | int(11) | NO | | NULL | |
| keterangan | varchar(30) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
4 rows in set (0.06 sec)

mysql>
mysql> alter table barang drop keterangan;
Query OK, 0 rows affected (0.50 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc barang;


+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| kode | varchar(5) | NO | PRI | NULL | |
| nama | varchar(20) | NO | | NULL | |
| harga | int(11) | NO | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.05 sec)

mysql> alter table barang add keterangan varchar (30) not null;
Query OK, 0 rows affected (0.63 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc barang;


+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| kode | varchar(5) | NO | PRI | NULL | |
| nama | varchar(20) | NO | | NULL | |
| harga | int(11) | NO | | NULL | |
| keterangan | varchar(30) | NO | | NULL | |
+------------+-------------+------+-----+---------+-------+
4 rows in set (0.06 sec)

mysql> alter table barang change keterangan ket varchar (50) not null;
Query OK, 0 rows affected (0.65 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc barang;


+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| kode | varchar(5) | NO | PRI | NULL | |
| nama | varchar(20) | NO | | NULL | |
| harga | int(11) | NO | | NULL | |
| ket | varchar(50) | NO | | NULL | |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.07 sec)

mysql>

Вам также может понравиться