2012年2月25日星期六

Any limit of the length of the characters in table name ?

Hi,
We are a team that are developing a projet which has in itself a good number
of tables in sql server (not temporary ones !). The entire team is pretty
knowledgeable in MSSQL server and in SQL programming in general... However
we kind of want to double check what are the limitations of naming tables
(not temporary ones ! "#"). ?
e.g
1. Any limit of the length of the characters in table name ?
2. Any special characters which are not allowed or is not advised to be in a
table name ?
3. or any other constrains or limitations I can't think of now.
Thank you very much in advance,
G.Y
Software Engineer,
QuadraMed, Reston VA> 1. Any limit of the length of the characters in table name ?
They are stored using SYSNAME datatype, which is NVARCHAR(128).
DECLARE @.s VARCHAR(255)
SET @.s = 'CREATE TABLE '+REPLICATE('x', 129)+' (i INT)'
EXEC(@.s)
Yields:
Server: Msg 103, Level 15, State 7, Line 1
The identifier that starts with 'xxxxxxxxxxxxxxxxxxxxxx[...]' is too long.
Maximum length is 128.
> 2. Any special characters which are not allowed or is not advised to be in
> a table name ?
Spaces. Punctuation. Accent characters. Do not start a table name with a
number or a dash. Underscores are the only non-alphanumeric that I allow,
only if deemed absolutely necessary by someone else
(ThisCaseWorksFineForMe), and only if they are at a logical place (not at
the beginning). In fact even numbers are questionable, but it really
depends on the entity you are trying to model.
Here are my thoughts on SQL Server naming conventions, maybe useful to you,
maybe not:
http://www.aspfaq.com/2538
> 3. or any other constrains or limitations I can't think of now.
http://www.aspfaq.com/2345

没有评论:

发表评论