数据库笔试题

上一篇 / 下一篇  2015-03-30 16:46:37 / 个人分类:数据库

---1) 创建一张学生表,包含以下信息,学号,姓名,年龄,性别,家庭住址,联系电话
CREATE TABLE student
(
    [id] [int] IDENTITY(1,1) NOT NULL,
    [student_id] [nvarchar](50)  NULL,
    [studen_name] [nvarchar](50) NULL,
    [age] [int] NULL ,
    [sex] [nvarchar](5) NULL,
    [address] [nvarchar](200) NULL,
    [tel] [nvarchar](20) NULL
)

--2) 修改学生表的结构,添加一列信息,学历 education
alter table student add education nvarchar(10) NULL

--3) 修改学生表的结构,删除一列信息,家庭住址
alter table student drop column address

--5) 修改学生表的数据,将电话号码以11开头的学员的学历改为“大专”

update student set education='大专' where tel like '11%'

--6) 删除学生表的数据,姓名以C开头,性别为‘男’的记录删除

delete student where studen_name like 'C%' and sex='男' 

--7) 查询学生表的数据,将所有年龄小于22岁的,学历为“大专”的,学生的姓名和学号示出来
select studen_name,student_id from student
where age<12 and education='大专'

--8) 查询学生表的数据,查询所有信息,列出前25%的记录
select TOP 25 PERCENT * from student

--9) 查询出所有学生的姓名,性别,年龄降序排列
select studen_name,sex,age from studen order by age desc

--10) 按照性别分组查询所有的平均年龄

select avg(age) as age from studen group by sex

TAG: 数据库

 

评分:0

我来说两句

Open Toolbar