#初始化utf8
set names utf8;
#丢弃数据库如果存在的情况下
drop database if exists xuezi;
@创建新的数据库,设置UTF8编码
create database xuezi charset=utf8;
#进入数据库
use xuezi;
#创建表
create table laptop(
lid int primary key auto_increment,#自动递增
title varchar(64),
price decimal(8,2),
stock decimal(10.8),
stime timestamp,#自动获取更新时间
phone varchar(11),
isindex boolean
);
#添加数据
insert into laptop values(null,'马铃薯',5.3,5000,null,11111111111,true);
insert into laptop values(null,'番薯',6.4,5000,null,11111111111,true);
insert into laptop values(null,'白菜',3.5,5000,null,11111111111,true);
insert into laptop values(null,'ak47',300.0,5000,null,11111111111,true);
insert into laptop values(null,'子弹',6.2,5000,null,11111111111,true);
insert into laptop values(null,'笔记本',9999.8,5000,null,11111111111,true);
#基于id进行更新
update laptop set title='坦克',price=6000000.0 where lid=2;
#基于id删除 delete from laptop where lid=1;
select *from laptop;
|