Should I use SQL_Variant data type?

后端 未结 3 509
半阙折子戏
半阙折子戏 2020-12-03 07:29

using SQL Server 2005 with SP4 and I am designing a database table.

Here is the table DDL

CREATE TABLE CPSync4D.ProjectProfilerOption
(
    ProjectP         


        
3条回答
  •  暖寄归人
    2020-12-03 07:40

    Its worth noting that it is not possible to copy the sql_variant column implicitly.

    e.g. Create a backup schema of CPSync4D.ProjectProfilerOption called CPSync4D.ProjectProfilerOption_bkp

    and then

    Insert into CPSync4D.ProjectProfilerOption_bkp
    (
        ProjectProfilerOptionID
       ,ProjectID
       ,ProfilerOptionID
       ,ProfilerOptionValue 
    )
    SELECT 
        ProjectProfilerOptionID
       ,ProjectID
       ,ProfilerOptionID
       ,ProfilerOptionValue 
    FROM CPSync4D.ProjectProfilerOption 
    

    All of the values for ProfilerOptionValue in the backup table will be varchar

    Note also: I have been told that the SQL_Variant cannot be used in replication but this is not true. Certainly it can be done with SQL 2008 R2 (that I am using) because I have just done it but this may have been true for older versions (I don't have any older versions to check with so cannot confirm or deny this).

    What is true though, is that if you do replicate a table with a SQL Variant in it and have a lot of data and then something goes wrong and you need to fix the data manually, then you might have a nasty piece of SQL to write. This is because when copying the data you cannot copy with several base types in the same copy statement. I guess that replication doesn't have this issue because it does not copy multiple rows (with the obvious exception of the snapshot but that uses bcp).

    ps. I realise this is an old post but put this here for other future visitors with the same question.

提交回复
热议问题