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;
Mysql 學習筆記( 》插入修改資料二)
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自動修改資料的插入和修改時間
建立時指定 建立表 create table t user id int 10 unsigned not null auto increment comment 主鍵id username varchar 20 not null comment 使用者名稱 password varchar 64 n...
在PB中插入 刪除和修改資料
1 插入資料 在資料庫中插入一條資料使用insert語句,格式如下 insert into 表名 字段列表 values 值列表 不同的字段使用逗號 分隔,並且不包含blob型別的字段 值列表中不同的值之間用逗號分隔,和字段列表中字段的型別對應相容 最好型別相同 並且字元型和日期型取值用引號引起來。...