查询是否有外键: select object_name(a.parent_object_id) 'tables' from sys.foreign_keys a where a.referenced_object_id=object_id('[表名]')
更改主键类型: ---删除原主键 Alter table base_log Drop PK__BASE_LOG__4364C88276969D2E ---修改主键类型 ALTER table base_log ALTER COLUMN LOG_ID NVARCHAR(32) ---把所有主键设为不能为空 Alter table base_log alter column LOG_ID nvarChar(32) not null ---重建主键 Alter table base_log ADD CONSTRAINT PK__BASE_LOG__4364C88276969D2E PRIMARY KEY (LOG_ID)