Creating data Tables
The following information is required to create a MySQL datasheet:
- Table name
- table field Name
- Define each table field
Grammar
The following is the SQL general syntax for creating a MySQL datasheet:
CREATE TABLE table_name (column_name column_type);
In the following example, we will create a datasheet in the tutorials database tutorials_tbl:
TUTORIALS_TBL (
tutorial_id INT not null auto_increment,
tutorial_title VARCHAR (MB) not NULL,
Tutorial_ Author VARCHAR () not NULL,
submission_date date,
PRIMARY KEY (tutorial_id)
);
Instance resolution:
If you don't want the field to be null, you can set the property to not NULL, and the error occurs if the data entered for the field is null when you manipulate the database.
The auto_increment definition is listed as an attribute, which is typically used for primary keys, and the value is automatically increased by 1.
The PRIMARY key keyword is used to define a column as a primary key. You can use multiple columns to define primary keys, separated by commas.
To create a table from a command prompt
The mysql> Command window makes it easy to create a MySQL datasheet. You can create a datasheet using SQL statement creation table.
Instance
The following is an instance of creating a datasheet tutorials_tbl:
root@host# Mysql-u Root-p
Mysql> CREATE TABLE tutorials_tbl (
-> tutorial_id INT not NULL auto_increment,
-> tutorial_title VARCHAR NOT NULL,
-> tutorial_author VARCHAR (=) NOT null,
-> submission_date date,->
PRIMARY KEY (tutorial_id)
->);
Query OK, 0 rows affected (0.16 sec)
Note: The MySQL command Terminator is a semicolon (;).
create a datasheet using a PHP script
You can use PHP's mysql_query () function to create a data table with existing databases.
The function has two parameters that return TRUE if the execution succeeds, or FALSE.
Grammar
BOOL mysql_query (SQL, connection);
Instance
The following example uses the PHP script to create the data table:
Delete data table
It's easy to delete data tables in MySQL, but you need to be careful when you delete a table, because all the data disappears after the delete command is executed.
Grammar
The following is a common syntax for removing MySQL data tables:
To delete a datasheet in a command prompt window
to delete a datasheet SQL statement as a drop table in the mysql> Command Prompt window:
Instance
The following instance deletes the datasheet tutorials_tbl:
root@host# mysql-u root-p
Enter password:*******
mysql> use tutorials;
Database changed
mysql> DROP TABLE tutorials_tbl
Query OK, 0 rows affected (0.8 sec)
mysql>
To delete a datasheet using a PHP script
PHP uses the mysql_query function to remove the MySQL data table.
The function has two parameters that return TRUE if the execution succeeds, or FALSE.
Grammar
BOOL mysql_query (SQL, connection);
Instance
The following example uses a PHP script to delete the datasheet tutorials_tbl: