資料庫增刪改查

2021-10-08 21:51:04 字數 1287 閱讀 7810

基本語法&&操作語句

create(建立)

alter(更新)

drop(刪除)

一次性刪除乙個表中所有的資料 包括日誌

truncate table 表名;

選中或者使用該資料庫 說明接下來的操作都是針對該資料庫進行

use 資料庫名稱

建立create database 資料庫名;

create table 資料表名(

欄位名 資料型別(長度) [其他值],

欄位名 資料型別(長度) [其他值],

欄位名 資料型別(長度) [其他值],……

);/*

create table 表名(

欄位名 型別 (長度) [是否為空] [有無預設值] [是否零填充] [是否無符號][約束設定]…

);*/

更改alter table 表名 modify 欄位名 varchar(64) not null;

rename table 表名 to 新錶名;

alter table 表名 rename 新錶名;

alter table 表名 change 欄位名 新欄位名;

#更改表中資料

update 表名 set 字段=值[,欄位2=值2,……] where 條件表示式

刪除drop database 資料庫名;

drop table 資料表名

delete from 表名 [where 條件表示式];

truncate table 資料表名;

alter table 表名 drop 欄位名;

新增alter table 表名 add 欄位名 字段數值引數;

insert into 表名(字段列表) values (值列表);

############新增資料**於其他的表中############

insert into tc (select stu_name from stu_info);

insert into 表名(字段列表) select 字段列表 from 表名 [where 條件表示式];

create table 表名[(字段列表)] select 字段列表 from 表名 [where 條件表示式];

create table 表名 select 字段列表 from 表名 [where 條件表示式]

查詢select 子句:需要查詢什麼資訊

from 子句:操作的資料來源在哪兒

select [欄位名],[…] from 表名 [where 條件表示式];

select * from 表名;

資料庫增刪改查

我們知道當我們的表建立後重複執行會出錯,一般我們會這麼處理 create table if not exists stuinfo 學了新建表我們還應該知道乙個東西,如何刪除表 deop table table name 怎麼檢視別人的見表語句呢 show create table stuinfo 怎...

資料庫增刪改查

import pymysql def getmysqlconn conn pymysql.connect host 172.16.238.130 port 3306,db my mysql user root password 123456 charset utf8 return conn def ...

資料庫增刪改查

資料庫操作 show databases create database 資料庫名 use 資料庫名 select database drop database 資料庫名 資料表操作 create table 表名 欄位名 型別名 約束 show tables drop table 表名 資料表增刪...