1. Create a table
CREATE TABLE [notnull][notnull],);
Example:
CREATE TABLE Student (
Sno Char (7) NOT null primary key,
Sname varchar (TEN) is not NULL,
Ssex char (2),
Sage integer
)
Data type char (fixed-length character): a space is usually used to populate an insufficient number of characters. Do not use fixed-length characters to hold variable lengths of data, such as names, which could result in wasted space and an accurate comparison of different data.
VARCHAR (variable length character)
2. Modify the table
You can add columns, delete columns, modify column definitions, add and remove constraints.
Alter Tabletable_name[Modify] [Column column_name] [datatype|null NOT NULL] [Restrict|cascade] [Drop] [constraint constraint_name] [Add] [column] columnDefinition
3. Create another table from an existing table
Use the combination of the CREATE TABLE and SELECT statements to copy an existing table.
Create Table as Select [*|column1, Column2] from [where]
4. Delete a table
Drop Table [restrict|cascade]
If the Restrict option is used and the table is referenced by the view or constraint, the DROP statement returns an error. When the Cascade option is used, the delete operation executes successfully and all referenced views and constraints are deleted.
===================================================================================================
1. Command line login local MySQL
Mysql-h localhost-u username-p Password
2. Tell MySQL which database we want to use:
Use MyDB;
3. List all tables for this DB:
Show tables;
4. List all fields and properties of the table (describe):
DESC table_name;
MySQL-operation table