Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:

sql2008 How to connect db in sql2008 without []

I have a db name satu-My-2030, when I try with T-sql

Use satu-My-2030 - It wont works Instead I must using

Use [satu-My-2030] It works, but how do I avoid from using []??
0
motioneye
Asked:
motioneye
  • 3
4 Solutions
 
Lee SavidgeCommented:
Is there any reason you have to avoid using []?
0
 
Lee SavidgeCommented:
You may need to read this about database identifiers:

http://msdn.microsoft.com/en-us/library/ms175874.aspx
0
 
Lee SavidgeCommented:
Specifically this line is pertinent to you:

When identifiers are used in Transact-SQL statements, the identifiers that do not comply with these rules must be delimited by double quotation marks or brackets.

A hypen does not comply with the rules so you must delimit them.
0
 
Deepak ChauhanSQL Server DBACommented:
Brackets are required if your table name, database name, linked server name ,  column names: or any object name in sql server

1 Contain special character or arithmetic operator in database name , linked servername or server name .
2 contain a space: SELECT [column name] FROM table;
3 contain a bracket: SELECT [wt[f], or SELECT [wt]]f]
4 contain a non-alphanumeric symbol like ^ or ! (yes, they can contain those symbols!)
  are reserved keywords like KEY, STATE, RULE, ...

These all are rules of sql server.
0
 
tliottaCommented:
Use [satu-My-2030] It works, but how do I avoid from using []?

In short, rename it so that the name follows the rules. For example, you might rename it to satuMy2030.

That will help avoid needing brackets.

Tom
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now