Showing posts with label local. Show all posts
Showing posts with label local. Show all posts

Friday, March 30, 2012

Scripting ALTER TABLE

I need to create a script to disable all triggers and constraints in my
database.

It appears as though I cannot use a local variable for the table name in the
ALTER TABLE statement (e.g. ALTER TABLE @.TBL).

Is there any reason for this?

Thanks,

Kevin"Kevin Haugen" <khaugen@.pacbell.net> wrote in message
news:jx1Hd.12736$5R.1377@.newssvr21.news.prodigy.co m...
>I need to create a script to disable all triggers and constraints in my
>database.
> It appears as though I cannot use a local variable for the table name in
> the ALTER TABLE statement (e.g. ALTER TABLE @.TBL).
> Is there any reason for this?
> Thanks,
> Kevin

You can't use variables in place of table or column names, except when using
dynamic SQL, which has its own issues. Although if you're a DBA running an
admin script, then it's usually a reasonable option - there's more
discussion here:

http://www.sommarskog.se/dynamic_sql.html

Unfortunately, you don't say what your goal is, but if it's to load data
into the database, then all the usual loading tools (bcp.exe, DTS, BULK
INSERT) can ignore both constraints and triggers, so you might not need a
script anyway.

Simon|||"Simon Hayes" <sql@.hayes.ch> wrote in message
news:41ecd751$1_1@.news.bluewin.ch...
> "Kevin Haugen" <khaugen@.pacbell.net> wrote in message
> news:jx1Hd.12736$5R.1377@.newssvr21.news.prodigy.co m...
>>I need to create a script to disable all triggers and constraints in my
>>database.
>>
>> It appears as though I cannot use a local variable for the table name in
>> the ALTER TABLE statement (e.g. ALTER TABLE @.TBL).
>>
>> Is there any reason for this?
>>
>> Thanks,
>>
>> Kevin
>>
> You can't use variables in place of table or column names, except when
> using dynamic SQL, which has its own issues. Although if you're a DBA
> running an admin script, then it's usually a reasonable option - there's
> more discussion here:
> http://www.sommarskog.se/dynamic_sql.html
> Unfortunately, you don't say what your goal is, but if it's to load data
> into the database, then all the usual loading tools (bcp.exe, DTS, BULK
> INSERT) can ignore both constraints and triggers, so you might not need a
> script anyway.
> Simon

I'll look into it. I'm planning on converting existing data into a new
format. Since I have to identify each table and write a query to do the
conversion, I could easily do a copy/paste for each table to disable and
re-enable the triggers and constraints. I am hoping to shortcut some of the
work by automating that piece.

Thanks,

Kevin

Wednesday, March 28, 2012

script USE help

I have a script that has a local variable called @.DB which holds the name of
the database to use, like this:
DECLARE
@.dbname varchar (256);
set @.dbname = 'DBNAME_REPLACEONINSTALL'
Our GUI installation modifies the value of this script. This is validated by
testing the value of the variable, using:
IF @.dbname like '%REPLACEONINSTALL%'
RAISERROR('Script is invalid. Must be run through GUI installer or local
variables at top of script must be replaced manually. Exiting database
create', 20, 1) WITH LOG;
else
select 'Script validated, proceeding' as STEP;
I then issue the USE command, using:
use @.DBNAME
DDL SQL..
DDL SQL..
DDL SQL..
The script fails due to this:
Server: Msg 170, Level 15, State 1, Line 7
Line 7: Incorrect syntax near '@.dbname'.
I am guessing that you cannot use local variables in a USE command. Is this
true?
"Bevo" <Bevo@.discussions.microsoft.com> wrote in message
news:67AAD8FB-EDA2-4CE7-BDAC-93E8EC322185@.microsoft.com...
> I am guessing that you cannot use local variables in a USE command. Is
this
> true?
That is correct... You'll probably have to use dynamic SQL with the USE and
the DDL in a single batch.

script USE help

I have a script that has a local variable called @.DB which holds the name of
the database to use, like this:
DECLARE
@.dbname varchar (256);
set @.dbname = 'DBNAME_REPLACEONINSTALL'
Our GUI installation modifies the value of this script. This is validated by
testing the value of the variable, using:
IF @.dbname like '%REPLACEONINSTALL%'
RAISERROR('Script is invalid. Must be run through GUI installer or local
variables at top of script must be replaced manually. Exiting database
create', 20, 1) WITH LOG;
else
select 'Script validated, proceeding' as STEP;
I then issue the USE command, using:
use @.DBNAME
DDL SQL..
DDL SQL..
DDL SQL..
The script fails due to this:
Server: Msg 170, Level 15, State 1, Line 7
Line 7: Incorrect syntax near '@.dbname'.
I am guessing that you cannot use local variables in a USE command. Is this
true?"Bevo" <Bevo@.discussions.microsoft.com> wrote in message
news:67AAD8FB-EDA2-4CE7-BDAC-93E8EC322185@.microsoft.com...
> I am guessing that you cannot use local variables in a USE command. Is
this
> true?
That is correct... You'll probably have to use dynamic SQL with the USE and
the DDL in a single batch.sql

Friday, March 9, 2012

Script Execution of Report with parameters

I need to script the execution of reports with input parameter values and with the report output going to PDF in a local file location on the server. I can't use traditional Report Server scheduling because I have to loop through a list of clients and execute the report for each client.

I appreciate any help you can offer.

Hello,

You should take a look at Data-Driven Subscriptions (if you have Enterprise edition) , it will be able to handle what you're trying to do. You can set the render output, parameters, etc.

Jarret

|||

Thanks for the feedback Jarret. We have only had the Standard edition, but our new server will have the Enterprise edition for me to try Data-Driven Subscriptions in the next couple of weeks.

I setup a test server with the Demo of SQL 2005 Enterprise and here are my results for anyone else having similar goals.

We have about 30-40 reports all of which are used by 40-50 clients. The way I accomplish this is by using dynamic Data Source connections in the reports which can connect to all 40-50 client databases. It works fine for on-demand reporting where I pass in the connection information based on the client calling the report. By using these dynamic Data Sources, it saves me from having to maintain between 1200 and 2000 reports and/or linked reports, one for each combination of report and client. We simply don't have the staff to maintain that many reports.

By following the steps in the BOL and using Credentials stored securely in the report server, you can create a New Data Driven Subscription... and report against multiple databases from one schedule by passing in the connection information from the Subscription database.

Wednesday, March 7, 2012

Script a SQL Server 2005 Express DB

Hi,
I have a SQL Express DB that I've used for local development.
I now want to move this to an online sql server.
Is there a simple way to generate scripts or a batch file to re-create
the database online.
Online I only have access to creating stored procedures, and I don't
want to retype the entire DB.
Thanks in advance,
RangyHi
Take a look at BACKUP/RESTORE commnads or sp_detach_db and sp_attach_db
stored procedures
in the BOL
"Ranginald" <davidwank@.gmail.com> wrote in message
news:1145936902.665792.323020@.y43g2000cwc.googlegroups.com...
> Hi,
> I have a SQL Express DB that I've used for local development.
> I now want to move this to an online sql server.
> Is there a simple way to generate scripts or a batch file to re-create
> the database online.
> Online I only have access to creating stored procedures, and I don't
> want to retype the entire DB.
> Thanks in advance,
> Rangy
>|||You might want to look at a tool like SQL Compare from Red Gate. It
compares two databases and generates change scripts for you.
Hope this helps!
Chuck Heinzelman
MCSD, MCDBA
I support the Professional Association for SQL Server (www.sqlpass.org)
This posting is not an endoresment of any product.
Information is provided as-is, and carries no warranties - either express or
implied.
Please respond in newsgroups only.
"Ranginald" <davidwank@.gmail.com> wrote in message
news:1145936902.665792.323020@.y43g2000cwc.googlegroups.com...
> Hi,
> I have a SQL Express DB that I've used for local development.
> I now want to move this to an online sql server.
> Is there a simple way to generate scripts or a batch file to re-create
> the database online.
> Online I only have access to creating stored procedures, and I don't
> want to retype the entire DB.
> Thanks in advance,
> Rangy
>