上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 19 下一页
摘要: select * from emp -- * 表示所有的 -- from emp 表示从emp表查询 select empno, ename from emp; select ename, sal*12 as "年薪" from emp; select ename, sal*12 as "年薪", 阅读全文
posted @ 2026-04-22 21:07 菜鸟的奋斗军 阅读(7) 评论(0) 推荐(0)
摘要: 主键通常都是整数 主键值通常都不允许修改 主键不要定义成id 不要使用为业务含义字段充当主键 通常在表中单独添加一个整型编号充当字段 如果一个表中的若干个字段是来自另外若干个表的主键或唯一键 则这若干个字段就是外键 通常来自另一个表的主键,而不是唯一键 因为可能是空 外键不一定来自别的表 有可能来自 阅读全文
posted @ 2026-04-22 15:14 菜鸟的奋斗军 阅读(8) 评论(0) 推荐(0)
摘要: 表是数据库里「存数据的容器」,约束是「给数据定的规矩 / 限制」,一个管存什么,一个管怎么存才合法。 它们的关系:表是主体,约束是依附在表上的规则,没有表就没有约束。 —————————————————————————————————————————————————————————————————— 阅读全文
posted @ 2026-04-21 12:28 菜鸟的奋斗军 阅读(6) 评论(0) 推荐(0)
摘要: create table student5 ( stu_id int primary key, stu_email nvarchar(200) not null, stu_name nvarchar(20) unique, stu_sal int check (stu_sal>=1000 and s 阅读全文
posted @ 2026-04-21 11:33 菜鸟的奋斗军 阅读(10) 评论(0) 推荐(0)
摘要: 要用无实际意义的做主键 不要用业务逻辑做主键,如果要改,关联的外键也需要改 查询效率低 要用一个没有实际意义的编号做主键 stu_id create table student4 ( stu_id int primary key identity(1,1),--自增 stu_name nvarcha 阅读全文
posted @ 2026-04-21 00:58 菜鸟的奋斗军 阅读(9) 评论(0) 推荐(0)
摘要: 你插入数据的时候,不手动填这个字段,数据库就自动帮你填上提前设定好的默认值,不用你每次都重复写。 create table student ( stu_id int primary key, stu_sal int check (stu_sal>=1000 and stu_sal<=12000), 阅读全文
posted @ 2026-04-20 22:56 菜鸟的奋斗军 阅读(9) 评论(0) 推荐(0)
摘要: create table student ( stu_id int primary key, stu_sal int check (stu_sal>=1000 and stu_sal<=12000) ) insert into student values(1,1000) insert into s 阅读全文
posted @ 2026-04-20 22:31 菜鸟的奋斗军 阅读(8) 评论(0) 推荐(0)
摘要: create table dept ( dept_id int primary key, dept_name nvarchar(100) not null, dept_address nvarchar(100) ) create table emp ( --不能写成{ emp_id int cons 阅读全文
posted @ 2026-04-20 20:09 菜鸟的奋斗军 阅读(8) 评论(0) 推荐(0)
摘要: 部门表dept里 dept_id=1 → 人事部(主键) 员工表emp里 dept_id=1 → 这个员工归属人事部(外键) —————————————————————————————————————————————— 插入约束 先插主键表(部门),再插外键表(员工) 员工不能填一个部门表里根本不存 阅读全文
posted @ 2026-04-20 16:24 菜鸟的奋斗军 阅读(8) 评论(0) 推荐(0)
摘要: 一张表只能有 1 个主键 不能重复、不能为空 用来唯一确定某一条数据 举例:学生表里,学号 就是主键每个学生学号不一样,不会重复,不会没有学号 ———————————————————————————————————————————————————————————————————— 外键 Foreig 阅读全文
posted @ 2026-04-20 00:11 菜鸟的奋斗军 阅读(12) 评论(0) 推荐(0)
上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 19 下一页