473,385 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

creating a view with columns not in another table

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
Jul 20 '05 #1
3 1429
Add newid() to your select statement.

Select newid(),

This will create a UID for each line returned by the select statement.

ma******@yahoo.com wrote in message news:<1d**************************@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

Jul 20 '05 #2
> 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
Jul 20 '05 #3
(ma******@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, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Richard Holliingsworth | last post by:
Hello: I have an Access 2K form I built from a SQL Server 7.0 view. I want to lock certain fields in the database from users so they can see them on the views and forms, but NOT be able to edit...
0
by: billmiami2 | last post by:
Perhaps many of you MS Access fanatics already know this, but it seems that stored procedures and views are possible in Jet. I thought I would leave this message just in case it would help anyone....
6
by: davegb | last post by:
I'm trying to create a self-join table to show the relationship between employee and supervisor. In another thread, I was advised to create a SupervisorID in the employee table, a separate...
2
by: bthalapathi | last post by:
I had a table called 'FruitSaleList', that contains the following columns sl.no, shop_id, fruitName, price, .... I had also another table called 'FruitList' that contains the columns ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.