考试报名
考试报名
考试内容
考试大纲
在线客服
返回顶部

备考刷题,请到

CDA认证小程序

(复合题)学生信息表 student 包含 id(学生编号)和 stuname(学生姓名)。 (3)以下哪个语句可以将 student 表中的 stuname 字段的位置移至 id 字段之后?
A. alter table student modify stuname after id;
B. alter table student modify stuname varchar(8) after id;
C. alter table student modify id before id;
D. alter table student modify id varchar(8) before id;
上一题
下一题
收藏
点赞
评论
题目解析
题目评论(0)

在 SQL 语言中调整字段位置时使用的关键词为 first 和 after 没有 before,所以排除了 C 和 D 选项,在使用 alter table…modify…语句更改字段属性或位置时至少需要指定字段名 + 字段的数据类型,所以排除 A 选项,所以答案为 B。

正确答案是:B: alter table student modify stuname varchar(8) after id;

专业分析:

在 MySQL 中,`ALTER TABLE` 语句可以用来修改表的结构,其中包括调整字段的位置。选项 B 中的语句 `alter table student modify stuname varchar(8) after id;` 正确地使用了 `MODIFY` 子句来调整 `stuname` 字段的位置,并且指定了字段的类型 `varchar(8)`。这样做的目的是确保在调整字段位置时,也明确了字段的数据类型。

具体分析各选项:
- A: `alter table student modify stuname after id;` 语句缺少字段的数据类型定义,因此是错误的。
- B: `alter table student modify stuname varchar(8) after id;` 语句正确地包含了字段的数据类型,并指定了新位置。
- C: `alter table student modify id before id;` 语句试图将 `id` 字段移到自身之前,这是不合理的。
- D: `alter table student modify id varchar(8) before id;` 语句试图修改 `id` 字段的数据类型并移到自身之前,这是不合理的。

因此,正确答案是 B。