Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SQL Server Error 1733: Sparse Column Set Fix

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

SQL Server error 1733 ('Cannot create the sparse column set because the table already contains a sparse column set') occurs when you try to add a second sparse column set to a table that already has one. A table can have only one sparse column set, so the fix is to either use the existing column set or drop it before creating a new one. The exact steps depend on whether you are working in SQL Server Management Studio (SSMS) or running T-SQL scripts.

What You'll Need

  • SQL Server Management Studio (SSMS) or another client such as Azure Data Studio, connected to your database.
  • ALTER permission on the table (or db_owner role).
  • The name of the table and the existing sparse column set (if any).
  • A backup of the table or database before making schema changes.

Step-by-Step

  1. Identify the existing sparse column set. Run this query in a new query window, replacing YourTable with your table name:
    SELECT name, is_column_set
    FROM sys.columns
    WHERE object_id = OBJECT_ID('YourTable') AND is_column_set = 1;
    If a row is returned, that is the column set already defined on the table. Note its name.
  2. Decide whether you need a new column set. If the existing column set already serves your purpose, you do not need to create another. You can use the existing one and skip the rest of these steps.
  3. If you must replace it, drop the existing column set first. Use:
    ALTER TABLE YourTable DROP COLUMN ExistingColumnSetName;
    Replace ExistingColumnSetName with the name from step 1. This removes the column set but does not delete the underlying sparse columns.
  4. Create the new sparse column set. Run:
    ALTER TABLE YourTable ADD NewColumnSetName COLUMN_SET FOR ALL_SPARSE_COLUMNS;
    Replace NewColumnSetName with your desired name. The column set must be the only one on the table.
  5. Verify the change. Re-run the query from step 1. You should see exactly one row with is_column_set = 1 and the new name.
  6. Test data access. Insert or update a row and select from the table to ensure the column set behaves as expected. Remember that a column set is a nullable XML column that represents all sparse columns; you cannot update it directly if it is computed.

Common Mistakes

  • Trying to add a second column set without dropping the first. This is the direct cause of error 1733. Always check for an existing column set first.
  • Assuming the error means the table has no column set. The message says 'already contains a sparse column set', so the opposite is true.
  • Dropping the column set without considering dependencies. If the column set is referenced by a view, function, or application, dropping it will break those objects. Script out dependencies first.
  • Using the wrong table name or schema. Always qualify with schema (e.g., dbo.YourTable) to avoid acting on the wrong object.
  • Forgetting that a column set is optional. You do not need a column set to use sparse columns; it is only for convenient access to all sparse columns as XML.

Tips

  • Before making schema changes, back up the table or database. You can use SELECT INTO to create a quick copy of the data.
  • Use sp_help YourTable to see all columns, including sparse and column set columns.
  • If you are scripting a deployment, wrap the drop and add in a transaction so you can roll back if something fails.
  • Consider whether a column set is truly needed. It adds an XML column that can be large; for wide tables with many sparse columns, it can simplify queries but may increase storage.
  • When altering a table with a column set, remember that you cannot add a sparse column set to a table that already has one, even if the existing one is not used.

Troubleshooting

If you still get error 1733 after dropping the column set, check for hidden or system-named column sets. Query sys.columns again without filtering by name to see all columns with is_column_set = 1. If the drop fails due to dependencies, use sp_refreshsqlmodule or drop and recreate dependent objects. If you lack permissions, ask a database administrator to run the ALTER statements. In rare cases, the table might be replicated or part of a schema-bound view; you may need to remove it from replication or drop the view first. Always test changes on a development copy before applying to production.

Frequently Asked Questions

Can I have more than one sparse column set on a table?

No. SQL Server allows only one sparse column set per table. Error 1733 is raised when you try to add a second one.

What happens to my data if I drop the column set?

Dropping the column set removes only the XML column that represents all sparse columns. The individual sparse columns and their data remain intact.

Do I need a sparse column set to use sparse columns?

No. Sparse columns work without a column set. The column set is an optional convenience for selecting all sparse columns as XML.

Why does the error mention 'sparse column set' when I didn't create one?

The table may have been created with a column set by a script, or a previous attempt added one. Check sys.columns as shown in step 1.

Can I rename a sparse column set?

No, you cannot rename a column set directly. You must drop it and create a new one with the desired name.

Does error 1733 affect indexes or constraints?

The error only prevents adding a second column set. Existing indexes and constraints are unaffected unless you drop the column set they reference.