I would like to add a field with:
ALTER TABLE Table_name ADD COLUMN ABCD012345(en) Memo;
Here is described what to do in that case:
To work arond this problem, do not use special characters. If you must use special characters in query expressions, enclose the special characters in brackets ([]). For example, if you want to use the greater than sign (>), use [>].
As I understand it I would Need to Change it to:
ALTER TABLE Table_name ADD COLUMN ABCD012345[(]en[)] Memo;
But this still leads to the same error: Syntax error in field Definition. If you Need a little more context: I do this with a ADODB.Recordset in a VBA macro.
Where do I go wrong? How can I solve it?
You need to surround the entire name with brackets, not just the special characters:
ALTER TABLE Table_name ADD COLUMN [ABCD012345(en)] Memo;
-- Here --------------------------^--------------^
Related
Is there any way I can create a mixed case table name in Oracle without using quotes?
The table names change to uppercase if I do not use quotes while creating the table.
Let me know if you need more information.
Eg:
create table testTable(testColumn varchar);
This creates a table named TESTTABLE with column name TESTCOLUMN.
I can use quotes, but it makes it more messy and difficult to write queries.
Can you please let me know how I can do this without using quotes? Thanks.
Regards,
Sawan
Please refer to the official Oracle Database documentation:
"Nonquoted identifiers are not case sensitive. Oracle interprets them as uppercase."
https://docs.oracle.com/en/database/oracle/oracle-database/20/sqlrf/Database-Object-Names-and-Qualifiers.html#GUID-3C59E44A-5140-4BCA-B9E1-3039C8050C49
All the data dictionary views will show the identifiers as Oracle interprets them. In other words, without quotes everything will be uppercase. I can testify that this is true even for accented characters.
You can't always get what you want...
I am trying to find an easy way to remove columns/fields from an existing QGIS Spatialite database file. I am new to both Spatialite GUI and SQL, but I want to get the said job done. I right-clicked on a layer (for-China) and chose 'Show columns' from the context menu. Then I got an error message:
SQL error: "near "-": syntax error"
so I tried executing the statement:
PRAGMA table_info('for-China');
alter table 'for-China'
delete row 'note';
and the table showed up, but the NOTE row wasn't deleted:
I tried using COLUMN instead of ROW and also tried using DROP instead of DELETE but NOTE is still left untouched. I am confused on what to do to delete the NOTE row.
I assume that spatialite uses the same escape characters as SQLite. Hence, try double quotes:
PRAGMA table_info("for-China");
alter table "for-China" drop column note;
You should only need this for identifiers that are keywords or use characters other than alpha numeric, underscore (and perhaps a few others).
SQLite also recognizes backticks and square braces, as explained in the documentation.
I was trying to use sqlFetch. The fetch works perfectly when I change the name of my table to have underlines instead of periods. So if I use the command
sqlFetch(conn, "HelloWorld_40")
It works fine. Unfortunately, my friends are all using the real name of the table
sqlFetch(conn, "HelloWorld.40")
But then it crashes and it tells me that
Error in sqlColumns(conn, "HelloWorld.40") :
'HelloWorld.40': table not found on channel
I'm guessing the period "." is illegal name for a table. But I don't want my friends to change it because it's a lot of people who would be affected. Is there a way I can call the table, or do I have to secretly go to their database, change the name while I use it and then change it back to a period (risking that I will forget, someone will read, blah blah).
Thanks.
put the table name in square brackets:
[HelloWorld.40]
It is a problem with sqlFetch which parse table name. Unfortunately it did not handle table quotes, so it's search for table 40 in schema HelloWorld. You need to directly call sqlQuery (with quoted table name, brackets for MS SQL Server):
sqlQuery(dbhandle, "SELECT * FROM [HelloWorld.40]")
Side note: you should specify which database you are using.
The best delimiter is double quotes -- that should work in most underlying databases:
"HelloWorld.40"
In MySQL, you can also use back ticks (`):
`HelloWorld.40`
In SQL Server, Access, and I think Sybase, you can also use square braces:
[HelloWorld.40]
I have a table in my database of type nvarchar(50);
I want to write to that specific column that string 'Tal' - Tal between 2 apostrophes.
When I'm trying to do so what is recorded in my DB is "Tal" - Tal between 2 quotation marks.
My database is an SQL database and so are my scripts.
How this can be solved?
The standard way to do what you want is this.
insert into mytable ( mycolumn ) values ('''Tal''');
The first and last ' are the start and end markers for the string. Each '' within these characters means '. Refer to page 89 of the SQL 92 specification at http://www.andrew.cmu.edu/user/shadow/sql/sql1992.txt
I think escaping is the key to your question. For SQL apostrophes are special characters, thus they have to be escaped by '' (two apostrophes). Have you checked that your scripts do not add the second apostrophe for you? Probably you have to add Tal without the apostrophes.
Escape % seems to be DB dependant. Oracles uses \%, others accespt [%] and some seem to have a keyword ESCAPE. You have read the documentation of your database, look for "escape characters".
Try inserting like this using the backslash \'Tal\'.
I have created a table with some columns using PL/SQL Develper to access this Oracle database.
After clicking the "Apply" button that will create the table, all my column names suddenly become upper case (which can hardly be read), including the table name!
Would that be possible to configure PL/SQL Developer IDE to leave the columns names and table names as they are?!
Oracle DBMS ignores case and translates everything to uppercase unless you use quotes. But the quotes have the liability that you always have to use them.
If you do not use the quotes you will get an error message ORA-00942: table or view does not exist
You can give column name in double quote "". Then those column name will be in as it is.