赞
踩
参考http://blog.csdn.net/fredrickhu/article/details/4708906一
(一)先打开sql server数据库,创建数据库Stu ,创建两个表:
create database Stu
- create table Student(
- StudentID int primary key,
- StudentName nvarchar(50),
- StudentAge int
- )
-
- create table BorrowRecord(
- BorrowRecord int identity(1,1),
- StudentID int,
- BorrowDate Datetime,
- ReturnDate Datetime
- )
注意这里不能添加外键,添加外键后有约束,就不能激发触发器了。下面的外键操作供自己复习:
- --添加外键
- alter table BorrowRecord
- add constraint fk_StudentID
- foreign key(StudentID) references Student(StudentID)
-
- --删除外键
- alter table BorrowRecord drop constraint fk_StudentID
- insert into Student values(1,'王五',20)
- insert into Student
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。