操作表中數(shù)據(jù)

use xuexaio;

create table studentInfo (
    `name` varchar (10),
    sex char,
    age int,
    address varchar(20)

);

show tables;
-- 插入操作
-- 值需要按照字母的順序一一對應(yīng),如果插入的值順序和創(chuàng)建表順序相同,則字母可以省略
insert into studentInfo(name ,sex,age,sddress ) VALUES("張三",'男',19,'許昌市');
insert into stidentInfo(sex,address,age,name) VALUES("女",'河南省鄭州市',29,'小紅');
insert into stidentInfo VALUES("小黑",'男',30,'河南省參州市');
SELECT * from studentInfo;
use xuexaio;

create table studentInfo (
    `name` varchar (10),
    sex char,
    age int,
    address varchar(20)

);

show tables;
-- 插入操作
-- 值需要按照字母的順序一一對應(yīng),如果插入的值順序和創(chuàng)建表順序相同,則字母可以省略
insert into studentInfo(name ,sex,age,sddress ) VALUES("張三",'男',19,'許昌市');
insert into stidentInfo(sex,address,age,name) VALUES("女",'河南省鄭州市',29,'小紅');
insert into stidentInfo VALUES("小黑",'男',30,'河南省參州市');
SELECT * from studentInfo;

-- 修改已創(chuàng)建的表字段默認(rèn)值
alter table studenInfo change sex sex char default '男';

insert into studentInfo(`name` ,sex,age,sddress ) VALUES("翠花",'男',19,'許昌市');
insert into stidentInfo(sex,address,age,name) VALUES("女",'河南省鄭州市',49,'秀蓮');
insert into stidentInfo VALUES("大黑",'男',30,'河南省參州市'); -- 有默認(rèn)值 如果省略字段 ,則值需要寫全
SELECT * from studentInfo;

create table studentInfo2 (
    id int auto_increment primary key,
    `name` varchar (10),
    sex char,
    age int,
    address varchar(20)

);

show tables;

insert into studentInfo2(id , `name`,sex,age,address,) values (1,"翠花" ,'女',18,'河南省許昌市');
insert into studentInfo2(`name`,sex,age,address,) VALUES ("翠花" ,'女',18,'河南省許昌市'
insert into studentInfo2(id , `name`,sex,age,address,) VALUES (3,"翠花2" ,'女',18,'河南省許昌市');

SELECT * from studentInfo2;
-- 修改已創(chuàng)建的表字段默認(rèn)值
alter table studenInfo change sex sex char default '男';

insert into studentInfo(`name` ,sex,age,sddress ) VALUES("翠花",'男',19,'許昌市');
insert into stidentInfo(sex,address,age,name) VALUES("女",'河南省鄭州市',49,'秀蓮');
insert into stidentInfo VALUES("大黑",'男',30,'河南省參州市'); -- 有默認(rèn)值 如果省略字段 ,則值需要寫全
SELECT * from studentInfo;

create table studentInfo2 (
    id int auto_increment primary key,
    `name` varchar (10),
    sex char,
    age int,
    address varchar(20)

);

show tables;

insert into studentInfo2(id , `name`,sex,age,address,) values (1,"翠花" ,'女',18,'河南省許昌市');
insert into studentInfo2(`name`,sex,age,address,) VALUES ("翠花" ,'女',18,'河南省許昌市'
insert into studentInfo2(id , `name`,sex,age,address,) VALUES (3,"翠花2" ,'女',18,'河南省許昌市');

SELECT * from studentInfo2;

-- 修改 UPDATE...set...where條件
-- 修改指定的數(shù)據(jù)
update studentInfo set name = "金蓮潘" where name="秀蓮";
-- 沒有寫條件,則修改全部的數(shù)據(jù)
update studentiIfo set name = "金蓮潘";


-- 刪除 delete from table where  ... 有日志留下可以恢復(fù)
delete from studentInfo2 where name="翠花2"; -- 刪除符合條件的數(shù)據(jù)

delete from studentInfo; -- 刪除所有數(shù)據(jù)


-- 摧毀數(shù)據(jù) 不留下日志,速度快,無法恢復(fù)
truncate table studenInfo2;













?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容