MySQL基礎學習筆記 表結構操作的SQL語句

2021-09-26 02:23:26 字數 2142 閱讀 4269

show

tables

;

create

table 表名(

欄位名稱 資料型別 可選的約束條件,

column1 datatype contrai,..

.);# 例

create

table 表名(

id int

unsigned

primary

keynot

null

auto_increment

, name varchar(20

)not

null

, age tinyint

unsigned

default0,

height decimal(5

,2),

gender enum

('男'

,'女'

,'保密'

)unique

(name)

);

drop

table 表名;

desc 表名;

# 或describe 表名;

alter

table 表名 add 列名 型別 約束;

alter

table students add birthday datatime;

alter

table 表名 modify 列名 型別 約束;

alter

table students modify birthday date

notnull

;

alter

table 表名 change 原列名 新列名 型別 約束;

alter

table students change birthday birth datetime

notnull

;

alter

table 表名 drop 列名;

alter

table students drop birthday;

show

create

table 表名;

# 全列插入:值的順序與表結構欄位的順序完全一一對應

insert

into 表名 value

(值1, 值2,.

..);

# 部分列插入:值得順序與給出的列順序對應

insert

into 表名(列名1

, 列名3,.

..)value

(值1, 值3,.

..);

# 全列多行插入

insert

into 表名 values(.

..),

(...

)...

;# 部分列多行插入

insert

into 表名(列1,.

..)values

(值1,..

.),(值1,.

..).

..;

# 查詢所有列

select

*from 表名;

# 查詢指定列

select 列名1

, 列名2,.

..from 表名;

update 表名 set 列名1

=值1, 列名2

=值2,..

.where 條件

delete 表名 where 條件;

# 新增刪除字段,0表示未刪除 1表示刪除

alter

table 表名 add 列名-isdelete bit

default0;

# 邏輯刪除資料

update 表名 set 列名-isdelete=

1where 條件;

MySQL筆記建立表結構 MySQL表結構筆記9

本篇大綱 mysql資料表 建立表建立主鍵 auto increate 指定預設值 更新表結構 刪除表,重新命名表 01 表 mysql 資料庫的表是乙個二維表,由乙個或多個資料列構成 每個資料列都有它的特定型別,該型別決定了mysql如何看待該列資料 02 建立表 命令 格式 使用create t...

MYSQL學習筆記 關於MySQL的多表操作 2

實際開發中,乙個專案通常需要很多張表才能完成。主鍵 和 外來鍵 的概念 主鍵是能確定一條記錄的唯一標識。外來鍵用於與另一張表的關聯,都是指向另乙個表的主鍵。可伸縮性 能夠適應不斷增加的工作量而不失敗,設計良好的資料庫或應用程式稱之為可伸縮性好。普通的多表查詢 select sname,address...

mysql控制access mysql 表操作

建立表 簡單的方式 create table person number int 11 name varchar 255 birthday date 或者是create table if not exists person number int 11 name varchar 255 birthda...