3 運算元據庫

2022-03-20 01:29:37 字數 1510 閱讀 3467

建立資料庫:create database 資料庫名;

顯示已存在的資料庫:show databases;

刪除資料庫:drop database 資料庫名;

檢視資料庫支援的引擎:show engines;

使用資料庫:use 資料庫名;

show engines;也可以用\g或\g結束,前乙個能讓顯示更美觀,後乙個與;作用相同

create table 表名(

屬性名 資料型別[完整的約束條件],

……屬性名 資料型別[完整的約束條件],

屬性名 資料型別

);

完整的約束條件
constraint 外來鍵別名 foreign key(屬性1.1,屬性1.2,……,屬性1.n)

references 表名(屬性2.1,屬性2.2,……,屬性2.n)

檢視表:show tables;

檢視表結構:describe/desec 表名;檢視表資料所用的型別和約束條件

檢視表詳細結構:show create table 表名;把分號換成\g會讓顯示更美觀

修改表名:alter table 舊表名 rename [to] 新錶名;

修改欄位的資料型別:alter table 表名 modify 屬性名 新資料型別;

修改字段(屬性)名:alter table 表名 change 舊屬性名 新屬性名 新資料型別;

增加字段:alter table 表名 add 屬性名1 資料型別[完整的約束條件] [first | alter 屬性名2];first作用是將新增欄位設為表的第乙個字段;alter作用是將新增欄位加到屬性2之後;若無指定,新增字段預設為最後乙個字段。

刪除字段:alter table 表名 drop 屬性名;

修改欄位的排列位置:alter table 表名 modify 屬性名1 資料型別 first | alter 屬性名2;

更改表的儲存引擎:alter table 表名 engine=儲存引擎名;

刪除表的外來鍵約束:alter table 表名 drop foreign key 外來鍵別名;

刪除沒有被關聯的表:drop table 表名;

刪除其他表關聯的父表:先用alter table 表名 drop foreign key 外來鍵別名;然後就可以用drop table 表名;刪除表;

運算元據庫

python importmysqldb defmydbtest conn mysqldb.connect host localhost user root passwd sa db b4img charset utf8 cursor conn.cursor sql select from imag...

運算元據庫

2.localhost 的位址 檢視 一般位於c windows system32 driver etc下,一般在最後有這麼一行 127.0.0.1 localhost 資料庫操作方法 鏈結資料庫 建立資料庫表 資料庫插入操作 資料庫查詢操作 後記 try 使用 fetchone 方法獲取一條資料 ...

運算元據庫

是選擇乙個 是可選引數 新建資料庫 create if not exists db name default character set charset name 檢視當前伺服器下的資料庫列表 show like pattern where expr 檢視警告資訊 show warnings 修改資...