use sql123
if object_id('dbo.employees','u') is not null
drop table dbo.employees
create table dbo.employees
(
empid int not null,
firstname varchar(30) not null,
lastname varchar(30) not null,
hiredate datetime not null,
salary money not null
);
alter table dbo.employees
add constraint pk_employees
primary key (empid);
if object_id('dbo.orders','u') is not null
drop table dbo.orders
create table dbo.orders
(
orderid int not null,
empid int not null,
orderts datetime not null,
constraint pk_orders
primary key (orderid)
);
alter table dbo.orders
add constraint fk_orders_employees
foreign key(empid)
references dbo.employees(empid)
主键约束 强制行 的唯一性, 视频里讲错了一句话,应该改成,更新或删除行,如果违法主键约束,数据库会报错, 行的唯一行,这5个字要注意。 外键是强制引用完整性, 引用表 被引用表 ,为什么会有引用被引用,这个是一种关系模型中定义的规范化。 有些人会认为是不是可以全部整成一个表? 这个是一种关系模型的一种数学过程。 (责任编辑:admin) |