從下面2句SQL語句執行來看,ide
SELECT * FROM sys.tables WHERE OBJECTPROPERTY(OBJECT_ID,'TableHasPrimaryKey') <> 0 SELECT * FROM sys.tables WHERE OBJECTPROPERTY(OBJECT_ID,'TableHasForeignKey') <> 0
就知道那一張表有主鍵PrimaryKey或ForeignKey。spa
好比,表[Q]和[QQ]既沒有主鍵,也沒有外鍵。code
當在SQL語句的條件中,使用「=」,那說明查詢出來的結果是否,便是不包含主鍵或外鍵。blog
SELECT * FROM sys.tables WHERE OBJECTPROPERTY(OBJECT_ID,'TableHasPrimaryKey') = 0 SELECT * FROM sys.tables WHERE OBJECTPROPERTY(OBJECT_ID,'TableHasForeignKey') = 0