May 7, 2009 at 10:21 pm
is it possible to create a Unique Column in view. similar to an autoincrementing column
thanks
May 8, 2009 at 12:37 am
What exactly you want to do? Cant you use cursor?
"Don't limit your challenges, challenge your limits"
May 8, 2009 at 12:54 am
It is possible. If you’ll give us more details about what you are trying to do, you’ll get better help and examples. In any case the code bellow shows you one way of doing so with ranking functions:
create view MyView
as
select ROW_NUMBER() over(order by object_id) as RowNum, name
from sys.objects
go
select * from MyView
go
drop view MyView
Adi
--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
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/
May 8, 2009 at 12:56 am
Yes, it is possible in SQL 2005 using ROW_NUMBER() function.
CREATE VIEW dbo.vwSysTables
AS
SELECT ROW_NUMBER() OVER( ORDER BY [name] ) AS UniqueNo, [name] FROM sys.tables
GO
SELECT * FROM dbo.vwSysTables
DROP VIEW dbo.vwSysTables
--Ramesh
May 8, 2009 at 3:11 am
frecal (5/7/2009)
is it possible to create a Unique Column in view. similar to an autoincrementing columnthanks
Also see what you can do with row_number() function
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx
Failing to plan is Planning to fail
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply