How to create a table in MySQL?

To create a table in MySQL, you can use the CREATE TABLE statement. Here is a simple example:

CREATE TABLE users (
    id INT NOT NULL AUTO_INCREMENT,
    username VARCHAR(50) NOT NULL,
    email VARCHAR(100) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id)
);

In this example, we have created a table called users, which includes four fields: id, username, email, and created_at. The id field is an auto-incremented integer and also serves as the primary key. The other fields are for username, email address, and creation time.

Leave a Reply 0

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


广告
Closing in 10 seconds
bannerAds