SQL 增删改查

create table tb_user(
 --列名 类型 约束
 uid int primary key identity,
 uname varchar(20) not null,
 upwd varchar(16) not null default '888888',
 usex varchar(2) not null check(usex='男' or usex='女'),
 uage int not null default 18 check(uage>0 and uage<150),
 usf varchar(20) not null
);
-- 增删改查
-- 任何程序的本质都是增删改查
-- 查询 
-- select 选择,from 来自
select * from tb_user;
-- 增加
-- insert 增加,into 到,values 值
insert into tb_user
values('小百','root123','男',100,'dasfafgfsad');
-- 修改
-- update 修改,set 设置
update tb_user set usex='女',uage=139;
-- 删除 delete
delete tb_user;
delete from tb_user;
-- 新建表
create table tb_stu(
 id int primary key identity,
 name varchar(50) not null,
 pwd varchar(20)
);
-- 增加
-- 表名后面带列名,意思就是这些对应的列
-- 表名后面不带列名,意思就是全部插入
-- 自增主键不需要填
insert into tb_stu values('小黑','123');
insert into tb_stu(name,pwd) values('小黑','123');
insert into tb_stu(name) values('大黑');
-- 查询
-- * 所有
-- 一些列
select * from tb_stu;
-- 只查询学生的名字
select name from tb_stu;
-- 只查询学生的密码
select pwd from tb_stu;
-- 只查询学生的名字,密码
select name,pwd from tb_stu;
-- 中文列名
select name as '名字',pwd as '密码' from tb_stu;
-- 全部修改
update tb_stu set pwd=456;
-- 条件修改  where
-- 所有的修改和删除因该都是根据主键来
update tb_stu set pwd=789 where id=1;
update tb_stu set pwd='000' where name='大黑';
-- 删除数据
delete tb_stu; --删除表中的所有的内容
-- 条件删除 where
delete tb_stu where id=1;
delete tb_stu where name='大黑';
-- create 新建表
-- drop 删除表
drop table tb_stu;
-- 增insert 删delete 改update 查select
posted @ 2022-05-25 20:35  百变小新  阅读(56)  评论(0)    收藏  举报