how to create surrogate id for view in tsql

  • hi,

    i have problem in tsql while creating the surrogate key for a view table.

    can any one help on this.....:-)

  • Can you expand a bit?

    An example would help a lot.

    -- Gianluca Sartori

  • Why would you create a surrogate key on a view?

    For better, quicker answers on T-SQL questions, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • hi, this is my source table i need to create view table for this with surrogate key.Can u help me................

    SELECT TOP 1000 [C_ID]

    ,[C_NM]

    ,[C_TYPE_ID]

    ,[DUR]

    ,[FEES]

    ,[LOAN_AV_FLG]

    ,[INSTALMENT]

    ,[NO_INSTALMENT]

    FROM [Mahesh_DB].[dbo].[Course]

  • maheshkrishnas (6/27/2011)


    hi, this is my source table i need to create view table for this with surrogate key.Can u help me................

    SELECT TOP 1000 [C_ID]

    ,[C_NM]

    ,[C_TYPE_ID]

    ,[DUR]

    ,[FEES]

    ,[LOAN_AV_FLG]

    ,[INSTALMENT]

    ,[NO_INSTALMENT]

    FROM [Mahesh_DB].[dbo].[Course]

    My recommendation would be to lookup CREATE VIEW in Books Online for this. Books Online is the help-system that comes with SQL Server.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Any reason why you cannot use C_ID itself , if you need an other then try using the row_number function or a guid or a computed column. I cant see why your view would need one , however its godd to keep in mind that the key will be used by applications and should not change.

    Ideally an Identity column on the underlying table is the best solution.

    Jayanth Kurup[/url]

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply