Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi All,I have 2 columns in database but they do not have names. How to add column names with SQL query?Thanksoliver
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 AthalyeIndia."The IMPOSSIBLE is often UNTRIED"
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
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)