use xuexiao;
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 , address ) values ("張三" ,'男',19,'河南省許昌市');
insert into studentInfo(sex , address , age , name ) values ("女" ,'河南省鄭州市',29,'小紅');
insert into studentInfo values ("小黑" ,'男',39,'河南省滄州市');
select * from studentInfo;
-- 修改已創(chuàng)建的表字段默認(rèn)值
alter table studentInfo change sex sex char default '男';
insert into studentInfo(`name` , sex , age , address ) values ("翠花" ,'女',18,'河南省許昌市');
insert into studentInfo(sex , address , age , name ) values ("女" ,'河南省鄭州市',49,'秀蓮');
insert into studentInfo values ( "黑斯", '男',29,'河北省邯鄲市'); -- 有默認(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,'河南省許昌市');
insert into studentInfo2(id , `name` , sex , age , address ) values (2 ,"翠花2" ,'女',18,'河南省許昌市');
insert into studentInfo2(`name` , sex , age , address ) values ( "黑斯", '男',29,'河北省邯鄲市'),
( "李逵", '男',29,'河北省邯鄲市'),
( "宋江", '男',29,'河北省邯鄲市'),
( "吳用", '男',29,'河北省邯鄲市'),
( "公孫勝", '男',29,'河北省邯鄲市');
desc studentInfo2;
select * from studentInfo2;
select * from studentInfo;
insert into studentInfo values ( "黑斯", '男',29,'河北省邯鄲市'),
( "李逵", '男',29,'河北省邯鄲市'),
( "宋江", '男',29,'河北省邯鄲市'),
( "吳用", '男',29,'河北省邯鄲市'),
( "公孫勝", '男',29,'河北省邯鄲市');
insert into studentInfo2 values ( 11,"黑斯", '男',29,'河北省邯鄲市'),
( 12,"李逵", '男',29,'河北省邯鄲市'),
( 13,"宋江", '男',29,'河北省邯鄲市'),
( 14,"吳用", '男',29,'河北省邯鄲市'),
( 15,"公孫勝", '男',29,'河北省邯鄲市');
select * from studentInfo2;
-- 修改 update ... set ... where 條件
-- 修改指定的數(shù)據(jù)
update studentInfo set name="潘金蓮" where name ="秀蓮";
-- 沒有寫條件,則修改全部的數(shù)據(jù)
update studentInfo 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 studentInfo2;
本章總結(jié)
SQL中的運算符
- 算術(shù)運算符帕棉、關(guān)系運算符针肥、邏輯運算符、賦值運算符
使用SQL語句增香伴、刪慰枕、改數(shù)據(jù)
- Insert插入數(shù)據(jù)
- Update修改數(shù)據(jù)
- Delete刪除數(shù)據(jù)
- TRUNCATE刪除數(shù)據(jù)