Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using MyLittleAdmin to manage a SQL Server database in the cloud.
By mistake I have generated a field whose name was enclosed in brackets in a table
For example It looks in the table like this.

ValorComision (money, not null)
Atraso (int, null)
[PagosExtra] (money, null)

the problem is that it is impossible for me to work with that field.
If I would like to do a simple search for example.

SELECT [PagosExtra] FROM IG_COBRO_ALQUILERES
Msg 207, Level 16, State 1, Line number 1
Invalid column name 'PagosExtra'.

What I have tried:

How could i change the name to the field or delete it to replace it and skip the problem?
Posted
Updated 20-Sep-18 21:38pm
Comments
MadMyche 20-Sep-18 11:37am    
Have you tried renaming the column?
Member 13991876 20-Sep-18 12:03pm    
Thanks, has worked

Start by finding out how SQL thinks it's named: I use SSMS, bit I'm sure MyLittleAdmin will have something similar.
In SSMS you can right click the table name and use "Script table as ... new query window" - that will give you the "sql name" for the column. It's probably [[PagosExtra]]]
When you have that, feed it into this:
EXEC sp_Rename 'MyTable.[[PagosExtra]]]', 'PagosExtra' , 'COLUMN'
and execute it.
You'll probably get a warning that it might break scripts, but it should be a "normal" name now.
 
Share this answer
 
Comments
Maciej Los 21-Sep-18 3:25am    
5ed!
Another idea is to change field/column name and remove unnecessary square brackets.

Note: i know nothing about MyLittleAdmin, but in MS SQL Management Studio you can always use alter table command[^] to modify column name[^]. I believe that logic is the same.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900