MySQL 數據庫常用基礎命令有哪些?

MySQL 數據庫常用基礎命令有哪些?

mysql 常用基礎命令

mysql 數據庫中,基礎命令是數據庫操作的基石。通過使用這些命令,你可以創建、修改和管理數據庫及表。

建表語句

  • create table:創建一個新表。
  • alter table:修改現有表的結構。
  • drop table:刪除一個表。

功能型語句

  • select:從表中檢索數據。
  • insert:向表中插入新數據。
  • update:更新表中的現有數據。
  • delete:從表中刪除數據。

示例

創建一個名為 users 的表:

create table users (   id int not null auto_increment,   name varchar(255) not null,   email varchar(255) unique not null,   primary key (id) );

在 users 表中插入一條記錄:

insert into users (name, email) values ('john doe', 'john.doe@example.com');

從 users 表中檢索所有記錄:

select * from users;

更新 users 表中的記錄,將 email 修改為 jane.doe@example.com:

update users set email = 'jane.doe@example.com' where id = 1;

刪除 users 表中 id 為 1 的記錄:

DELETE FROM users WHERE id = 1;

通過了解這些基礎命令,你可以開始探索 mysql 數據庫的強大功能。

? 版權聲明
THE END
喜歡就支持一下吧
點贊8 分享