Showing posts with label quotcreate. Show all posts
Showing posts with label quotcreate. Show all posts

Wednesday, March 21, 2012

CREATE SCHEMA fails Inside an If Block

Hello All,

The below "CREATE SCHEMA" sql statement fails if it is inside an IF block. It runs fine if i run it without the IF block...

IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = N'Customer')

BEGIN

CREATE SCHEMA Customer AUTHORIZATION [sys]

END

-

Did anyone encountered this issue before....

Thanks..

Make this as dynamic SQL.|||

Thanks, Bushan.

As the DDL scripts can grow bigger, I feel that it is hard to maintain dynamic sql. But, I was just trying to figure out why this is not possible in this "create schema" scenario alone. It even works for "drop schema".

|||

Like the error message you get back says, CREATE SCHEMA must be the first command in the batch. So to do a CREATE SCHEMA in a script like this, that one statement has to be done dynamically.

IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = N'Customer')
BEGIN
exec ('CREATE SCHEMA Customer AUTHORIZATION [sys]')
END
Annoying? Yes? But it is not that much more work than doing it in the way that you (and I) originally expected :)

|||This is such an OBVIOUS shortcoming of TransactSQL. Why hasn't Microsoft corrected this flaw. As far as I know (with the exception of entering the exec ('sneak the CREATE in as a text string') there is no way to conditionally create a SCHEMA or a FUNCTION for that matter.

If it's disallowed for security reasons then why can we sneak it in with an EXEC?

The problem this causes for me (over and over again) is I write a sample function for the user and include it in my upgrade script. If they've already run the script for an earlier version, they already have my example and may have customized it to their specific application. If they have, I don't really want to replace it with my example again. So I'm stuck sneaking it in through the string route. This has been a flaw in T-SQL for a long time....

Sorry for the rant... Sure wish the T-SQL gods were listening |||
Thanks for the clarification..

Wednesday, March 7, 2012

create local .CUB File in AS2005

Hi,

we have a problem with the "CREATE GLOBAL CUBE" function in AS2005:

While accessing the local .CUB file (created with "CREATE GLOBAL CUBE"), our application only shows key-values for some dimensions instead of their names.
If we use the same statement in AS2000 to create the .CUB, everything is displayed correctly;
as well if the application directly connects to the DB (AS2000 & AS2005).

We used the Profiler to take a look at the traces and found something in the SELECT that is used to fill the new cube after creation:
every dimension is bracketed with "KEY()"
We tested the statement and replaced the "KEY()" with "NAME()" and it looks like this would bring the correct data.

But how do we tell the AS2005 to use NAME() instead of KEY() while compiling the "CREATE GLOBAL CUBE" statement?

Or is there annother way to create the local .CUB file?
We are able to create a cube via xmla ... but how do we write it to a local file?

Thanks for your answers and for tolerating my bad english
best regards,
Sven

I don't know what you mean by the statement "Our application only shows key-values". If you mean your application only displays dimension member keys instead of dimension member names, then, this is a bug that is being fixed in the SP2 release.

You can capture the local cube statement, modify it suitably and send it via MDX Client.

create local .CUB File in AS2005

Hi,

we have a problem with the "CREATE GLOBAL CUBE" function in AS2005:

While accessing the local .CUB file (created with "CREATE GLOBAL CUBE"), our application only shows key-values for some dimensions instead of their names.
If we use the same statement in AS2000 to create the .CUB, everything is displayed correctly;
as well if the application directly connects to the DB (AS2000 & AS2005).

We used the Profiler to take a look at the traces and found something in the SELECT that is used to fill the new cube after creation:
every dimension is bracketed with "KEY()"
We tested the statement and replaced the "KEY()" with "NAME()" and it looks like this would bring the correct data.

But how do we tell the AS2005 to use NAME() instead of KEY() while compiling the "CREATE GLOBAL CUBE" statement?

Or is there annother way to create the local .CUB file?
We are able to create a cube via xmla ... but how do we write it to a local file?

Thanks for your answers and for tolerating my bad english
best regards,
Sven

I don't know what you mean by the statement "Our application only shows key-values". If you mean your application only displays dimension member keys instead of dimension member names, then, this is a bug that is being fixed in the SP2 release.

You can capture the local cube statement, modify it suitably and send it via MDX Client.

Tuesday, February 14, 2012

Create database

Hi!

Is it possible to set the database owner using the "create database" command?

Thank you!

Hi Ana,

No, the CREATE DATABASE statement does not have a "owner = <name>" clause. The owner is the user that creates the database. The database owner can be changed by using sp_changedbowner. See this Books Online topic for details: http://msdn2.microsoft.com/en-us/library/ms178630.aspx.

Regards,

Gail

|||Thank you!