MYSQL資料庫基本DDL語句

2021-08-17 02:24:05 字數 1373 閱讀 8493

1、資料庫

*檢視所有的資料庫: show databases;

*切換(選擇要操作)資料庫:use 資料庫名

*建立資料庫:create database [if not exists] mydb1 [charset=utf8]

*刪除資料庫:drop database [if exists] mydb1

2、資料型別

int:整型

double:浮點型,例如duble(5,2)表示最多5位,其中必須有2位小數,即最大值為999.99;

decimal:浮點型,在表示錢方面使用該型別,因為不會出現精度缺失問題

char:固定長度字串型別,char(255),資料的長度不足指定長度時,補足到指定長度!

varchar:可變長度字串型別,varchar(65535),zhangsan

text(clob):字串型別;text是方言,標準叫clob

>很小 256b

>小 64k

>中 16m

>大 4g

blob:位元組型別:

>很小 256b

>小 64k

>中 16m

>大 4g

date:日期型別,格式為:yyyy-mm-dd;

time:時間型別,格式為:hh:mm:ss

timestamp:時間戳型別;

3、表

*建立表

create table [if not exists] 表名 (

列名 列型別,

列名 列型別,

......

列名 列型別

);*檢視當前資料庫中所有表名稱:show tables;

*檢視指定表的建立語句:show create table 表名(了解)

*檢視表結構:desc 表名;

*刪除表:drop table 表名;

*修改表: 字首; alter table 表名

>新增列:

alter table 表名 add(

列名 列型別,

列名 列型別,...

)>修改列型別:

如果被修改的列已存在資料,那麼新的型別可能會影響到已存在資料

alter table 表名 modify 列名 列型別;

>修改列名:

alter table 表名 change 原列名 新列名 列型別;

>刪除列:

alter table 表名 drop 列名;

>修改表名:

alter table 表名 rename to 新錶名;

mysql資料庫DDL語句

1.資料庫服務啟動命令 net start mysql 2.資料庫登入命令 mysql u username p password 3.資料庫基本操作指令 ddl 資料庫定義語言 1.建立資料庫 create database if not exists database name characte...

MySQL 資料庫基本操作(DDL)

ddl 資料定義語言 data define language 定義資料庫,資料庫表它們的結構 create 建立 drop 刪除 alter 修改 選中資料庫 要對哪個資料庫進行操作 use 資料庫名檢視所有已建的資料庫show databases 建立資料庫 直接建立資料庫 create dat...

MYSQL資料庫基本語句

sqlite3支援的型別 整數,文字,浮點,二進位制 sqlite3 test.sqlite test.sqlite是資料庫的名字 table 檢視資料庫中是否有表 建立表 no學號 整型 主鍵 自動增長的 不能為空 name姓名 文字 不能為空 age年齡 整型 create table stud...