使用TableHasPrimaryKey或TableHasForeignKey来知道表是否有主键或外键
程序员文章站
2023-09-07 08:19:11
从下面2句SQL语句执行来看, SELECT * FROM sys.tables WHERE OBJECTPROPERTY(OBJECT_ID,'TableHasPrimaryKey') <> 0 SELECT * FROM sys.tables WHERE OBJECTPROPERTY(OBJEC ......
从下面2句sql语句执行来看,
select * from sys.tables where objectproperty(object_id,'tablehasprimarykey') <> 0 select * from sys.tables where objectproperty(object_id,'tablehasforeignkey') <> 0
就知道那一张表有主键primarykey或foreignkey。
比如,表[q]和[qq]既没有主键,也没有外键。
当在sql语句的条件中,使用“=”,那说明查询出来的结果是否,即是不包含主键或外键。
select * from sys.tables where objectproperty(object_id,'tablehasprimarykey') = 0 select * from sys.tables where objectproperty(object_id,'tablehasforeignkey') = 0