Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Intsert into table that has unique id?

Status
Not open for further replies.

gtjr92

Programmer
May 26, 2004
96
I am trying to instert data from one table into another. The source table does not have a uniqueIDentifier but the destination table does. How can I get the uniquid field to autopopulate when I do this insert?
Code:
insert into Members(address,phone,firstname,lastname,Email,City,State,zip,no_Permission,Others) Select address,phone,firstname,lastname,Email,City,State,zip,no_Permission,Others from DIR;
I keep getting Cannot insert the value NULL into column 'memberid', ; column does not allow nulls. INSERT fails.
The statement has been terminated.
 
Since you are getting this error you are not using an identity field. What method is the system using to generate the unique numbers?

Denny
MCSA (2003) / MCDBA (SQL 2000)

--Anything is possible. All it takes is a little research. (Me)

[noevil]
(Not quite so old any more.)
 
Use this

Code:
insert into Members([i]memberid[/i], address,phone,firstname,
lastname, Email,City,State,zip,no_Permission,Others) 

Select [i](newid())[/i], address,phone,firstname,
lastname, Email,City,State,zip,no_Permission,Others 
from DIR;


dale
 
That will work fine, if you are using a uniqueidentifier. Are you using an uniqueidentifier or a number?

Denny
MCSA (2003) / MCDBA (SQL 2000)

--Anything is possible. All it takes is a little research. (Me)

[noevil]
(Not quite so old any more.)
 
I will try what was suggested and let you know when i get a chance tommorow
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top