This is a discussion on creating a view with columns not in another table within the SQL Server forums, part of the Microsoft SQL Server category; --> Hello, I'm somewhat of a newbie and I need to create a view with a column that is not ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hello, I'm somewhat of a newbie and I need to create a view with a column that is not derived from any other tables. What I want is for this field to be an auto-increment field or some kind of UID. Can anyone quickly tell me how to do this. Here is my dilemma. I need to pull data from a unique data set from a table which does not have a primary key, and none exists in its data. Please tell me how to put this data in a view(or another table) so that I can pull it out with unique records. It doesnt matter what the unique field consists of. Thanks |
| |||
| Add newid() to your select statement. Select newid(), This will create a UID for each line returned by the select statement. margraft@yahoo.com wrote in message news:<1db47099.0411231136.50d722c7@posting.google. com>... > Hello, > > I'm somewhat of a newbie and I need to create a view with a column > that is not derived from any other tables. What I want is for this > field to be an auto-increment field or some kind of UID. Can anyone > quickly tell me how to do this. > > Here is my dilemma. I need to pull data from a unique data set from a > table which does not have a primary key, and none exists in its data. > Please tell me how to put this data in a view(or another table) so > that I can pull it out with unique records. It doesnt matter what the > unique field consists of. > > Thanks |
| |||
| > Select newid(), > > This will create a UID for each line returned by the select statement. If you do twice the request, the UID wont be the same... So it removes a lot of the interest of the UID. The best thing to do would ne to add a primary key to the table... -- Vincent |
| ||||
| (margraft@yahoo.com) writes: > I'm somewhat of a newbie and I need to create a view with a column > that is not derived from any other tables. What I want is for this > field to be an auto-increment field or some kind of UID. Can anyone > quickly tell me how to do this. > > Here is my dilemma. I need to pull data from a unique data set from a > table which does not have a primary key, and none exists in its data. > Please tell me how to put this data in a view(or another table) so > that I can pull it out with unique records. It doesnt matter what the > unique field consists of. Using newid() as Mike suggested will give you a 16-byte binary value, which may be somewhat difficult to manage. But it's certainly the easiest method. If you want an integer number, the best is probably to write a multi-step table function where you select the data into a table with an IDENTITY column, and then return that table. -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp |