Mysql基本語句的總結

2022-08-01 23:48:15 字數 1801 閱讀 8211

1---------------建立乙個表------------------------------------

drop table if exists 表名

create   table 表名(

id int(11) primary key auto_increment,

name varchar(20) not null

);2---------------修改乙個表的表名------------------------------------

alter table 表名1 rename to 表名2

解釋:將表名1改為表名2

demo:

alter table ta1 rename to ta0;

3---------------新增乙個欄位------------------------------------

alter table 表名 add column 欄位的名稱 varchar(20) not null default 1 comment '對該字段的解釋' after 其他字段

解釋:after,新增的字段在after欄位名字段後面,有排序的作用。

4---------------刪除乙個欄位------------------------------------

alter table 表名 drop 欄位名

5---------------刪除資料/庫(只刪除資料結構不刪除-----drop是整個表會刪除,包括表的資料和表的結構。truncate是先刪除整個表,在建立起錶的結構,資料會丟失)------------------------------------

drop database 【資料庫的名字】;

truncate 表名  //刪除表中資料。【釋放空間,id會重置】

delete from 表名 【一行一行的刪除資料,不釋放空間,可以發現再次新增資料資料的id是不斷的疊加的】

6---------------修改欄位名稱------------------------------------

alter table 表名 change 舊欄位 新字段 varchar(20)

demo:

alter table ta0 change names name varchar(20);

7---------------修改字段型別------------------------------------

alter table 表名 modify 字段 欄位的新型別

demo:

alter table ta0 modify uname int;

8----------------查詢語句-----------------------------------

select * from 表名 where +條件

9----------------插入語句-----------------------------------

(1)    insert into 表名 values (字段);

demo:

insert into ta1 values(1,'2');

(2)  insert into  表名(欄位名) values (對應的值);

demo:

insert into ta1 (id,username) values (2,'散');

10----------------更新語句-----------------------------------

update 表名 set 欄位名 = 值

demo:update ta1 set username='4';

mysql 基本語句總結

1.開啟 關閉資料庫服務 dos下輸入 net start mysql net stop mysql 開啟 關閉服務 2.建立 使用資料庫 create database 資料庫名稱 use 資料庫名稱 3.建立資料庫表 create table 表名 列名 屬性 屬性 列名 屬性 屬性 4.插入i...

mysql基本語句 mysql基本語句

mysql關係型資料庫rds中的老大哥,增刪改查是mysql入門的基礎 增刪改查語句 增刪改查的語句命令為 增 insert 刪 delete 改 update 查 select或者show 庫操作建立資料庫 create database shujukuba 建立帶字符集的資料庫 create d...

MySQL基本語句總結之約束

not null 限制列取值非空。default 給定列的預設值。unique 限制列取值不重。check 限制列的取值範圍。primary key 指定本列為主碼。foreign key 定義本列為引用其他表的外碼。使用形式為 foreign key 外碼列名 references 外表名 外表列...