Skip to content

Naming a default constraint

I’m trying to create a default constraint here, but the system is generating a weird name for it. If I want to name it df_MY_TABLE_GUID or something, how could I specify that name be used? Answer Just specify the constraint name with the full syntax, like the UNIQUE in your example: As a matter of routi…

Summarize aggregations into friendly text

This is my table in SQL Server : and I want this output in SQL Server (return this Text with Query not function): Does anyone know how I can do this? Answer Modern Versions If on SQL Server 2017 or better, you can also do it this way (and this prevents you from having to know in advance and hard-code

Show all varchar values with PIVOT

I need to show all varchar values with pivot but I’m not sure if that is possible? I have OCCUPATIONS table: Pivot query: Query result: Above query gives only 1 record in each column but I want to get all. Answer You ‘ll need an extra column, e.g. with ROW_NUMBER():