I'm creating procedure, but SQL Developer throws a weird error. I make a screenshot.
Table columns have names with small letters. I wrote small letters! But SQL Developer say, that I wrote big letters and big letters of course doesn't match real column names...
Sorry for my English, I hope you will understand.
If you are absolutely sure that you did create the column names with "ID_pr" style, then when querying, you will need to query them with the quotes.
SELECT "PRACOVNIK"."ID_pr" ..
like so.
Example of a SQLFiddle which demonstrates this: http://sqlfiddle.com/#!4/93b49/5
Related
To start off with, I have looked into this issue and gone through quite a few suggestions here on SO, but many leave me in doubt whether they are good performance-wise.
So to my problem:
I have a table with usernames and want to provide users the possibility to search for others by their name. As these names are taken from Steam though, the names not containing some form of special character are in the minority.
The easiest solution would be to use LIKE name%, but with the table size constantly increasing, I don't see this as the best solution, even though it may be the only one.
I tried using a fulltext search, but the many special characters crushed that idea.
Any other solutions or am I stuck with LIKE?
Current table rows: 120k+
Well I don't believe that string-functions are faster, but contemporary I don't got any big database for testing performance. Let's give it a try:
WHERE substr(name, 1, CHAR_LENGTH('ste')) = 'ste'
I would like to suggest one solution which I applied before.
First of all, I clean all special characters from the string in name column.
Then I store cleaned string in another column (called cleaned_name) and index (fulltext search) this column instead of the original column.
Finally, I used the same function in step 1 to clean the queried name before executing a fulltext search on cleaned_name.
I hope that this solution is suitable for you.
Does width of a column name really matter when I do select or insert or when I run stored procedure? Any performance implications with respect to column name width.
I guess the answer is No. But I still want to get more insights to it.
May be different databases internally refer sql table column names differently. The answer which is true for MS Sql Server may not hold true for Oracle?
For SQL Server, I'm going to say "no". The name is just a reference into the metadata for the table that says what the column position and data type are. I'd venture to say it's the same for mySQL as well, but that's purely speculative.
That said, there's a saying in software in general that goes something like "imagine that the person who has to maintain your code is a homicidal maniac". So feel free to push the limits of the size of the column name. But keep that saying in mind. :)
We have a legacy schema file which has the following column names, would like to understand if any of them would cause an issue if we port our application to h2, mysql, postgres or oracle.
e.g how would I know if using this would be ok across the databases listed below. Are there any good tools which can do a preliminary check on this?
key
when
size
type
count
from
with
Should be quite easy to get the list of reserved words and build a table of the reserved words. Here are some lists of reserved words:
Oracle: http://download.oracle.com/docs/cd/B19306_01/em.102/b40103/app_oracle_reserved_words.htm
SQL Server:
http://msdn.microsoft.com/en-us/library/ms189822.aspx
PostgreSQL:
http://www.postgresql.org/docs/current/static/sql-keywords-appendix.html
MySQL:
https://dev.mysql.com/doc/refman/5.6/en/keywords.html#keywords-in-current-series
And here's an online checker: http://www.petefreitag.com/tools/sql_reserved_words_checker/?word=on
I am not aware of any tables but it should not be difficult to filter them if you have the list of table names and column names.
Oracle has a V$RESERVED_WORDS view in its data dictionary.
All you have to do is to match your table/column names against this: Just add them to temp table and join with tis view. If you have a result for your query then you have a reserved word.
Other databases may have such metadata as well.
DatabaseMetaData.getSQLKeywords() is supposed to return a comma-separated list of reserved words within this database. This list doesn't contain ANSI SQL keywords such as FROM however. I'm not completely sure if this really contains all keywords in all databases however.
For H2, the list of keywords is documented under Keywords / Reserved Words.
The easiest way to find out would be to try it. All of the database management systems you mention are open source or free to download and try. Run your SQL script with the CREATE TABLE statements through them and see what happens.
The problem with asking this without reference to an actual SQL script is that some parsers have various classes of reserved words. Some key words might be listed as key words, but might still be OK to use as column names, but perhaps not in tricky SELECT statement later on. So it's always best to try it out.
I suggest based on the list you give, it won't work in most SQL systems. But you can always consistently double quote the identifiers to steer clear of key word problems. (You will need to run MySQL in ANSI mode, though.)
In MySQL, is it necessary to surround tablenames with the tickmark? I've often seen code snippets that use the tickmarks, but I've not encountered a case where not surrounding a tablename with the tickmarks does anything different than with.
It looks like the framework I work with automatically parses reserved word keynames with tickmarks.
The tickmarks are there to distinguish the table (or column!) names from SQL reserved words. For example, without the tickmarks, a table or column named update could clash with the SQL command update.
It's best practice not to name tables and columns with reserved words in the first place, of course, but if you port an application to a new database engine (or possibly even a new MySQL version), it might have a different set of reserved words, so you may have just broken your app anyway. The tickmarks are your insurance against this sort of oops.
Tickmarks are necessary when table or column names use mySQL keywords.
I once worked at a job where they had a database of "locations". They called it states. and had everything in tables each table was named by state code. so Missouri was MO, and Arkansas was AR.
Several state codes are also reserve words OR ( Oregon), and IN (Indiana), and ON (Ontario) ... I know not exactly a state.
Even tho I think there were better ways of organizing their database data, there are cases where people want to name things a reserved word. This is an example where the `` marks kept code working.
It's only necessary if your table name is composed of non-"word" characters (ie: anything besides letters, numbers, and underscores), or happens to be the same as a keyword in MySQL. It's never "bad" to quote the name, but it's bad not to when you have to, so many programs that generate MySQL queries will be conservative and quote the name -- it's just easier that way.
I have the following problem (using mysql 5.0.70).
In one table I have a varchar field containing some kind of a number, like:
"0303A342", "21534463", "35663CE3"
etc. Collation is set to utf8_general_ci.
The problem shows up when a user of the system is trying to search for a record containing part of this number. SQL query looks like
...
WHERE 'number' LIKE '%0303A%'
Now if the 'A' in the LIKE part is entered as a Latin A, the result contains only records with Latin A's in them -- as it should. And when the A is Cyrillic, the results are again only those rows containing the Cyrillic A. There are many other letters like E, C, B, T and so on.
Now my question is, if there is a way to modify my sql query so it returns all rows matching the LIKE '%0303A%' part but for all kind of A`s in there? Or I should convert the user input before inserting/updating the database?
You should convert the user input, there is no function LOOKS LIKE in MySQL :)
You can store the transliterated string along with the original one and use php::translit to do this:
id data trans_data
1 Москва MOSKVA
2 София SOFIA
SELECT *
FROM table
WHERE trans_data LIKE CONCAT('%', ?, '%')
mysqli->bind_param('s', strtoupper(transliterate('Москва')));
The fact that some letters look alike in several alphabets does not make them identical. In fact their looking alike might even depend on the font used to display them.
Your example data looks like hexadecimal values. Without knowing more about the context of your problem, might it be possible to have the user enter the data in decimal format (just using digits)? Another possibility might be a custom control to enter the search criteria. Does it have to be free text or would maybe a listbox with several options suffice?
If not, you might find functions similar to what Quassnoi describes (transliterate()) in the language or library you are using. With plain MySQL you are probably out of luck. And even if you find some function that does what you want, make sure it supports all the languages/alphabets your users are going to use - I for one would not know how many alphabets there are that have 1:1 mappings of their characters to the latin ones.
I can't use the php translit - the data I'm dealing with (the 'numbers' as I call them) are some kind of an identifiers, so it doesn't make sense to search for "IA" if somebody enters "Я".
Because I know my users will use only Latin and Cyrillic characters, what I'm going to do is make a list of the common letters in the two alphabets and convert user input before reaching the db. Kind of sucks but seems the most appropriate solution.