|
|
|
|
|
|
|
| Question of the Day |
Today's question (by Steve Jones - SSC Editor): | |
Identities and Sequences I | |
| When thinking of the Identity property for auto incrementing columns and sequences for the same action, which are explicitly linked to increment a number in a table when a new row is added? | |
Think you know the answer? Click here, and find out if you are right. | |
| Yesterday's Question of the Day (by Steve Jones - SSC Editor) |
Fun with JSON II I have some data in a table: CREATE TABLE #test_data
(
id INT PRIMARY KEY,
name VARCHAR(100),
birth_date DATE
);
-- Step 2: Insert rows
INSERT INTO #test_data
VALUES
(1, 'Olivia', '2025-01-05'),
(2, 'Emma', '2025-03-02'),
(3, 'Liam', '2025-11-15'),
(4, 'Noah', '2025-12-22');If I run this query, how many rows are returned? SELECT t1. AS row,
t2.*
FROM OPENJSON(
(
SELECT t.* FROM #test_data AS t FOR JSON PATH
)
) t1
CROSS APPLY OPENJSON(t1.value) t2;Answer: 12 Explanation: The inner query combines all the data into 1 row. The OPENJSON() with the SELECT inside will break this into 4 rows, one for each row of data. The cross apply takes the value and then splits each of those into its own row. Each column in the table (3 of them) gets broken into a row. With 4 rows, this is 12 rows returned. Ref: OPENJSON - https://learn.microsoft.com/en-us/sql/t-sql/functions/openjson-transact-sql?view=sql-server-ver17 |
| Database Pros Who Need Your Help |
Here's a few of the new posts today on the forums. To see more, visit the forums. |
| SQL Server 2019 - Administration |
| Windows logins for users migrated from DomainA to DomainB - Hi, I have a SQL Server instance where users connect to via Windows Authentication, so for each user there is a row in sys.server_principals with (as example) "DomainA\JohnDoe". Recently a lot of users were migrated to DomainB (same forest) using the ADMigration wizard. Although I haven't created a new "DomainB\JohnDoe" login, this user is still […] |
| SQL Server 2019 - Development |
| how to write this query? - Hi everyone I asked this earlier but the desired outcome is a bit different this time so I am starting a new post. I would like to transform the source table into the desired outcome format. How can I do this? Desired Outcome: Sample Data: drop table if exists #temp1 create table #temp1 ( report_run_time […] |
| would it be so terrible to install ssms on a few user desktops? - Hi, ssms is free here. I can think of other reasons to do this but i would like to install ssms on the desktops of a FEW users who already know, or have the aptitude to learn sql. and are willing to be limited to very small "governed" datsets. We have excel sprawl from 2 […] |
| Editorials |
| Breaking Down Your Work - Comments posted to this topic are about the item Breaking Down Your Work |
| Multiple Deployment Processes - Comments posted to this topic are about the item Multiple Deployment Processes |
| A Full Shutdown - Comments posted to this topic are about the item A Full Shutdown |
| I'm thinking about submitting some articles - I've written some documentation on using different Markdown types of files on GitHub. It's a series of documents. Some of them are long, but others are short. Anyway, what I don't know is if I should just submit them as separate articles or if they would qualify as a Stairway. Would someone with SQL Server […] |
| Not Just an Upgrade - Comments posted to this topic are about the item Not Just an Upgrade |
| Article Discussions by Author |
| Restoring On Top II - Comments posted to this topic are about the item Restoring On Top II |
| SQL Art 2: St Patrick’s Day in SSMS (Shamrock + Pint + Pixel Text) - Comments posted to this topic are about the item SQL Art 2: St Patrick’s Day in SSMS (Shamrock + Pint + Pixel Text) |
| How to Use sqlpackage to Detect Schema Drift Between Azure SQL Databases - Comments posted to this topic are about the item How to Use sqlpackage to Detect Schema Drift Between Azure SQL Databases |
| Upgrading Admin Queries - Comments posted to this topic are about the item Upgrading Admin Queries |
| OPENQUERY Flexibility - Comments posted to this topic are about the item OPENQUERY Flexibility |
| Going Native with Fabric Spark Pools: The Fabric Modern Data Platform - Comments posted to this topic are about the item Going Native with Fabric Spark Pools: The Fabric Modern Data Platform |
| SQL Server 2022 - Administration |
| XACT_ABORT being set to ON by web services - We have two "identical" instances of an ASP.NET web service (or so I have been told), that are connecting to databases that are also reasonably identical, running on separate instances of SQL Server 2022. For some reason, XACT_ABORT has been found to be set to ON with one of the web services, but not with […] |
| |
| ©2019 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved. webmaster@sqlservercentral.com |