dbTalk Databases Forums  

how to create a field in a view that is unique

microsoft.public.sqlserver.programming microsoft.public.sqlserver.programming


Discuss how to create a field in a view that is unique in the microsoft.public.sqlserver.programming forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Roger
 
Posts: n/a

Default how to create a field in a view that is unique - 11-30-2011 , 11:10 AM






I've got a view, pulling fields from many tables
but no one table's key is being used, so I have no unique field
is there a function in sql server that will do this ?

ie
select a.cust, b.price, x
from tblCust as a inner join tblCustPrice on a.cust = b.cust

how to make 'x' be 1,2,3, etc

Reply With Quote
  #2  
Old   
Bob Barrows
 
Posts: n/a

Default Re: how to create a field in a view that is unique - 11-30-2011 , 12:42 PM






Roger wrote:
Quote:
I've got a view, pulling fields from many tables
but no one table's key is being used, so I have no unique field
is there a function in sql server that will do this ?

ie
select a.cust, b.price, x
from tblCust as a inner join tblCustPrice on a.cust = b.cust

how to make 'x' be 1,2,3, etc
Use the ROW_NUMBER() function. See BOL (Books Online) for examples.

Reply With Quote
  #3  
Old   
Roger
 
Posts: n/a

Default Re: how to create a field in a view that is unique - 11-30-2011 , 06:05 PM



On Nov 30, 11:42*am, "Bob Barrows" <reb01... (AT) NOyahooSPAM (DOT) com> wrote:
Quote:
Roger wrote:
I've got a view, pulling fields from many tables
but no one table's key is being used, so I have no unique field
is there a function in sql server that will do this ?

ie
* *select a.cust, b.price, x
* * * from tblCust as a inner join tblCustPrice on a.cust = b.cust

how to make 'x' be 1,2,3, etc

Use the ROW_NUMBER() function. See BOL (Books Online) for examples.
thanks

Reply With Quote
  #4  
Old   
--CELKO--
 
Posts: n/a

Default Re: how to create a field in a view that is unique - 12-05-2011 , 04:22 PM



Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, data types, etc. in
your schema are. Please learn to follow ISO-11179 data element naming
conventions and formatting rules. Temporal data should use ISO-8601
formats. Code should be in Standard SQL as much as possible and not
local dialect.

Sample data is also a good idea, along with clear specifications. It
is very hard to debug code when you do not let us see it. If you want
to learn how to ask a question on a Newsgroup, look at:
http://www.catb.org/~esr/faqs/smart-questions.html I have following
tables and business rules.

Quote:
I've got a view, pulling fields [sic: columns are nothing like fields] from many tables but no one table's key is being used, so I have no unique field [sic]
So the VIEW has no key? So it is what we call “Garbage” in IT? What
attribute does this magic number model? Guess at usable data element
names, how does this work for you?

SELECT C1.cust_nbr, C2.something_price,
ROW_COUNT()
OVER (ORDER BY C1.cust_nbr, C2.something_price)
AS meaningless_seq
FROM Customers AS C1,
Customers AS C2
WHERE C1.cust_nbr = C2.cust_nbr;

OYour VIEW can now be used as a non-relational magnetic tape file,
which do have fields and not columns. Your whole approach is wrong;
please read a book on basic RDBMS.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.