create database chaxun
use chaxun

create table chaxun3
(
id int primary key identity(1,2),
name varchar(20),
sex char(2),
age char(20),
info varchar(20),
tel varchar(20)
)

insert into chaxun3 values('阳阳','男',18,'优秀学生',15210854732),('小玉','女',20,'大美女',15238485962),
('宋遥','女',21,'美女',15236485962),('周杰伦','男',22,'大明星',15236485688)

---查询全部、
select * from chaxun3

---条件查询
select * from chaxun3 where name='小玉'
select * from chaxun3 where sex='女'

---and or 查询   select * from 表名 where 条件
select * from chaxun3 where name='阳阳' or name='小玉'
select * from chaxun3 where name='宋遥' or sex='男'

select * from chaxun3 where id=3 and info='大美女'
select * from chaxun3 where name='周杰伦' and tel=15236485688

---between....and...
select * from chaxun3 where age between 20 and 22
---等价于
select * from chaxun3 where age>=20 and age<=22

---部分查询  select 字段名 from 表名 where 条件
select id,name from chaxun3 where info='大明星'

---查询前n条记录  select top n * from 表名 (也可以有where条件)
select top 3 * from chaxun3
select top 3 * from chaxun3 where id>2
select top 3 id,name,sex from chaxun3

---查询前百分比记录  格式:select top n percent * from 表名
select top 100 percent * from chaxun3
select top 30 percent * from chaxun3