Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Inserting value into new column

Author  Topic 

divya317
Starting Member

16 Posts

Posted - 2008-09-11 : 17:54:58
Hello All,

I have inserted a new column in 'Antiques'table
Column : Id(primary key,Auto increment),Fname,lname,designation
10 records are alreday in the above column. Now, I have addred new column 'IP Address'.
I want to enter data IPAddress of each individual.

When I try to enter values like :
INSERT into Antiques
(IPAddress)
VALUES ('255.255.0.0','98.123.251.21')

It shows me error:

Msg 110, Level 15, State 1, Line 1
There are fewer columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.


Thanks,
Divya

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-09-11 : 17:57:08
Use an UPDATE statement to update the existing rows.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

pommguest99
Starting Member

16 Posts

Posted - 2008-09-11 : 18:59:25
If you want to update it with a new value of IpAddress for each row that is already there, you can try an update statement as follows -

update Antiques
set [Ip Address ] = '10.10.10.10' where Id is not null

or if you want to insert new records, try the following -

Insert into Antiques("Fname","lname","designation","[ip address]")
values ('Divya', 'Divya', 'ITAdmin', '10.10.01.10')

regards,
Anil

Go to Top of Page

divya317
Starting Member

16 Posts

Posted - 2008-09-12 : 10:46:19
Is there any way that I can insert all the IP address in one shot with the help of 'ID' i.e. autoincrment number?
Go to Top of Page

pommguest99
Starting Member

16 Posts

Posted - 2008-09-12 : 14:21:21
If they are all distinct ip address then you cannot do that. You have to insert record by record.

Im not sure if I answered your question.

regards,
Anil
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-13 : 13:32:18
quote:
Originally posted by divya317

Is there any way that I can insert all the IP address in one shot with the help of 'ID' i.e. autoincrment number?


you can. but how would you decide which IP address should go to which ID record?DO you have any related columns in both tables?
Go to Top of Page

pommguest99
Starting Member

16 Posts

Posted - 2008-09-15 : 13:07:18
Visakh16,

Hello !!!

Im a student of a database programming class & I started delving into db's only the past few months or so.

I just saw your reply to the question posed in here.

So can you please educate me as how to insert unique IP addressess against lets say an identifier(pk). I been thinking about this for the past half hour & Im clueless & I would want to find out.

regards,
Anil.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-15 : 13:12:17
quote:
Originally posted by pommguest99

Visakh16,

Hello !!!

Im a student of a database programming class & I started delving into db's only the past few months or so.

I just saw your reply to the question posed in here.

So can you please educate me as how to insert unique IP addressess against lets say an identifier(pk). I been thinking about this for the past half hour & Im clueless & I would want to find out.

regards,
Anil.


What i got from OPs post was a way to update a table column with IPaddresses from another table. Thats why i asked how the two tables are related i.e what determines which ipaddress should be assigned to which record.
Go to Top of Page
   

- Advertisement -