Insert varbinary data into SQL Server database

前端 未结 1 1037
日久生厌
日久生厌 2021-02-07 03:07

I have this table:

   (
   ,
   ,)

I tr

相关标签:
1条回答
  • 2021-02-07 03:22

    Two issues:

    Issue #1: don't use TEXT anymore - it's deprecated. Use a VARCHAR(n) with a suitable size of n, or if you really must (only if you REALLY must), use VARCHAR(MAX)

    CREATE TABLE dbo.CONNECT_USER
    (
        NUM_TRF int,
        NAME varchar(255),
        DESCRIPTION varchar(1000),
        REPORT varbinary(max)
    )
    

    I would personally also avoid writing EVERYTHING IN ALL CAPS - this just makes it so much harder to read! And I would try to avoid very generic column names like Name or Description - those are not very intuitive, and might collide with other table's columns and / or with SQL Server reserved keywords. Try to use more expressive, more context-related column names that make sense in your environment (ConnectUsername or whatever)

    Issue #2: when doing an INSERT, I would recommend to always define the column you want to insert into. This avoids unpleasant surprises when a table is restructured or new columns are added:

    INSERT INTO [MY_DB_APP].[dbo].[CONNECT_USER](NUM_TRF, NAME, DESCRIPTION, REPORT)
    VALUES(1, 'name', 'description', CAST('wahid' AS VARBINARY(MAX)))
    GO
    
    0 讨论(0)
提交回复
热议问题