How to create databases and tables in MySQL?

To create databases and tables in MySQL, you can follow these steps:

Create database.

CREATE DATABASE database_name;

Choose the database you want to use.

USE database_name;

3. Create a table:

CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,
    ...
);

In this case, table_name refers to the name of the table to be created, while column1, column2, column3, etc. are the column names within the table. Datatype specifies the data type of each column, such as INT, VARCHAR, DATE, etc.

If you need to add a primary key or other constraints to a table, you can use the ALTER TABLE statement.

ALTER TABLE table_name
ADD CONSTRAINT constraint_name PRIMARY KEY (column_name);

Finally, you can use the DESCRIBE statement to view the structure of the table.

DESCRIBE table_name;

By following the steps above, you can create databases and tables in MySQL.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds