MySql基礎 建立表 新增資料

2021-10-09 01:40:58 字數 768 閱讀 2145

# 如果yonghu表已經存在 則刪除此表

drop

table

ifexists

`yonghu`

;# 建立使用者表

create

table yonghu (

# 列名稱為id 'primary key'代表為主鍵 'auto_increment'代表自增

id int(11

)primary

keyauto_increment

,# 列名稱為ming_cheng varchar(20)表示為字串 20表示最多可以存20個字元

ming_cheng varchar(20

));# 顯示當前資料庫所有的表

show

tables

;# 新增三條資料

insert

into yonghu(ming_cheng)

values

('使用者1'),

('使用者2'),

('使用者3');

# 查詢yonghu表的所有資料

select

*from yonghu;

# 查詢yonghu表 id大於2的資料

select

*from yonghu where id >2;

# 查詢yonghu表 id大於2的 ming_cheng列資料

select ming_cheng from yonghu where id >

2;

mysql操作(建立表,向表中新增資料)

建立表 使用者表 create table tbl user id是沒有業務含義的邏輯主鍵,不允許為空,無符號的,自增長的整數型別 id int 11 unsigned not null auto increment,name是使用者名字,字串型別,不允許為空,預設值為空 name varchar ...

向表中新增資料

新增資料 1.所有欄位都插入 insert into student values a001 張三 男 01 5月 05 10 oracle中預設的日期格式 dd mon yy dd 日子 天 mon 月份 要加上漢字 月 不然報錯 yy 2位的年 如 09 6月 99 代表1999年6月9號 2....

MySQL為表的指定字段新增資料

只向表的部分字段新增資料,而其他欄位的值為表定義時的預設值 insert into 表名 欄位1,欄位2,values 值1,值2,欄位1,欄位2,表示資料表中的欄位名稱,此次,只指定表中部分欄位的名稱。值1,值2,表示指定欄位的值,每個值的順序 型別必須與對應的字段相匹配。向student表中新增...