Get_RDS_Task_Schema

Snippet Name: Get_RDS_Task_Schema

Tags:

Created Date: 2025-06-16 13:12:38
Last Modified Date: 2025-05-31 10:32:05

Dependencies:

DBA Notes:

Sample Output:

Title: Get RDS Task Schema
Author: user
how can i get the schema of the table output from EXEC msdb.dbo.rds_task_status;

Author: ChatGPT
The `msdb.dbo.rds_task_status` stored procedure is specific to **Amazon RDS for SQL Server**, and it returns the status of various RDS tasks (like backups, restores, etc.). However, it **does not return a strongly typed result set**, so you can't directly use `SELECT * INTO` or reference it like a table.

To get the schema (columns and data types) of the result set it returns, you can use a couple of approaches:

---

### ??? Option 1: Use `INSERT ... EXEC` into a temporary table (manually defined)
Since `EXEC msdb.dbo.rds_task_status` outputs a known set of columns, you can **create a temp table** with the expected schema and then **insert into it**:

```sql
-- Step 1: Create the temp table with the known schema
CREATE TABLE #rds_task_status (
    task_id INT,
    task_type NVARCHAR(100),
    db_name NVARCHAR(128),
    status NVARCHAR(100),
    percent_complete INT,
    duration INT,
    last_modified_time DATETIME,
    lifecycle NVARCHAR(100),
    created_time DATETIME,
    S3_object_arn NVARCHAR(300),
    overwrite_S3_backup_file BIT,
    kms_key_id NVARCHAR(256),
    task_metadata NVARCHAR(MAX),
    error_code INT,
    error_message NVARCHAR(MAX)
);

-- Step 2: Insert the output from the stored procedure
INSERT INTO #rds_task_status
EXEC msdb.dbo.rds_task_status;

-- Step 3: Inspect the schema
SELECT * FROM tempdb.sys.columns WHERE object_id = OBJECT_ID('tempdb..#rds_task_status');

-- Or just query the data
SELECT * FROM #rds_task_status;
```

---

### ??? Option 2: Use `sp_describe_first_result_set` (Not supported for all procs)

You *can try*:

```sql
EXEC sp_describe_first_result_set N'exec msdb.dbo.rds_task_status';
```

But this **might return NULLs** if SQL Server can't determine metadata (common with RDS stored procedures), so Option 1 is more reliable.

---

### ??? Option 3: Use SQL Server Management Studio (SSMS) results
Just run:

```sql
EXEC msdb.dbo.rds_task_status;
```

Then right-click the result grid ??? "Save Results As..." ??? CSV. Open the CSV and manually define a table schema based on the columns and types.

---

Would you like a script to automatically generate a `CREATE TABLE` statement from the result set too?


Leave a Reply