1

On SQL SERVER:

I have a schema on my database created using command:

CREATE SCHEMA my-schema AUTHORIZATION [G_USER]

When I try search for the schema using the following statement I do not get any result.

SELECT * FROM sys.schemas WHERE name=N'my-schema'

However when I try SELECT * FROM sys.schemas I get a whole bunch of other schemas but not the my-schema which I created on the database.

Am I doing something wrong? Any Help will be greatly appreciated.
Thanks!

aruuuuu
  • 1,605
  • 2
  • 22
  • 32

1 Answers1

2

Here is my syntax (from the personal code-snipplets vault)

if not exists(select 1 from information_schema.schemata where schema_name='my-schema')
BEGIN
    print 'Creating the schema : [my-schema]' 
    EXEC ('CREATE SCHEMA [my-schema] AUTHORIZATION dbo;')
END


if exists(select 1 from information_schema.schemata where schema_name='my-schema')
BEGIN
print 'Schema Exists : [my-schema]' 
END

(My personal code below, just in case)

if not exists(select 1 from information_schema.schemata where schema_name='LookupSchema')
BEGIN
    EXEC ('CREATE SCHEMA LookupSchema AUTHORIZATION dbo;')
END

GO
granadaCoder
  • 26,328
  • 10
  • 113
  • 146