MySQL:数据库表格内容

时间:2021-6-12 作者:qvyue
use xuexiao;

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

show tables;
-- 插入操作
-- 值需要按照字端的顺序一一对应,如果插入的值顺序和创建表顺序相同,则字段可以省略
insert into studentInfo(`name` , sex , age ,address) values ("里斯",'男',19,'河南许昌');
insert into studentInfo(sex,address,age,name) values("女",'山东菏泽曹县',28,"笨比");
insert into studentInfo values ("宋江",'男',50,'菏泽曹县');
select * from studentInfo;

-- 修改已创建的表字段默认值
alter table studentInfo change sex sex char default'男';

insert into studentInfo(`name` , sex , age ,address) values ("潘金莲",'女',19,'山东菏泽');
insert into studentInfo(sex,address,age,name) values("女",'山东菏泽曹县',28,"王婆");
insert into studentInfo values ("西门庆",'男',50,'菏泽曹县');  -- 有默认值 如果省略字段,则值需要全写
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,"牛逼",'男',666,'山东菏泽曹县');
insert into studentInfo2(`name` , sex , age ,address) values ("牛逼",'男',666,'山东菏泽曹县');
insert into studentInfo2(id,`name` , sex , age ,address) values (3,"牛逼2",'男',666,'山东菏泽曹县');
insert into studentInfo2(id,`name` , sex , age ,address) values (2,"牛逼3",'男',666,'山东菏泽曹县');
insert into studentInfo2(`name` , sex , age ,address) values ("窝里宝贝",'男',666,'山东菏泽曹县'),
    ("李逵",'男',30,'山东'),
    ("宋江",'男',30,'山东郓城'),
    ("吴用",'男',30,'山东石碣村'),
    ("鲁智深",'男',30,'山东五台山'),
    ("公孙胜",'男',30,'山东梁山');
    desc studentInfo2;
    select * from studentInfo2;
    select * from studentInfo;
    insert into studentInfo(`name` , sex , age ,address) values ("窝里宝贝",'男',666,'山东菏泽曹县'),
    ("李逵",'男',30,'山东'),
    ("宋江",'男',30,'山东郓城'),
    ("吴用",'男',30,'山东石碣村'),
    ("鲁智深",'男',30,'山东五台山'),
    ("公孙胜",'男',30,'山东梁山');
    

```sql
insert into studentInfo2 values (10,"窝里宝贝",'牛逼',666,'山东菏泽曹县'),
(11,"李逵",'男',30,'山东'),
(12,"宋江",'男',30,'山东郓城'),
(13,"吴用",'男',30,'山东石碣村'),
(14,"鲁智深",'男',30,'山东五台山'),
(15,"公孙胜",'男',30,'山东梁山');

select * from studentInfo2;

-- 修改
-- 修改指定的数据
update studentInfo set name = "潘金莲" where name = "笨比";
-- 没有写条件,则修改全部的数据
update studentInfo set name = "潘金莲";

-- 删除 delete from table where ...
delete from studentInfo2 where name = "牛逼2"; -- 删除符合条件的数据
delete from studentInfo; -- 删除所有数据

-- 销毁数据 不留下日志 ,速度快,无法恢复
truncate table studentInfo2;
```


声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:qvyue@qq.com 进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。