included actual sql query to discover fi foreign key with the same name exists in a specific table of the database in use
This commit is contained in:
		
							parent
							
								
									9044197ef9
								
							
						
					
					
						commit
						9a4a2b53ad
					
				@ -130,7 +130,14 @@ func (s mssql) RemoveIndex(tableName string, indexName string) error {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s mssql) HasForeignKey(tableName string, foreignKeyName string) bool {
 | 
			
		||||
	return false
 | 
			
		||||
	var count int
 | 
			
		||||
	currentDatabase, tableName := currentDatabaseAndTable(&s, tableName)
 | 
			
		||||
	s.db.QueryRow(`SELECT count(*) 
 | 
			
		||||
	FROM sys.foreign_keys as F inner join sys.tables as T on F.parent_object_id=T.object_id 
 | 
			
		||||
		inner join information_schema.tables as I on I.TABLE_NAME = T.name 
 | 
			
		||||
	WHERE F.name = ? 
 | 
			
		||||
		AND T.Name = ? AND I.TABLE_CATALOG = ?;`, foreignKeyName, tableName, currentDatabase).Scan(&count)
 | 
			
		||||
	return count > 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s mssql) HasTable(tableName string) bool {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user