Click here to Skip to main content
14,111,188 members
Rate this:
 
Please Sign up or sign in to vote.
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
   
Comments
Maciej Los 21-Sep-18 3:25am
   
5ed!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
   

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web05 | 2.8.190518.1 | Last Updated 21 Sep 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100