mysql 學習 資料庫操作 增刪改整理

2021-07-16 05:45:46 字數 1170 閱讀 3344

資料庫命令;

顯示資料庫:show databases ;

使用資料庫:use mysql-01;

建立資料庫:create database mysql-01;

刪除資料庫:drop database mysql_01;

對錶的操作

顯示資料庫裡的所有表:show tables;

檢視某個表裡面的所有內容: select * from table_01;

建立表:

create table  table_01(

id int not null auto_increment comment'id非空自增',

sname char comment '使用者名稱',

psw  char comment'使用者密碼',

primary key(id) comment'主鍵id'

刪除表:drop table table_01;

修改表結構:

1.給表新增字段:

alter table  table_01 add kf_id varchar(20);

2修改字段:

2.1修改欄位的型別:

alter table  table_01 modify kf_id char(10);

2.2修改欄位名及型別:

alter table  table_01 change kf_id kf_name varchar(20);

3 刪除字段:

alter table table_01 drop column kf_name;

修改表的資料內容:

1 插入資料

insert into table_01(id,sname,psw) values(1,'小明','0123456');

2,刪除某個表所有資料:

2.1刪除資料內容

delete from table_01;

2.2刪除資料同時把主鍵值歸1

truncate table table_01;

3 刪除單個資料:

delect from table_01 where id=10;

4 修改資料

update table_01 set sname='小明' where id=10;



mysql資料庫增刪改操作

insert into 表名 列名1,列名2,列名3 values 值1,值2,值3 insert into user user id,name,age values 1,nice 24 delete from 表名 where 條件 update 表名 set 列名 列的值,列名2 列2的值 wh...

Python 資料庫,操作mysql,增刪改

demo.py 增 刪 改 匯入pymysql模組 from pymysql import 需要pip3 install pymysql 安裝模組。python2.x中用的是mysqldb模組 def main 建立connection連線 conn connect host localhost p...

詳解mysql資料庫增刪改操作

插入資料 insert into 表名 列名1程式設計客棧,列名2,列名3 values 值1,值2,值3 insert into user user id,name,age values 1,nice 24 簡單寫法可以省去欄位名,但是要插入全部字段。批量插入 單條插入和程式設計客棧批量插入的效率...