MySQL的簡單操作 增刪改查

2021-10-07 13:59:40 字數 1887 閱讀 3364

– 建立資料庫

create database 資料庫名;

– 如果 (資料庫名) 資料庫不存在就建立

create database if not exists (資料庫名);
– 嘗試刪除資料庫(如果存在就刪除)

drop database if exists (資料庫名);
– 選中資料庫

use 資料庫名;
------------ mysql 中的表操作 -------------

– 建立資料表

create table (表名)(

欄位名1 型別 [字段約束],

欄位名2 型別 [字段約束],

......

);

– 檢視資料表

show tables;
– 刪除資料表

drop table (表名);
– 檢視表結構

desc (表名);
– 檢視建表語句

show create table (表名);
------- 表中資料庫操作 -------

– 新增資料

insert into 表名[(字段列表)] value(值列表);

如: insert into tab(id,name) vlaue(1,'aa');

– 一次性新增多條資料

如: insert into tab(id,name) values(1,'aa'),(2,'bb'),(3,'cc');
– 檢視資料

select (欄位名列表) | * (代表所有字段) from (表名);
– 修改表中的資料

update (表名) set (欄位名)=修改值 where (條件 -- 哪些資料執行修改);

如: update tab set name='bb' where id=1;

– 資料刪除

delect from (表名) where (條件);

如: delect from tab where name='aa';

---- 使用表型別和約束建立表

如: create table stu(

id欄位 int型別 無符號 自增 主鍵,

name欄位 varchar(16)型別 not null unique(唯一性),

***字段 enum('w','m') not null default 'w',

age欄位 int型別 unsigned not null default 14;

classid char(6)

);

mysql 簡單操作 增刪改查(1)

資料 資料庫 資料庫管理系統 資料庫系統時與資料庫技術密切相關的的四個基本概念。資料 data 描述事物的的符號記錄稱為資料。資料庫 db 儲存資料的倉庫,它儲存了一系列有組織的資料 資料庫管理系統 dbms 資料庫是通過dbsm建立和操作的容器,資料庫管理系統是和計算機作業系統一樣的是計算機的基礎...

mysql 簡單增刪改查

增刪改查 以sql server 首先要建立乙個資料庫 建立乙個資料庫的語句 create database test建立乙個 create table testtab 建立語句 id int not null primary key,建立乙個int 型別的id 設定為非空 並且設定為主鍵約束 us...

Python簡單操作MySQL的增,刪,改,查

python操作mysql需要先安裝乙個pymysql模組。pip install pymysql 證明一下是否成功的新增環境變數,可以用cmd測試一下,win r輸入cmd開啟命令列,輸入mysql u 使用者名稱 p 密碼,這樣就可以訪問到mysql了,也就是環境變數配置好了 檢視資料庫可以輸入...