约束后uc的用途是什么?

时间:2016-04-29 08:58:23

标签: sql

CREATE TABLE Persons
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
CONSTRAINT **uc**_PersonID UNIQUE (P_Id,LastName)
)

1 个答案:

答案 0 :(得分:3)

命名约束是绝对好的做法(否则SQL Server会使用随机名称命名它们,这使得使用常规升级脚本升级多个系统变得非常困难)。

最好使用前缀来查看这是什么类型的约束。

常见的是

  • UQ,UC或UK的唯一约束/唯一密钥
  • FK for foreign key
  • 主键的PK
  • CK表示CHECK约束

更新

最好将表的名称添加到约束中(以避免歧义)。在你的情况下,这是:

import UIKit
import CoreLocation

class HomeViewController: UIViewController, UIScrollViewDelegate ,UICollectionViewDataSource, UICollectionViewDelegate, CLLocationManagerDelegate  { 

// Location Manager
var locationManager: CLLocationManager = CLLocationManager()

//MARK: Location related functions
func trackLocation(){
    // Set the delegate
    self.locationManager.delegate = self

    // Request location authorization
    self.locationManager.requestWhenInUseAuthorization()

    // Request a location update
    if #available(iOS 9.0, *) {
        self.locationManager.requestLocation()
    } else {
        // Fallback on earlier versions
    }

    // Start location updates
    self.locationManager.startUpdatingLocation()

}

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    if let location = locations.first {
        print("Found user's location: \(location)")
    }
}

func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
    print("Failed to find user's location: \(error.localizedDescription)")
}

Btw(命名约定):以单数形式使用表名(人而不是人)是很常见的。请在此处阅读:Table Naming Dilemma: Singular vs. Plural Names