Informatics Practices · Ch 7 — Introduction to Structured Query Language (SQL)
CREATE Database
CREATE Database
A database is a named container managed by the DBMS — tables can only exist inside one. So the first step in building any MySQL project is to create that container, and only after that can relations be defined within it.
Creating the database. The statement follows a simple pattern:
CREATE DATABASE databasename;
To build the attendance-management system developed through this chapter, a database called StudentAttendance is needed. At the mysql prompt:
mysql> CREATE DATABASE StudentAttendance;
Query OK, 1 row affected (0.02 sec)
The reply beginning with "Query OK" is MySQL's confirmation that the statement executed successfully.
In a LINUX environment, names of databases and tables are case-sensitive — StudentAttendance and studentattendance would count as different names. In WINDOWS there is no such differentiation. As a good practice, always write a database or table name in exactly the same letter cases that were used at the time of its creation; the habit prevents surprises when the same SQL is run on a different operating system.
Selecting the database with USE. A DBMS can manage multiple databases on one computer, which raises an obvious question every time you start working: which database do your commands apply to? The database you want to work in must therefore be selected first. Only once a database is selected can you proceed with creating tables in it or querying its data:
mysql> USE StudentAttendance;
Database changed
The "Database changed" message confirms that every statement typed from this point on operates inside StudentAttendance. …