当前位置: 首页> 房产> 政策 > 中国最大的手表网站_北京网站搜索引擎优化推广_广告传媒公司经营范围_郑州网站推广报价

中国最大的手表网站_北京网站搜索引擎优化推广_广告传媒公司经营范围_郑州网站推广报价

时间:2025/7/9 2:29:32来源:https://blog.csdn.net/printf_printf_/article/details/145500089 浏览次数:0次
中国最大的手表网站_北京网站搜索引擎优化推广_广告传媒公司经营范围_郑州网站推广报价

创建学生表;

mysql> create table Student(-> Sno int primary key auto_increment,-> Sname varchar(30) not null unique,-> Ssex char(2) check (Ssex='男' or Ssex='女') not null,-> Sage int not null,-> Sdept varchar(10) default '计算机' not null-> );
Query OK, 0 rows affected (0.04 sec)

创建课程表;

mysql> create table Course(-> Cno int primary key not null,-> Cname varchar(20) not null-> );
Query OK, 0 rows affected (0.03 sec)

创建选课表;

mysql> create table SC(-> Sno int not null,-> Cno varchar(10) primary key not null,-> Score int not null-> );
Query OK, 0 rows affected (0.02 sec)

1、修改 Student 表中年龄(Sage)字段属性

mysql> alter table Student modify column Sage smallint;
Query OK, 0 rows affected (0.07 sec)
Records: 0  Duplicates: 0  Warnings: 0

2、为 Course 表中 Cno 课程号字段设置索引并查看索引

mysql> create index course_cno_index on Course(Cno);
Query OK, 0 rows affected (0.02 sec)
Records: 0  Duplicates: 0  Warnings: 0mysql> show index from Course;
+--------+------------+------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| Table  | Non_unique | Key_name         | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression |
+--------+------------+------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| course |          0 | PRIMARY          |            1 | Cno         | A         |           0 |     NULL |   NULL |      | BTREE      |         |               | YES     | NULL       |
| course |          1 | course_cno_index |            1 | Cno         | A         |           0 |     NULL |   NULL |      | BTREE      |         |               | YES     | NULL       |
+--------+------------+------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
2 rows in set (0.01 sec)

3、为 SC 表建立按学号(Sno)和课程号(Cno)组合的升序的主键索引,需要先删除可能存在的主键索引。

mysql> alter table SC drop primary key;
Query OK, 0 rows affected (0.05 sec)
Records: 0  Duplicates: 0  Warnings: 0mysql> alter table SC add primary key (Sno,Cno);
Query OK, 0 rows affected (0.04 sec)
Records: 0  Duplicates: 0  Warnings: 0

4、创建视图 stu_info

mysql> create view stu_info as-> select S.Sname, S.Ssex, C.Cname, SC.Score-> from Student S-> join SC on S.Sno = SC.Sno-> join Course C on SC.Cno = C.Cno;
Query OK, 0 rows affected (0.01 sec)

5、删除所有索引:
        对于 Student 表,由于没有显式创建索引,无需删除索引操作。
        对于 Course 表:

mysql> drop index course_cno_index on Course;
Query OK, 0 rows affected (0.02 sec)
Records: 0  Duplicates: 0  Warnings: 0

        对于 SC 表,通过alter table添加的主键索引:

mysql> alter table SC drop primary key;
Query OK, 0 rows affected (0.04 sec)
Records: 0  Duplicates: 0  Warnings: 0

 

 

关键字:中国最大的手表网站_北京网站搜索引擎优化推广_广告传媒公司经营范围_郑州网站推广报价

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: