sql语句基本操作
2009-09-25 20:07
218 查看
1.建表语句:create table
用法: create table 表的名字 (字段1, 字段2,。。。。)
举例:例如创建一个学生成绩表,包含的字段有,学生id,姓名,性别,班级,成绩create table score(
create table score(
sid nvarchar(10) primary key,
sname nvarchar(10) not null,
sex nvarchar(2),
sclass nvarchar(5),
score int,
check(sex in('男','女'))
);
2.插入语句:insert into
用法:insert into 表的名字 (字段1, 字段2,。。。。) values (值1,值2,。。。。)
如果字段是表中所有字段字段列表可省去,直接写表名就行了
举例:往表score中插入7条数据
insert into score values('95002','小李','男','01',82)
insert into score values('95003','小丽','女','01',83)
insert into score values('95004','小赵','男','01',67)
insert into score values('95005','小美','女','01',78)
insert into score values('95006','小田','男','01',88)
insert into score values('95007','小徐','女','01',85)
insert into score values('95008','小王','男','01',86)
3.查询语句:select
用法:select 字段 from 表名 where 条件
字段间用','分开,同样如果选择表的所有字段,可用通配符*
举例:输出score表中成绩在60到80的同学的所有信息
select * from score where score>=60 and score<=80
输出score 表中成绩为85或86或87的学生信息
select * from score where score=85 or score=86 or score=87
输出score 表中班级为95001或者性别为女性的学生的名字
select sname from score where sclass='95001' or sec='女'
4.删除语句:delete
用法:delete from 表的名字 where 条件
举例:删除score表中分数低于70分的记录
delete from score where score<70
用法: create table 表的名字 (字段1, 字段2,。。。。)
举例:例如创建一个学生成绩表,包含的字段有,学生id,姓名,性别,班级,成绩create table score(
create table score(
sid nvarchar(10) primary key,
sname nvarchar(10) not null,
sex nvarchar(2),
sclass nvarchar(5),
score int,
check(sex in('男','女'))
);
2.插入语句:insert into
用法:insert into 表的名字 (字段1, 字段2,。。。。) values (值1,值2,。。。。)
如果字段是表中所有字段字段列表可省去,直接写表名就行了
举例:往表score中插入7条数据
insert into score values('95002','小李','男','01',82)
insert into score values('95003','小丽','女','01',83)
insert into score values('95004','小赵','男','01',67)
insert into score values('95005','小美','女','01',78)
insert into score values('95006','小田','男','01',88)
insert into score values('95007','小徐','女','01',85)
insert into score values('95008','小王','男','01',86)
3.查询语句:select
用法:select 字段 from 表名 where 条件
字段间用','分开,同样如果选择表的所有字段,可用通配符*
举例:输出score表中成绩在60到80的同学的所有信息
select * from score where score>=60 and score<=80
输出score 表中成绩为85或86或87的学生信息
select * from score where score=85 or score=86 or score=87
输出score 表中班级为95001或者性别为女性的学生的名字
select sname from score where sclass='95001' or sec='女'
4.删除语句:delete
用法:delete from 表的名字 where 条件
举例:删除score表中分数低于70分的记录
delete from score where score<70
相关文章推荐
- SQL语句CRUD基本操作----必须掌握!
- 基本SQL 语句操作数据增删查改
- SQL基本操作语句
- SQL语句基本操作
- MySQL(三)之SQL语句分类、基本操作、三大范式
- SQL基本操作语句全集
- 掌握SQL四条最基本的数据操作语句:Insert,Select,Update和Delete
- SQL语句中表的基本操作
- SQL语句中对基本表的操作(DDL)
- SQL基本操作语句
- MySQL的基本操作及SQL语句的基本命令
- SQL语句添加删除修改字段及其他基本操作(33条)转
- sql语句的基本操作
- 数据库操作基本SQL语句
- sql 基本操作语句
- 用SQL语句添加删除修改字段、一些表与字段的基本操作、数据库备份等
- mysql数据库常用的基本SQL语句--数据库表操作
- SQL基本操作语句及经典语句全集
- sql基本操作语句
- MYSQL大全(sql语句,基本命令操作)