2 運算元據庫

2022-09-10 06:09:08 字數 2172 閱讀 5668

運算元據庫 > 運算元據庫中的表 >運算元據庫中表的資料

mysql關鍵字不區分大小寫

下面做的筆記中,代表可選

create database [if not exists] school
drop database [if exists] school
use `school` -- 如果你的表名或者欄位名是乙個特殊字元,就要帶``
show databases -- 檢視所有的資料庫
多記關鍵字

字串時間和日期

通常用來設定唯一的主鍵-index,必須是整數型別(一般主鍵才設定自增)

4.not null:

5.default:

乙個建立例子

create table if not exists `student`( 

`id` int(4) not null auto_increment comment '學號',

`name` varchar(30) not null default '匿名' comment '姓名',

`pwd` varchar(20) not null default '123456' comment '密碼',

`gender` varchar(2) not null default '女' comment '性別',

`birthday` datetime default null comment '出生日期',

`address` varchar(100) default null comment '家庭住址',

`email` varchar(50) default null comment '郵箱',

primary key(`id`)

)engine=innodb default charset=utf8mb4;

總結:default的兩種搭配

這兩種方法設定好之後不賦值也不會報錯

格式:

create table [if not exists] `表名`( 

`欄位名` 列型別 [屬性] [索引] [注釋],

`欄位名` 列型別 [屬性] [索引] [注釋],

`欄位名` 列型別 [屬性] [索引] [注釋],

···`欄位名` 列型別 [屬性] [索引] [注釋] -- 最後一行不用加逗號

)[表引擎][字符集][注釋]

一些常用命令

show create database school -- 檢視建立資料庫的語句

show create table student -- 檢視資料表的定義語句

desc student -- 顯示表的結構

資料庫引擎

資料庫表的字符集編碼

charset=utf8mb4

mysql的預設編碼是latin1,不支援中文

-- 修改表名

alter table teacher rename as teacher1

-- 增加表的字段

alter table teacher add age int(11)

-- 修改表的字段

alter table teacher modify age varchar(11) -- 修改約束

alter table teacher change age age1 int(1) -- 字段重新命名

/*change可以修改約束和重新命名

modify只能修改約束

*/

-- 刪除表的字段

alter table teacher drop age

-- 刪除表

drop table if exists teacher

VBA運算元據庫2

excel的vba連線資料庫方法 public sub getdata dim strconn as string,strsql as string dim conn as adodb.connection dim ds as adodb.recordset dim col as integer 清...

運算元據庫

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 方法獲取一條資料 ...