Showing posts with label via. Show all posts
Showing posts with label via. Show all posts

Monday, March 19, 2012

How to tailor CREATE DATABASE for an arbitrary instance

Suppose the following:

    As part of a product install (using InstallShield)...

    I create a SQL Server Express instance (say "X") via a silent install

    I supply a script to create a database in instance X.

The idea, of course, is to have a fully automated install. But there's one problem I can't quite see how to work around:

- the CREATE DATABASE statement needs the name of a file to contain the database, and that file needs to be in a folder that belongs to the instance (e.g. Microsoft SQL Server\MSSQL.1, Microsoft SQL Server\MSSQL.2, etc).

Is there a syntactic variant that allows me to avoid this problem?

Thanks
Josh

hi,

don't know if this can be a solution to your problem, but in the CREATE DATABASE syntax only the database name is mandatory.. http://msdn2.microsoft.com/en-us/library/ms176061.aspx

if you only specify

CREATE DATABASE myDb;

the "myDb" name will be used for physical files naming, resulting in a "myDb.Mdf" and "myDb_log.Ldf" files, stored in the folder hosting all other databases..

the new "myDb" will inherits all settings applied to "model" database, both regarding database settings as physical settings as well (size, growth, etc)...

but you loose control over the physical and logical name specification, and, of course, you can this way no longer specify size, growth, max size, ...

regards

|||

Andrea:

Between then and now, I found what I needed in one of your posts from yesterday.

With very minor adaptation, I arrived at the following (which worked like a charm):

DECLARE @.itemp VARCHAR(255);
DECLARE @.RegKey VARCHAR(255);
DECLARE @.instance VARCHAR(255);
DECLARE @.subfolder VARCHAR(255);
DECLARE @.rootfolder VARCHAR(255);
DECLARE @.DBFileName VARCHAR(255);
DECLARE @.DBLogName VARCHAR(255);
DECLARE @.CreateDB VARCHAR(MAX);

SELECT @.itemp = CONVERT(varchar, SERVERPROPERTY('InstanceName'));
IF @.itemp IS NULL
SET @.instance = 'MSSQLServer';
ELSE
SET @.instance = @.itemp;

EXEC master..xp_regread @.rootkey='HKEY_LOCAL_MACHINE',
@.key = 'SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL\',
@.value_name = @.instance,
@.value = @.subfolder OUTPUT;

SET @.RegKey = 'SOFTWARE\Microsoft\Microsoft SQL Server\' + @.subfolder + '\Setup';

EXEC master..xp_regread @.rootkey='HKEY_LOCAL_MACHINE',
@.key = @.RegKey,
@.value_name = 'SQLDataRoot',
@.value = @.rootfolder OUTPUT;

SET @.DBFileName = @.rootfolder + '\DATA\' + 'MyDatabase.mdf';
SET @.DBLogName = @.rootfolder + '\DATA\' + 'MyDatabase_log.mdf';

-- Create the database

SET @.CreateDB = 'CREATE DATABASE [OTHGMD] ON PRIMARY
(NAME = ''MYDATABASE'', FILENAME = ''' +
@.DBFileName + ''', SIZE = 51200KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB) ' +
'LOG ON (NAME = N''MYDATABASE_log'', FILENAME = ''' +
@.DBLogName + ''', SIZE = 5120KB , MAXSIZE = 2048GB , FILEGROWTH = 10%) ' +
'COLLATE SQL_Latin1_General_CP1_CI_AS;'

EXEC (@.CreateDB);
GO

Thanks Very Much
Josh

p.s. A pox on the SQL Syntax committee for making us have to do this. Can you think of a good reason why the file name can't be a variable?

|||

hi,

usually referenced objects are to be considered constants or literals... only parameters can (and should be) variable

as you surely know, you are executing dynamic SQL, composed on the fly and executed... SQL Server takes even care of that as it can, somehow and sometime, avoid recompilation of some dynamic statements, but that' all... just a "limitation" of current implementation of DBMS engines, and, as per the CREATE DATABASE statement, this regards SQL Server "only" as each different vendor provides it's own "syntax" to generate new catalogues and database... it's not that standard... AFAIK the ANSI standard starts with the SCHEMA, and, for the ANSI commetee, there's no part for "variables", as all must be resolved in "literals"... it is the compilation phase, in SQL Server as in other engines, that pepare the final statement, replacing variables with literals (where allowed by the host language/tool/engine) and finally passes the "final" result as output to the compiling phase.. tokenizer, algebrizer and other technologies come then into play.. but this is another story

regards

how to syncronize record via ftp?

CIAO all people...!
Ihave 1 database di access 2000 built on 20 table...query and form,
users insert record easy from form.
I have Microsoft SQL Server Service Manager 7.00.623.
I have the same database in web space ...ex ...(ad esempio
ftp.tiscali.it/azienda/db/data.mdb)
how to syncronize record?
the all database is 60 mb
Access replica is ok for localhost or for a pc in lan...is not ok for
FTP...
Replica snapshot di SQL (with server distributore etc etc) is ok only for
SQL database but i have access...
Is this an Access question?
If so, please post it to microsoft.public.access.replication
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"miikii" <m_piccSPAM@.DELCAKKIOhotmail.com> wrote in message
news:42144f3e$0$6316$5fc30a8@.news.tiscali.it...
> CIAO all people...!
> Ihave 1 database di access 2000 built on 20 table...query and form,
> users insert record easy from form.
> I have Microsoft SQL Server Service Manager 7.00.623.
> I have the same database in web space ...ex ...(ad esempio
> ftp.tiscali.it/azienda/db/data.mdb)
> how to syncronize record?
> the all database is 60 mb
>
> Access replica is ok for localhost or for a pc in lan...is not ok for
> FTP...
> Replica snapshot di SQL (with server distributore etc etc) is ok only for
> SQL database but i have access...
>
>

Wednesday, March 7, 2012

How to stored a stored procedures results into a table

Hi, How can I store a stored procedure's results(returning dataset) into
a table?

Bob

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!"Bob James" <BJ@.system.com> wrote in message news:41ed4eb1$1_2@.127.0.0.1...
> Hi, How can I store a stored procedure's results(returning dataset) into
> a table?
> Bob
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

insert into dbo.MyTable
exec dbo.MyProc @.parm1 = 'foo'

Where dbo.MyTable already exists and matches the structure (columns and data
types) of the procedure's result set. But there are a number of issues with
this approach:

http://www.sommarskog.se/share_data.html#INSERTEXEC

If you read the whole article you might find one of the other approaches
suits your needs better anyway, so you can avoid those issues.

Simon

Sunday, February 19, 2012

How to stop mssql

Hi.
I need to stop mssql service via command row.
How can I do?
Tnk,
Luca"Luca" <NOSPAMprong2k@.hotmail.com> wrote in message
news:chpn2i$rk7$1@.atlantis.cu.mi.it...
> Hi.
> I need to stop mssql service via command row.

net stop mssqlserver

or net stop mssqlserver /y

That will also stop the SQL Server agent w/o prompting.

(net stop sqlserveragent stops the agent.)

> How can I do?
> Tnk,
> Luca

how to stop executing a script

a setup process executes a script via osql. I want to parameterize
it in such a way that whenever wanted the script will do nothing.
For that I plan to created a table in master database, say
NODROP_DATABASE
the first few lines of the script will be
IF EXISTS (SELECT * FROM master.dbo.sysobjects where name =
'NODROP_DATABASE'
and type = 'U')
BEGIN
return
END
-- rest of the script here with many GO in between.
what is happening is that the return statement takes the control to the
first line after GO. The execution continues from the first GO after
that.
Is there any other approach to stop executing.
Assuming the script is run by a SYSADMIN you can RAISERROR with a severity
of 20 or greater to terminate the current connection.
Alternatively, run the script from OSQL with the -b option and it will
terminate on the first error.
David Portas
SQL Server MVP
|||... or, if using OSQL, issue a RAISERROR with state 127. OSQL will stop on errors with state 127.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:peKdnWO5478MiE3fRVn-vw@.giganews.com...
> Assuming the script is run by a SYSADMIN you can RAISERROR with a severity of 20 or greater to
> terminate the current connection.
> Alternatively, run the script from OSQL with the -b option and it will terminate on the first
> error.
> --
> David Portas
> SQL Server MVP
> --
>
|||Tibor Karaszi wrote:

> ... or, if using OSQL, issue a RAISERROR with state 127. OSQL will stop on errors with state 127.
David and Tibor,
Raising error with RAISEERROR means abnormal termination. The problem
with
that approach is that setup has to be programmed to ignore 127. I want
a graceful exit from running the script as if the script ran
successfully.
|||Why not just add the conditional test in your calling code and decide
at that point whether or not to execute the script. I can't think of a
better way.
David Portas
SQL Server MVP
|||Hi,
You could try to use labels.
IF (1 = 1)
GOTO QUIT
PRINT 'Not executing code'
QUIT:
PRINT 'Quit'
Ramon @. Havana Club,
SQL Server MCDBBA
"Data Cruncher" <dcruncher4@.netscape.net> ??/?? ? ??
??: news:1121093312.487489.156320@.z14g2000cwz.googlegr oups.com...[vbcol=seagreen]
> Tibor Karaszi wrote:
on errors with state 127.
> David and Tibor,
> Raising error with RAISEERROR means abnormal termination. The problem
> with
> that approach is that setup has to be programmed to ignore 127. I want
> a graceful exit from running the script as if the script ran
> successfully.
>

how to stop executing a script

a setup process executes a script via osql. I want to parameterize
it in such a way that whenever wanted the script will do nothing.
For that I plan to created a table in master database, say
NODROP_DATABASE
the first few lines of the script will be
IF EXISTS (SELECT * FROM master.dbo.sysobjects where name =
'NODROP_DATABASE'
and type = 'U')
BEGIN
return
END
-- rest of the script here with many GO in between.
what is happening is that the return statement takes the control to the
first line after GO. The execution continues from the first GO after
that.
Is there any other approach to stop executing.Assuming the script is run by a SYSADMIN you can RAISERROR with a severity
of 20 or greater to terminate the current connection.
Alternatively, run the script from OSQL with the -b option and it will
terminate on the first error.
David Portas
SQL Server MVP
--|||... or, if using OSQL, issue a RAISERROR with state 127. OSQL will stop on
errors with state 127.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:peKdnWO5478MiE3fRVn-vw@.giganews.com...
> Assuming the script is run by a SYSADMIN you can RAISERROR with a severity
of 20 or greater to
> terminate the current connection.
> Alternatively, run the script from OSQL with the -b option and it will ter
minate on the first
> error.
> --
> David Portas
> SQL Server MVP
> --
>|||Tibor Karaszi wrote:

> ... or, if using OSQL, issue a RAISERROR with state 127. OSQL will stop on errors
with state 127.
David and Tibor,
Raising error with RAISEERROR means abnormal termination. The problem
with
that approach is that setup has to be programmed to ignore 127. I want
a graceful exit from running the script as if the script ran
successfully.|||Why not just add the conditional test in your calling code and decide
at that point whether or not to execute the script. I can't think of a
better way.
David Portas
SQL Server MVP
--|||Hi,
You could try to use labels.
IF (1 = 1)
GOTO QUIT
PRINT 'Not executing code'
QUIT:
PRINT 'Quit'
Ramon @. Havana Club,
SQL Server MCDBBA
"Data Cruncher" <dcruncher4@.netscape.net> '?/'' ? ''
'?: news:1121093312.487489.156320@.z14g2000cwz.googlegroups.com...
> Tibor Karaszi wrote:
>
on errors with state 127.[vbcol=seagreen]
> David and Tibor,
> Raising error with RAISEERROR means abnormal termination. The problem
> with
> that approach is that setup has to be programmed to ignore 127. I want
> a graceful exit from running the script as if the script ran
> successfully.
>

how to stop executing a script

a setup process executes a script via osql. I want to parameterize
it in such a way that whenever wanted the script will do nothing.
For that I plan to created a table in master database, say
NODROP_DATABASE
the first few lines of the script will be
IF EXISTS (SELECT * FROM master.dbo.sysobjects where name = 'NODROP_DATABASE'
and type = 'U')
BEGIN
return
END
-- rest of the script here with many GO in between.
what is happening is that the return statement takes the control to the
first line after GO. The execution continues from the first GO after
that.
Is there any other approach to stop executing.Assuming the script is run by a SYSADMIN you can RAISERROR with a severity
of 20 or greater to terminate the current connection.
Alternatively, run the script from OSQL with the -b option and it will
terminate on the first error.
--
David Portas
SQL Server MVP
--|||... or, if using OSQL, issue a RAISERROR with state 127. OSQL will stop on errors with state 127.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:peKdnWO5478MiE3fRVn-vw@.giganews.com...
> Assuming the script is run by a SYSADMIN you can RAISERROR with a severity of 20 or greater to
> terminate the current connection.
> Alternatively, run the script from OSQL with the -b option and it will terminate on the first
> error.
> --
> David Portas
> SQL Server MVP
> --
>|||Tibor Karaszi wrote:
> ... or, if using OSQL, issue a RAISERROR with state 127. OSQL will stop on errors with state 127.
David and Tibor,
Raising error with RAISEERROR means abnormal termination. The problem
with
that approach is that setup has to be programmed to ignore 127. I want
a graceful exit from running the script as if the script ran
successfully.|||Why not just add the conditional test in your calling code and decide
at that point whether or not to execute the script. I can't think of a
better way.
--
David Portas
SQL Server MVP
--|||Hi,
You could try to use labels.
IF (1 = 1)
GOTO QUIT
PRINT 'Not executing code'
QUIT:
PRINT 'Quit'
Ramon @. Havana Club,
SQL Server MCDBBA
"Data Cruncher" <dcruncher4@.netscape.net> '?/'' ? ''
'?: news:1121093312.487489.156320@.z14g2000cwz.googlegroups.com...
> Tibor Karaszi wrote:
> > ... or, if using OSQL, issue a RAISERROR with state 127. OSQL will stop
on errors with state 127.
> David and Tibor,
> Raising error with RAISEERROR means abnormal termination. The problem
> with
> that approach is that setup has to be programmed to ignore 127. I want
> a graceful exit from running the script as if the script ran
> successfully.
>