Relative Content

SQL

Search and rename Foreign Key Name

List foreign keys: select schema_name(fk_tab.schema_id) + ‘.’ + fk_tab.name as foreign_table, ‘>-‘ as rel, schema_name(pk_tab.schema_id) + ‘.’ + pk_tab.name as primary_table, substring(column_names, 1, len(column_names)-1) as [fk_columns], fk.name as fk_constraint_name from sys.foreign_keys fk inner join sys.tables fk_tab on fk_tab.object_id = fk.parent_object_id inner join sys.tables pk_tab on pk_tab.object_id = fk.referenced_object_id cross apply (select col.[name] + ‘, ‘ […]

Update if parameter is not null or empty

Using just IsNull your query would look something like… UPDATE [Users]SET FirstName = IsNull(@FirstName, FirstName),City = IsNull(@City, City)….WHERE … DECLARE @value AS INT = NullSELECT CASE WHEN ISNULL(@value, 2)=0 THEN Null Else ISNULL(@value, 2) END will Update the row with the param value if they are NOT null, otherwise update it to itself aka change […]