引用作为主键的外键与父表上的另一个键

时间:2016-10-04 17:33:48

标签: sql database oracle foreign-keys foreign-key-relationship

我有那些表:

override func viewDidLoad() {
    super.viewDidLoad()
    for view: UIView in pageViewController!.view.subviews {
        if (view is UIScrollView) {
            let scrollView = (view as! UIScrollView)
            self.scrollViewPanGestureRecognzier = UIPanGestureRecognizer()
            self.scrollViewPanGestureRecognzier.delegate = self
            scrollView.addGestureRecognizer(scrollViewPanGestureRecognzier)
        }
    }
}

    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
    if gestureRecognizer == scrollViewPanGestureRecognzier {
        guard let panGestureRecognizer = gestureRecognizer as? UIPanGestureRecognizer else { return false }
        let velocity = panGestureRecognizer.velocityInView(view)
        let translation = panGestureRecognizer.translationInView(view)
        if translation.x < 0 {
            return true
        }
        if velocity.x < 0 {
            return true
        }
        return false
    }
    return false
}

创建第二个表时出现此错误:

create table t_table(t1 int, constraint tprim primary key(t1));

create table parent_table(t1 int, p1 int, p2 int, constraint pprim primary key(t1, p1));

create table child_table(t1 int, c1 int, p1 int, constraint cprim primary key(t1, c1), constraint fchild foreign key (p1) references parent_table(p1));
parent_table中的

ORA-02270: no matching unique or primary key for this column-list 并不是唯一的,因此我无法解决此问题。

在这种情况下如何说p1是child_table中引用parent_table(p1)的外键?

提前感谢。

2 个答案:

答案 0 :(得分:2)

你不能。外键引用主键。也许你想要做的是在child_table的外键中包含t1?或者,如果你真的需要像p1这样的东西在child_table中成为FK,那么你可能还需要一个表,仅用于p1,具有唯一值?然后,parent_table和child_table中的p1都是指向此附加表的FK。

答案 1 :(得分:0)

这是不可能的,您必须引用主键