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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 add column name

Author  Topic 

ovince
Starting Member

32 Posts

Posted - 2007-02-17 : 05:17:29
Hi All,

I have 2 columns in database but they do not have names. How to add column names with SQL query?

Thanks
oliver

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-02-17 : 07:47:43
Can you tell how you got two columns without a name? I don't think SQL Server allows that.

To rename a column:

EXEC sp_rename 'Table.Col1', 'Col2', 'COLUMN'


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-17 : 08:10:24
you created a with a single space ?

create table tbl
(
[ ] int,
col int
)


use sp_rename as Harsh suggested to rename the column

exec sp_rename 'tbl.[ ]', 'newcol', 'COLUMN'


use sp_help to view the table structure

exec sp_help tbl



KH

Go to Top of Page

ovince
Starting Member

32 Posts

Posted - 2007-02-17 : 08:26:42
hi

I use the SQL to take data from one database. It allows to import files with data and automatically creates table from it. Before importing the file I forgot to put column names and now I am unhappy since I can not join with other tables :). I will import once again with name (I wanted to avoid this because the data file is large-importing is long)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-17 : 08:44:22
use sp_rename to rename as suggested


KH

Go to Top of Page
   

- Advertisement -