locked
How can i select from sys.databases and compare the name returned ? RRS feed

  • Question

  • User1253338400 posted

    Hi ,

    I have a db I can see in SSMS named MyTestDB. The server is Case Sensitive with collation SQL_Latin1_General_CP1_CS_AS

    i am wanting to see if a db exists . I do the following 

    SELECT name from sys.databases WHERE name = 'MYTESTDB', notice the upper case.

    If it were a Case Insensitive DB it would return one row. 

    How can i do the select to return one row in a case sensitive db ?

    thanks

    Tuesday, September 22, 2020 5:05 AM

Answers

  • User-939850651 posted

    Hi robby32,

    According to your description, I built a database for testing and tried your query statement. I found that the collation has no substantial effect on this statement.

    You need to specify the collation in the conditional statement.

    Just like this:

    select name from sys.databases where name='databaseName' COLLATE SQL_Latin1_General_CP1_CS_AS

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 23, 2020 10:16 AM