perl,mysql table name limit? - mysql

i am interacting with the mysql database via perl. I was wondering if there are table name limits.
Also. How do i handle special characters within the table names when creating it through perl?
thanks

According to the MySQL docs, the maximum length for a table name is 64 characters. This page also describes the permissible syntax for identifiers.

Related

Using special characters in mysql table or column name

I have seen other questions related to using special characters in column name but I didn't get my point. I want to use column name like
`first_name#abc|xyz|exy#`
Is it legal does it cause any security issue or any error while querying them?
MySQL 5.7 sets the encoding of the column names to utf-8 by default.
If you want to see the configuration in your system, execute the following command:
SHOW VARIABLES LIKE 'character_set_results';
Source: https://dev.mysql.com/doc/refman/5.7/en/charset-metadata.html

How to create multilingual Unicode text attributes in SQL?

I have a database and the requirement is to store the data in the columns that can:
hold fixed-length Unicode characters like Japanese, Chinese, French, Arabic and so on characters.
The data stored in a column is Unicode or multilingual and is of variable length.
In my suggestions, the Data Types are NCHAR, NVARCHAR, CHAR and VARCHAR etc...
But please tell me how what are the SQL queries to create these columns with the above-mentioned constraints.
The user requirements are to speed up the data retreival process. Also if to save hard disk.
Depending on your DBMS, you can create your database defining what would be the character encoding (normally, UTF-8 would do). Once the database was create with that encoding, you can insert text in any language. Take into account that the actual number of characters that you will be able to store within a table column will normally be less that what you defined as string length. For instance, if you create the column as varchar(1000), you will NOT be able to store 1000 character in all cases.
Check your specific DBMS documentation on how to configure UTF-8 encoding.

workaround: make mysql column name longer than 64 chars

I am working on an application to dynamically generate mysql tables from Excel files.
Current I am stuck because some of the column names in the Excel files have more than 64 characters, while in mysql the maximum length for column names are 64 characters.
I thought about setting up another table to store the column names but then I will have to perform some joint operation to retrieve them.
Is there any clever way to workaround this problem?
MySQL is an open source project. You can download the source code, change things, and build your own version.
I haven't read MySQL source, but the odds are good that the maximum length of identifiers is a compile-time constant. It might be as simple as finding that constant, changing it, and recompiling. (Simple doesn't necessarily mean easy, though.)
It really is pretty easy in PostgreSQL. The PostgreSQL docs even tell you the name of the constant, and which file it's in. (NAMEDATALEN, in src/include/pg_config_manual.h)
Personally, I think you're better off fixing the Excel column names to conform to MySQL limits.
There is no other way to increase the length of the column size more than 64. here are some standards. you cant go beyond this limit.
Identifier Maximum Length (characters)
Database 64
Table 64
Column 64
Index 64
Constraint 64
Stored Program 64
View 64
Alias 256
Compound Statement Label 16
And you cant retrive the column names through join operation. through join operation you can only achieve data of 2 or more tables. the solutio to your problem is that you should truncate the column names in excel already before exporting them to mysql.

How to display special characters in SQL server 2008?

I am using SQL server 2008 and have the column in my table set to nvarchar. Data with special characters are getting stored wrongly in this table. Eg: this is one entry
Need to check if doesn’t comes as doesn’t itself and don’t comes asdon’t itself and ensure closure of issues.
The garbage ’ should actually be an apostrophe ('). I have checked my collation string. At database level it is SQL_Latin1_General_CP850_BIN2 and at server level it is SQL_Latin1_General_CP1_CI_AS.
I know for sure the encoding set everywhere else in my application is UTF-8.
How do I store the data correctly in my table? Do I need to change my SQL queries or any settings in the database?
Please advise.
You need to make sure that you're observing two things:
Always use NVARCHAR as datatype for your columns
Always make sure to use the N'....' prefix when dealing with string literals (for example in your INSERT or UPDATE statements)
With those two things in place, SQL Server has no trouble at all storing all Unicode characters you might throw at it...

Mysql Database Name Restrictions

I am building a system where while the admin is installing it, one of the steps is to create a database (from the system). So my question is, how should I validate the database name? I found it can't be longer than 64 chars but is this the only restriction? I tested some db names with special characters in phpmyadmin which didn't give an error.
MySQL database naming restrictions:
Cannot be longer than 64 characters.
Cannot contain / \ or . characters.
Cannot contain characters that are not permitted in file names.
Cannot end with space characters.
More information here.
The Regex for this:
^[^\\/?%*:|\"<>.]{1,64}$