Saturday, August 10, 2013

Create a Database (CMD)


Shortcut example: M+(up-arrow)to find a previously typed command like mysql -u root -p

#Comment, /*MLC*/

mysql> create database customer;
Query OK, 1 row affected (0.01 sec)

mysql>show databases;
+---------------------+
| Database            |
+---------------------+
| information_schema  |
+---------------------+
| customer            |
+---------------------+
mysql>use customer;
Database changed

mysql>select database();#show the current database
+-------------+
| database()  |
+-------------+
| customer    |
+-------------+

mysql> create table customers
    -> (
    -> first_name varchar(25) NOT NULL,
    -> last_name varchar(25) NOT NULL,
    -> state CHAR(2) NOT NULL DEFAULT "WA",
    -> birth_date DATE NOT NULL,
    -> sex ENUM('M','F') NOT NULL,
    #In this case they can only select between M/F
    -> cust_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    #Unsigned - can't be negative
    -> last_meeting TIMESTAMP,
    -> money_owed FLOAT NULL#No comma here
    -> );
Query OK, 0 rows affected (0.22 sec)
mysql> show tables;
+--------------------+
| Tables_in_customer |
+--------------------+
| customers          |
+--------------------+

mysql>drop table customers;
OK man (0.00 sec)

1 comment:

  1. Thanks a bunch for sharing this with all folks you actually know what you are talking about! Bookmarked. Please additionally seek advice from my website =). We could have a hyperlink trade arrangement among us.
    Create a MySQL database

    ReplyDelete