Drop the Table and Database
In this final step, you will learn how to drop the emp
table and the testddl
database.
- Drop the
emp
table:
DROP TABLE `emp`;
- Drop the
testddl
database:
DROP DATABASE `testddl`;
You can refer to the following output:
MariaDB [(none)]> USE `testddl`;
Database changed
MariaDB [testddl]> CREATE TABLE `emp` (
-> `eid` int(5) NOT NULL,
-> `ename` varchar(50),
-> `sal` DECIMAL,
-> `deptno` int(5),
-> PRIMARY KEY (`eid`)
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Query OK, 0 rows affected (0.005 sec)
MariaDB [testddl]> CREATE TABLE `dept` (
-> `did` int(5) NOT NULL,
-> `dname` varchar(50) DEFAULT NULL,
-> PRIMARY KEY (`did`)
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Query OK, 0 rows affected (0.004 sec)
MariaDB [testddl]> desc emp;
+--------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+---------------+------+-----+---------+-------+
| eid | int(5) | NO | PRI | NULL | |
| ename | varchar(50) | YES | | NULL | |
| sal | decimal(10,0) | YES | | NULL | |
| deptno | int(5) | YES | | NULL | |
+--------+---------------+------+-----+---------+-------+
4 rows in set (0.001 sec)
MariaDB [testddl]> ALTER TABLE `emp` AUTO_INCREMENT=10;
Query OK, 0 rows affected (0.005 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [testddl]> ALTER TABLE `dept` AUTO_INCREMENT=10;
Query OK, 0 rows affected (0.003 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [testddl]> ALTER TABLE `emp` MODIFY `sal` INT(5);
Query OK, 0 rows affected (0.006 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [testddl]> desc emp;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| eid | int(5) | NO | PRI | NULL | |
| ename | varchar(50) | YES | | NULL | |
| sal | int(5) | YES | | NULL | |
| deptno | int(5) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
4 rows in set (0.001 sec)
MariaDB [testddl]> DELETE FROM `emp`;
Query OK, 0 rows affected (0.000 sec)
MariaDB [testddl]> TRUNCATE TABLE `dept`;
Query OK, 0 rows affected (0.003 sec)
MariaDB [testddl]> show tables;
+-------------------+
| Tables_in_testddl |
+-------------------+
| dept |
| emp |
+-------------------+
2 rows in set (0.000 sec)
MariaDB [testddl]> DROP TABLE `emp`;
Query OK, 0 rows affected (0.002 sec)
MariaDB [testddl]> show tables;
+-------------------+
| Tables_in_testddl |
+-------------------+
| dept |
+-------------------+
1 row in set (0.000 sec)
MariaDB [testddl]> show schemas;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| testddl |
+--------------------+
5 rows in set (0.000 sec)
MariaDB [testddl]> DROP DATABASE `testddl`;
Query OK, 1 row affected (0.004 sec)
MariaDB [(none)]> show schemas;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.000 sec)
Congratulations! You have completed the DDL Comprehensive Challenge. You have learned how to create a database, create tables, modify table structures, delete data from tables, and drop tables and databases.********