mysql的基礎增刪改查(一)

2022-07-22 08:24:10 字數 1129 閱讀 1061

修改,操作表:

1、建表:create table myclass(id int(4) not null primary key auto_increment,name char(20) not null);

2、獲取表結構命令: desc 表名,或者show columns from 表名

3、刪除表命令:drop table 《表名》

4、在表中增加字段:命令:alter table 表名 add欄位 型別 其他;

eg:alter table myclass add passtest int(4) default '0'

5、在表中刪除字段:命令:alter table 表名 drop欄位;

eg:alter table myclass drop passtest;

6、更改表名:命令:rename table 原表名 to 新錶名; eg:rename table myclass to youclass

7、更改欄位名:alter table myclass change column degree score double(8,2);

修改,運算元據:

1、插入資料:insert into myclass values(1,'tom'),(2,'joan');或者insert into myclass(name) values('tom'),('joan'); (因為id自增)

2、查詢所有行命令: select 《欄位1,欄位2,...> from < 表名 > where < 表示式 >

eg:select * from myclass;

3、查詢前幾行資料: select * from myclass order by id limit 0,2;或者:select * from myclass limit 0,2;

4、刪除表中資料命令:delete from 表名 where 表示式

eg:delete from myclass where id=1;

5、修改表中資料:update 表名 set 字段=新值,… where 條件

eg:update myclass set name='mary' where id=1;

eg:update myclass set name=concat('s',name);(用函式)

mysql增刪改查效果 mysql增刪改查

檢視所有資料庫 mysql show databases 建立乙個庫ghd並指定字符集為utp8 mysql create database ghd charset utf8 檢視mysql支援的字符集 mysql show char set 建立乙個表,並設定id為主鍵 create table ...

mysql增刪改查擴充套件 MySQL增刪改查

1 插入 insert 1 insert into 表名 values 值1 值2 例子 insert into t1 values zengsf 23 fengshao 22 2 insert into 表名 欄位1,values 值1 例子 insert into t1 name values ...

mysql建刪改查 mysql的基礎增刪改查(一)

修改,操作表 1 建表 create table myclass id int 4 not null primary key auto increment,name char 20 not null 2 獲取表結構命令 desc 表名,或者show columns from 表名 3 刪除表命令 d...