Mysql 學習筆記( 》插入修改資料二)

2021-09-08 19:45:08 字數 1495 閱讀 9027

use db;

-- 建立學生資訊表

create table student

(sno int unsigned not null auto_increment,

sname varchar(20) not null,

sage tinyint unsigned not null,

sbirthday datetime,

saddress varchar(50),

sscore decimal(4,2),

primary key(sno)

)engine=myisam auto_increment=201601 default charset=utf8;

-- 刪除表

drop table student;

-- 檢視表的結構

desc student;

-- insert 操作 插入資料(into可寫可不寫 建議寫)

insert into student values(null,'李四',18,'2000-1-18','武漢',82);

insert student values(null,'張三飛',18,'2008-1-18','上海',82.5);

-- 插入兩條記錄

insert into student values(null,'老王',18,'2000-1-18','武漢',82),(null,'張飛',55,'546-1-18','鄭州',45.1);

-- 複製已有的記錄的屬性並且插入

insert into student(sname,sage,sbirthday,saddress,sscore)

select sname,sage,sbirthday,saddress,sscore from student;

insert student(sname,sage) values('rose',18),('jack',20);

-- replace 當有相同primary或unique主鍵時,替換, 沒有相同的則跟insert功能相同

replace into student(sname,sage) values('張先生',18),('關羽',20);

replace into student values(201609,'asda',18,'2000-1-18','武漢',82.6);

-- 修改資料

update student set sscore=85,saddress='上海',sbirthday='1966-2-3' where sno=201603;

-- 刪除資料

delete from student where sno=201603;

delete from student;/*無條件刪除所有記錄*/

truncate table student;/*直接清空表的全部記錄,auto_increment自動編號從1開始分配(1,2,3...)*/

-- 檢視查詢資料顯示

select * from student;

《學習 》2插入修改資料

use db 建立學生資訊表 create table student sno int unsigned not null auto increment,sname varchar 20 not null,sage tinyint unsigned not null,sbirthday dateti...

MySQL學習筆記10 修改資料

資料庫通過插入 更新和刪除等方式來該表表中的記錄,其中 insert語句實現插入資料 update語句實現更新資料 delete語句實現刪除資料 參考表 插入資料 不指定欄位名插入 mysql insert into person values 1,張三 男 1988 query ok,1 row ...

MySQL學習 修改資料表

1 取出乙個表的部分內容,形成乙個新錶 原表user 取出其中的 userid,username,userpass三項內容形成新錶user1 2 在原有表的基礎上新增新的列定義 下圖,增加新的gender列和email列演示 alter table user add gender varchar 2...