Create Simple Tables : Create Table « Table Index « SQL / MySQL






Create Simple Tables

   
/*
mysql> DROP TABLE Employee;

mysql> CREATE TABLE Employee (
    ->     Name VARCHAR(50),
    ->     Phone VARCHAR(15)
    -> );
Query OK, 0 rows affected (0.21 sec)

mysql> Show tables;
+-------------+
| Tables_in_t |
+-------------+
| employee    |
| enrollment  |
| student     |
| studentexam |
+-------------+
4 rows in set (0.07 sec)

mysql> Describe Employee;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| Name  | varchar(50) | YES  |     | NULL    |       |
| Phone | varchar(15) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.03 sec)

mysql> INSERT INTO Employee (Name, Phone) VALUES ('Joe Wang', '666 2323');
Query OK, 1 row affected (0.04 sec)

mysql> INSERT INTO Employee (Name) VALUES ('John Doe');
Query OK, 1 row affected (0.02 sec)

mysql> INSERT INTO Employee (Name, Phone) VALUES ('John Doe', NULL);
Query OK, 1 row affected (0.01 sec)

mysql> Select * from Employee;
+----------+----------+
| Name     | Phone    |
+----------+----------+
| Joe Wang  | 666 2323 |
| John Doe | NULL     |
| John Doe | NULL     |
+----------+----------+
3 rows in set (0.08 sec)


*/

DROP TABLE Employee;

CREATE TABLE Employee (
    Name VARCHAR(50), 
    Phone VARCHAR(15)
);

Show tables;
Describe Employee;

INSERT INTO Employee (Name, Phone) VALUES ('Joe Wang', '666 2323');
INSERT INTO Employee (Name) VALUES ('John Doe');
INSERT INTO Employee (Name, Phone) VALUES ('John Doe', NULL);

Select * from Employee;

           
         
    
    
  








Related examples in the same category

1.Create table: default value for column
2.Create table: small int and unsigned int
3.Create table: smallint, decimal and float
4.Create table: char, varchar
5.Create table: BLOB
6.Create table: char set and language
7.Create table: ENUM and set
8.Create table: YEAR and TIMESTAMP
9.Create table: null and not null
10.Create table: not null and default value
11.Create table: default int value
12.Create table: primary key
13.Create table: primary key 2
14.Create table: two columns for primary key
15.Create table: auto increment primary key
16.Create table: REFERENCES
17.Create table: foreign key
18.Create table: engine type INNODB
19.Set average row length and max, min rows
20.Syntax for Creating Tables (CREATE TABLE)
21.Create an empty table, use a WHERE clause that is always false
22.To produce a summary that includes all hours of the day, create a reference table that lists each hour
23.Creates table-level privileges.
24.Create a copy of the product table:
25.Create a table called cust_names using the table definitions and data from the product table.
26.CREATE TABLE IF NOT EXISTS
27.CREATE TABLE TEAMS_COPY1 LIKE TEAMS
28.Creating Copies of a Table
29.Creating a New Table by Copying
30.Creating a Table
31.Add an IF NOT EXISTS clause to the statement: