使用DML運算元據庫

2021-09-24 06:16:55 字數 2023 閱讀 6573

create table student(

stuid int primary key auto_increment comment 『學生編號』,

stuname varchar(25) comment 『學生姓名』,

stupwd varchar(50) comment 『學生密碼』,

gender char(2) default 『男』 comment 『性別』,

gradeid int comment 『年級編號』,

phone varchar(11) comment 『**』,

email varchar(25) comment 『郵箱』,

address varchar(255) default 『位址不詳』 comment 『位址』,

identitycard varchar(18) unique comment 『身份證號』

) comment 『學生表』;

– 1.修改表(並不是特別常用 只需要了解記憶一些常見的即可《面試題》)

alter table student change identitycard identityid varchar(18);

alter table student add borndate datetime comment 『出生日期』;

alter table student drop borndate;

alter table student rename school_stu;

alter table school_stu

add constraint pk_stu_stuid

primary key school_stu(stuid);

alter table school_stu

add constraint fk_stu_grade

foreign key (gradeid)

references grade(gradeid);

– cud sql-

/*ddl 資料定義語言 create drop …

[dml] 資料操作語言 增刪改

dql 資料查詢語言

dcl 資料控制語言

*/insert into school_stu (stuid,stuname,stupwd) values(2,『石浩然』,『root』);

insert into school_stu values(3,『呵呵』,『hehe』,『女』,2,『12312』,『x』,『x』,『***』,『2019-05-23』);

insert into school_stu (stuid,stuname) values(null,『我是測試的』);

insert into school_stu(stuname) values(『陳旭』),(『李天一』),(『努力過』);

insert into school_stu(stuname)

select 『呵呵1』 union

select 『呵呵2』 union

select 『呵呵3』

insert into stu(stuid,stuname)

select stuid,stuname from school_stu;

create table newstu(

select stuid,stuname from school_stu

);update school_stu set stuname = 『李天二』

update school_stu set stuname = 『李易峰』 where stuid = 7;

update school_stu set stuname = 『李元霸』 where gender = 『男』

update school_stu set gradeid = gradeid + 1,phone = 『13838384383』 where stuid = 1;

delete from school_stu where stuname = 『李元霸』 and gender = 『男』;

truncate table school_stu;

使用DML運算元據

建立學生表 create table student stuid int primary keyauto increment comment 學生編號 stuname varchar 25 comment 學生姓名 stupwd varchar 50 comment 學生密碼 gender char...

DML運算元據

建立學生表create table student stuld int prmary key auto increment comment學生編號,stuname varchar 25 comment學生姓名,stupwd varchar 50 comment學生密碼,gender char 2 d...

DML運算元據 天冷加衣

二 刪除資料 三 修改資料 insert into 表名 列名1 列名2,列名n values 值1,值2,值n 簡化 insert into 表名 values 值1,值2,值n 需要寫全所有列的值 除了數字,其他型別值需要加引號 單雙都可 delete from 表名 where 條件不建議,會...