Showing posts with label procedures. Show all posts
Showing posts with label procedures. Show all posts

Wednesday, March 28, 2012

Script wackiness

I have tried to script all the tables and stored procedures from several
SQL2005 dbs and I noticed that I get double-quotes for single quotes and a
lot of extra single quotes near the END statements -- making the whole thing
unusable. Anyone know what this is?Could you please post some code ?
HTH, Jens K. Suessmeyer.
http://www.sqlserver2005.de
--|||Here are some examples. What the sprocs do is irrelevant, they've been used
for a long time. But this is script output from 2005 (previously scripted in
from 2000).
****************************************
*
CAST(IsNull(ME.ActualH,0) AS nvarchar(5))+'' ''+
CASE
WHEN ActualHFrac = 0 THEN ''''
WHEN ActualHFrac = 0.0625 THEN ''1/16''
..
/* note the double quotes for singles */
****************************************
**
...
COMMIT TRANSACTION
SELECT @.err = @.@.error
IF @.err <> 0
RETURN @.err
'
END
/* note the wacky little single quote before END, this does not show in 2000
output */
****************************************
**
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id =
OBJECT_ID(N'[dbo].[sel_ContactBrandsCRM]') AND type in (N'P', N'PC')
)
BEGIN
EXEC dbo.sp_executesql @.statement = N'
CREATE PROCEDURE [dbo].[sel_ContactBrandsCRM]
@.ContactID int,
@.SaleID int
AS
...
/* note the single quote after the N on the EXEC line */
"Jens" <Jens@.sqlserver2005.de> wrote in message
news:1168464966.601900.217650@.p59g2000hsd.googlegroups.com...
> Could you please post some code ?
> HTH, Jens K. Suessmeyer.
>
> --
> http://www.sqlserver2005.de
> --
>|||Hi
you told that the scripts are unusable, if that means that the script
break on execution or creation you will have to use the SET
QUOtED_IDENTIFIERS OFF option .
HTH, Jens K. Suessmeyer.
http://www.sqlserver2005.de
--

Script wackiness

I have tried to script all the tables and stored procedures from several
SQL2005 dbs and I noticed that I get double-quotes for single quotes and a
lot of extra single quotes near the END statements -- making the whole thing
unusable. Anyone know what this is?
Could you please post some code ?
HTH, Jens K. Suessmeyer.
http://www.sqlserver2005.de
|||Here are some examples. What the sprocs do is irrelevant, they've been used
for a long time. But this is script output from 2005 (previously scripted in
from 2000).
*****************************************
CAST(IsNull(ME.ActualH,0) AS nvarchar(5))+'' ''+
CASE
WHEN ActualHFrac = 0 THEN ''''
WHEN ActualHFrac = 0.0625 THEN ''1/16''
...
/* note the double quotes for singles */
******************************************
...
COMMIT TRANSACTION
SELECT @.err = @.@.error
IF @.err <> 0
RETURN @.err
'
END
/* note the wacky little single quote before END, this does not show in 2000
output */
******************************************
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id =
OBJECT_ID(N'[dbo].[sel_ContactBrandsCRM]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @.statement = N'
CREATE PROCEDURE [dbo].[sel_ContactBrandsCRM]
@.ContactID int,
@.SaleID int
AS
...
/* note the single quote after the N on the EXEC line */
"Jens" <Jens@.sqlserver2005.de> wrote in message
news:1168464966.601900.217650@.p59g2000hsd.googlegr oups.com...
> Could you please post some code ?
> HTH, Jens K. Suessmeyer.
>
> --
> http://www.sqlserver2005.de
> --
>
|||Hi
you told that the scripts are unusable, if that means that the script
break on execution or creation you will have to use the SET
QUOtED_IDENTIFIERS OFF option .
HTH, Jens K. Suessmeyer.
http://www.sqlserver2005.de

Script wackiness

I have tried to script all the tables and stored procedures from several
SQL2005 dbs and I noticed that I get double-quotes for single quotes and a
lot of extra single quotes near the END statements -- making the whole thing
unusable. Anyone know what this is?Could you please post some code ?
HTH, Jens K. Suessmeyer.
http://www.sqlserver2005.de
--|||Here are some examples. What the sprocs do is irrelevant, they've been used
for a long time. But this is script output from 2005 (previously scripted in
from 2000).
*****************************************
CAST(IsNull(ME.ActualH,0) AS nvarchar(5))+'' ''+
CASE
WHEN ActualHFrac = 0 THEN ''''
WHEN ActualHFrac = 0.0625 THEN ''1/16''
...
/* note the double quotes for singles */
******************************************
...
COMMIT TRANSACTION
SELECT @.err = @.@.error
IF @.err <> 0
RETURN @.err
'
END
/* note the wacky little single quote before END, this does not show in 2000
output */
******************************************
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id =OBJECT_ID(N'[dbo].[sel_ContactBrandsCRM]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @.statement = N'
CREATE PROCEDURE [dbo].[sel_ContactBrandsCRM]
@.ContactID int,
@.SaleID int
AS
...
/* note the single quote after the N on the EXEC line */
"Jens" <Jens@.sqlserver2005.de> wrote in message
news:1168464966.601900.217650@.p59g2000hsd.googlegroups.com...
> Could you please post some code ?
> HTH, Jens K. Suessmeyer.
>
> --
> http://www.sqlserver2005.de
> --
>|||Hi
you told that the scripts are unusable, if that means that the script
break on execution or creation you will have to use the SET
QUOtED_IDENTIFIERS OFF option .
HTH, Jens K. Suessmeyer.
--
http://www.sqlserver2005.de
--

Script to store stored procedures in seperate files

How does MicroSoft store the stored procedures in seperate files.
What tools are used.
Cause that's what I like to do too.

Arno de Jong,

The Netherlands.
(SCPTFXR does not have the option to store the stored procedures in
different files
I think)Enterprise Manager will do this for you: Right-click on the database, click
"Generate SQL script", select the option "Create one file per object".

You can do this programmatically using the Script method of the DMO
StoredProcedure object. Call .Script once for each SP with an appropriate
file name.

http://msdn.microsoft.com/library/e...ef_m_s_0n1g.asp

--
David Portas
----
Please reply only to the newsgroup
--

"A.M. de Jong" <arnojo@.wxs.nl> wrote in message
news:bpshql$oie$1@.reader11.wxs.nl...
> How does MicroSoft store the stored procedures in seperate files.
> What tools are used.
> Cause that's what I like to do too.
> Arno de Jong,
> The Netherlands.
> (SCPTFXR does not have the option to store the stored procedures in
> different files
> I think)|||SQL Server stores the text of stored procedures/views/triggers in a
table called syscomments.

you could use SP_HELPTEXT spname to retrieve text for any stored
procedure
you could study the SP_HELPTEXT procedure and it will show you exactly
how microsoft retrieves the TEXT:) ENJOY

Peace:)

"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message news:<g8GdnSrn59RfdVyi4p2dnA@.giganews.com>...
> Enterprise Manager will do this for you: Right-click on the database, click
> "Generate SQL script", select the option "Create one file per object".
> You can do this programmatically using the Script method of the DMO
> StoredProcedure object. Call .Script once for each SP with an appropriate
> file name.
> http://msdn.microsoft.com/library/e...ef_m_s_0n1g.asp
> --
> David Portas
> ----
> Please reply only to the newsgroup
> --
> "A.M. de Jong" <arnojo@.wxs.nl> wrote in message
> news:bpshql$oie$1@.reader11.wxs.nl...
> > How does MicroSoft store the stored procedures in seperate files.
> > What tools are used.
> > Cause that's what I like to do too.
> > Arno de Jong,
> > The Netherlands.
> > (SCPTFXR does not have the option to store the stored procedures in
> > different files
> > I think)

Monday, March 26, 2012

Script to identify line count in an procedure

Hi Guys,
Do any one of you have any scripts which return the procedure name and
number of lines for all procedures in a database.
Say I have a server with 1000 stored procedure,I need a script which return:
Procedure name Number of lines
-- --
Thanks in advance
HariI think this should do it:
SELECT O.name, SUM(LEN(text)-LEN(REPLACE(text,CHAR(13),'')))
FROM syscomments AS C
JOIN sysobjects AS O
ON C.id = O.id
WHERE O.xtype='P'
GROUP BY O.id, O.name
--
David Portas
--
Please reply only to the newsgroup
--|||Thanks a lot.
Regards
Hari
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:iMidnTtJieiJzlqiRVn-gQ@.giganews.com...
> I think this should do it:
> SELECT O.name, SUM(LEN(text)-LEN(REPLACE(text,CHAR(13),'')))
> FROM syscomments AS C
> JOIN sysobjects AS O
> ON C.id = O.id
> WHERE O.xtype='P'
> GROUP BY O.id, O.name
> --
> David Portas
> --
> Please reply only to the newsgroup
> --
>

Script to grant execute for sprocs

Hello.

I'm using what looks to be a popular script to grant execute privileges to stored procedures, and it works great as long as the user account that you want to grant to is not a domain account.

For example, I need to grant execute to myDomain\dbUsers, but get a syntax error when the script tries to execute this statement:

SET @.SQL = 'GRANT EXECUTE ON [' + @.Owner

+ '].[' + @.StoredProcedure

+ '] TO myDomain\dbUsers'

Incorrect syntax near '\'.

The script works fine if a non-concatenated user account is given.

We use Active Directory to manage our access, thus the domain\group.

Has anyone found a way around this?

Thanks in advance.

Tess

Here's the entire script for anyone who's interested:

USE whateverDatabase

GO

DECLARE @.SQL nvarchar(4000),

@.Owner sysname,

@.StoredProcedure sysname,

@.RETURN int

-- Cursor of all the stored procedures in the current database

DECLARE cursStoredProcedures CURSOR FAST_FORWARD

FOR

SELECT USER_NAME(uid) Owner, [name] StoredProcedure

FROM sysobjects

WHERE xtype = 'P'

AND OBJECTPROPERTY(OBJECT_ID(QUOTENAME(USER_NAME(uid)) + '.' + QUOTENAME(name)), 'IsMSShipped') = 0

AND name LIKE 'p%'

OPEN cursStoredProcedures

-- "Prime the pump" and get the first row

FETCH NEXT FROM cursStoredProcedures

INTO @.Owner, @.StoredProcedure

-- Set the return code to 0

SET @.RETURN = 0

-- Encapsulate the permissions assignment within a transaction

BEGIN TRAN

-- Cycle through the rows of the cursor

-- And grant permissions

WHILE ((@.@.FETCH_STATUS = 0) AND (@.RETURN = 0))

BEGIN

-- Create the SQL Statement. Since we’re giving

-- access to all stored procedures, we have to

-- use a two-part naming convention to get the owner.

SET @.SQL = 'GRANT EXECUTE ON [' + @.Owner

+ '].[' + @.StoredProcedure

+ '] TO myDomain\dbUsers'

-- Execute the SQL statement

EXEC @.RETURN = sp_executesql @.SQL

-- Get the next row

FETCH NEXT FROM cursStoredProcedures

INTO @.Owner, @.StoredProcedure

END

-- Clean-up after the cursor

CLOSE cursStoredProcedures

DEALLOCATE cursStoredProcedures

-- Check to see if the WHILE loop exited with an error.

IF (@.RETURN = 0)

BEGIN

-- Exited fine, commit the permissions

COMMIT TRAN

END

ELSE

BEGIN

-- Exited with an error, rollback any changes

ROLLBACK TRAN

-- Report the error

SET @.SQL = 'Error granting permission to ['

+ @.Owner + '].[' + @.StoredProcedure + ']'

RAISERROR(@.SQL, 16, 1)

END

GO

Just like with table and other object names, if the user contains special characters it must be "quoted" so, add either [] or "" around the user

|||

Thank you very much!

Tess

sql

Script to export tables,store procedures and data in SQL Server Management Studio Expres

how i can do a script to export tables,store procedures and data in SQL Server Management Studio Expres

I just arrive to do a script for tables and stores procedures

help please

hi,

this feature is not supported in SQL Server Management Studio (and SSMSExpress too)... you can only script out the DDL to re-create the initial objects but not to populate them..

if you like, you can have a look at 2 free prjs of mine at http://www.asql.biz/en/Download2005.aspx..

amScript is to generate DDL scripts, where amInsert is to generate INSERT INTO scripts to populate existing tables...

regards

|||

Our web hosting team is working on a tool that will do much of this as well. You can check out their progress by downloading the most recent CTP of the Database Publishing Wizard from CodePlex. You'll find information on the site explaining what the tool does and how it works.

Mike

Friday, March 23, 2012

Script to drop articles from transactional replication

--This script builds a script to drop articles from replication in
transactional publications
--It will build the necessary replication procedures and parameters to
remove articles from replication
--Instructions
--Either hard code the where clause criteria or have it look in a table you
have already populated
--Run this script on the distribution server
--Be sure to have the results output to text
--Copy the results and execute on the server where the publications exist
use distribution
go
select 'use ' + p.publisher_db + char(13) + 'go ' + char(13) + 'exec sp
dropsubscription @.publication = ''' + p.publication + ''', @.article = ''' +
a.article + ''', @.subscriber = ''' + s.srvname + ''', @.destination_db = ''' +
sub.subscriber_db + '''' + char(13) + 'exec sp_droparticle @.publication = '''
+ p.publication + ''', @.article = ''' + a.article + '''' + char(10) + char(13)
from dbo.mspublications p
inner join
dbo.msarticles a on p.publication_id = a.publication_id
inner join
dbo.msdistribution_agents ag on p.publisher_id = ag.publisher_id and
p.publisher_db = ag.publisher_db
inner join
master.dbo.sysservers s on ag.subscriber_id = s.srvid
inner join
dbo.mssubscriptions sub on ag.id = sub.agent_id and
sub.publisher_id = p.publisher_id and
sub.publisher_db = p.publisher_db and
sub.article_id = a.article_id
where a.article in(
'table1','table2','etc..'
)
and p.publisher_db = 'db_name'
--Sorry, had a typo
--This script builds a script to drop articles from replication in
transactional publications
--It will build the necessary replication procedures and parameters to
remove articles from replication
--Instructions
--Either hard code the where clause criteria or have it look in a table you
have already populated
--Run this script on the distribution server
--Be sure to have the results output to text
--Copy the results and execute on the server where the publications exist
use distribution
go
select 'use ' + p.publisher_db + char(13) + 'go ' + char(13) + 'exec
sp_dropsubscription @.publication = ''' + p.publication + ''', @.article = '''
+
a.article + ''', @.subscriber = ''' + s.srvname + ''', @.destination_db = ''' +
sub.subscriber_db + '''' + char(13) + 'exec sp_droparticle @.publication = '''
+ p.publication + ''', @.article = ''' + a.article + '''' + char(10) + char(13)
from dbo.mspublications p
inner join
dbo.msarticles a on p.publication_id = a.publication_id
inner join
dbo.msdistribution_agents ag on p.publisher_id = ag.publisher_id and
p.publisher_db = ag.publisher_db
inner join
master.dbo.sysservers s on ag.subscriber_id = s.srvid
inner join
dbo.mssubscriptions sub on ag.id = sub.agent_id and
sub.publisher_id = p.publisher_id and
sub.publisher_db = p.publisher_db and
sub.article_id = a.article_id
where a.article in(
'table1','table2','etc..'
)
and p.publisher_db = 'db_name'

Script to Add WITH ENCRYPTION to all SPs, Vs and Fns

I'm about to roll out a new database to another site and would like to encrypt all stored procedures, views and functions. I know this can be done by simply adding WITH ENCRYPTION in the appropriate spot, but I don't want to edit every single stored procedure, view and function one by one.

Is there a way (and if so, how do I go about it) to first of all output all stored procedures, views and scripts to a file, (not using enterprise manager, but rather using a sql script) then encrypt them all?

Essentially, I need to output them all to a file first just in case I have to edit them again.

Any ideas on how I would go about this?

Thanks in advanceAnyone have any clues?|||you need to script out the sp/fn/etc, then use FileSystemObject to read the file in and look for " AS" and prefix it with "with encryption". There isn't any *automated* way or sql builtin tool.

Wednesday, March 21, 2012

Script Table, Index, Stored Procedures from Table list

I have a list of approximately 2000 objects that need to create a sql script
to generate these objects. The script will be applied to another datbase to
generate these objects.
The 2000 objects name have been loaded into a Table A.
Please help put together a program that will read the object names from
Table A and generate a sql script for objects.
Thank You,Option#1
Try from Enterprise Manager (Tools -> Generate SQL Scripts)
Option#2
Try Import\Export utility from Enterprise Manager
Thanks,
RK
"Joe K." wrote:

> I have a list of approximately 2000 objects that need to create a sql scri
pt
> to generate these objects. The script will be applied to another datbase
to
> generate these objects.
> The 2000 objects name have been loaded into a Table A.
> Please help put together a program that will read the object names from
> Table A and generate a sql script for objects.
> Thank You,
>|||I would like to way read from a table to "Generate SQL Scripts".
I would like to automate the "Generate SQL Scripts" procedure.
Thanks,
"Ram Kumar Koditala" wrote:
> Option#1
> Try from Enterprise Manager (Tools -> Generate SQL Scripts)
> Option#2
> Try Import\Export utility from Enterprise Manager
> Thanks,
> RK
> "Joe K." wrote:
>|||You'll have to use SQL DMO to do this. See if the following links help:
http://www.karaszi.com/SQLServer/in...rate_script.asp
http://www.databasejournal.com/feat...cle.php/1480901
Anith

Tuesday, March 20, 2012

Script Stored Procedures based on dependency

I don't follow the logic of a sql server farm as if they
were entirely different databases without incorporating
replication. Clustering is largely for failover I believe.
That said, this script does a nice job of creating
a sql script of all your procs from your qa/development
database in order by dependency if you really do
need to copy the procs to multiple databases:
http://www.eggheadcafe.com/articles/20030609.asp
Robbe Morris - 2004/2005 Microsoft MVP C#
Earn money answering .NET Framework
messageboard posts at EggHeadCafe.com.
http://www.eggheadcafe.com/forums/merit.asp
"tshad" <tscheiderich@.ftsolutions.com> wrote in message
news:uCg%230cOpFHA.3244@.TK2MSFTNGP09.phx.gbl...
> How are people dealing with SPs in an n-tiered environment?
> If you have x number of machines and they all have to have the same SPs,
> how do you deal with changes to the SPs?
> Do you make changes to one Server and then copy them to the rest?
> We are concerned with this as we are expecting to be setting up a Web Farm
> as well as multiple Sql Servers to spread out the load.
> Thanks,
> Tom
>"Robbe Morris [C# MVP]" <info@.eggheadcafe.com> wrote in message
news:%23yphCPPpFHA.2156@.TK2MSFTNGP14.phx.gbl...
>I don't follow the logic of a sql server farm as if they
> were entirely different databases without incorporating
> replication. Clustering is largely for failover I believe.
I am not really sure, either.
This was something that was brought up at one of our development meetings
that one of our partners used (with oracle, actually I believe). They were
talking about outgrowing the server they had and needed to add servers to
spread the load. Not really sure how they were doing it.

> That said, this script does a nice job of creating
> a sql script of all your procs from your qa/development
> database in order by dependency if you really do
> need to copy the procs to multiple databases:
> http://www.eggheadcafe.com/articles/20030609.asp
Like it.
Worked like a charm, with no changes at all.
Thanks,
Tom
> --
> Robbe Morris - 2004/2005 Microsoft MVP C#
> Earn money answering .NET Framework
> messageboard posts at EggHeadCafe.com.
> http://www.eggheadcafe.com/forums/merit.asp
>
> "tshad" <tscheiderich@.ftsolutions.com> wrote in message
> news:uCg%230cOpFHA.3244@.TK2MSFTNGP09.phx.gbl...
>

Monday, March 12, 2012

Script Help

Would really appreciate some help/ideas. The stored procedures for my
application are all saved to a folder in the file system of my deeloper work
station. What is the best way to loop through the folder and execute the sql
(create procedure...)in each file?
Thanks for any tipsOne method is to run your scripts with a FOR command from the command-prompt
that invokes OSQL. For example:
FOR %f IN (*.SQL) DO OSQL -i "%f" /E /S MyServer
Hope this helps.
Dan Guzman
SQL Server MVP
"Mardy" <Mardy@.discussions.microsoft.com> wrote in message
news:F9E35C8D-A44A-484A-A63B-D3571A908AF8@.microsoft.com...
> Would really appreciate some help/ideas. The stored procedures for my
> application are all saved to a folder in the file system of my deeloper
> work
> station. What is the best way to loop through the folder and execute the
> sql
> (create procedure...)in each file?
> Thanks for any tips|||FYI, I generally just copy all of the procedures to one file and run that:
COPY *.* SP.sql
But this will only work if you have a GO statement at the bottom of each.
"Dan Guzman" wrote:

> One method is to run your scripts with a FOR command from the command-prom
pt
> that invokes OSQL. For example:
> FOR %f IN (*.SQL) DO OSQL -i "%f" /E /S MyServer
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Mardy" <Mardy@.discussions.microsoft.com> wrote in message
> news:F9E35C8D-A44A-484A-A63B-D3571A908AF8@.microsoft.com...
>
>

Script for SQL 2005

Hi,

How to prepare a script that copies all the table structures, procedures, logins, functions from sql server 2000 database to sql server 2005 database. Sorry i am confused doing this. can anyone help me out. pls.

Thanks in advance

1st question, why do you need a script to do this? You can backup your SQL 2000 DB, restore it on SQL 2005 and upgrade it to SQL 2005 when you restore. Same holds true for detaching it from SQL 2000, copying it to SQL 2005 server, then attaching it to the SQL 2005 DB server as an upgraded DB.

If you need the scripts, you can script the database by Opening Enterprise Manager, right clicking on the database you want, then select script menu (I can't remember the exact name of the choice), but in the script wizard, select all objects and set your paramaters and file output. Run the wizard and you should get one or several (depending on how you set it up) files you can open and run on SQL 2005 (SQL 2005 supports SQL 2000 database compatability, so you can create the SQL 2000 DB on it and then upgrade it).

Script for SQL 2005

Hi,

How to prepare a script that copies all the table structures, procedures, logins, functions from sql server 2000 database to sql server 2005 database. Sorry i am confused doing this. can anyone help me out. pls.

Thanks in advance

1st question, why do you need a script to do this? You can backup your SQL 2000 DB, restore it on SQL 2005 and upgrade it to SQL 2005 when you restore. Same holds true for detaching it from SQL 2000, copying it to SQL 2005 server, then attaching it to the SQL 2005 DB server as an upgraded DB.

If you need the scripts, you can script the database by Opening Enterprise Manager, right clicking on the database you want, then select script menu (I can't remember the exact name of the choice), but in the script wizard, select all objects and set your paramaters and file output. Run the wizard and you should get one or several (depending on how you set it up) files you can open and run on SQL 2005 (SQL 2005 supports SQL 2000 database compatability, so you can create the SQL 2000 DB on it and then upgrade it).

Friday, March 9, 2012

script for all dependencies

Hi All,
Is there any script to get all the dependencies on all the tables or all the
Stored Procedures in a database? I need to check the dependencies are still
there after I upgrade a database.
Thanks
Julia
Try this script. The output from this is the sql code you can run.
select 'sp_depends ' + '''' + name + '''' + char(13) + 'GO' from sysobjects
where type = 'U' and name not like 'dt%'
The output will look something like this:
sp_depends 'Orders'
GO
sp_depends 'Products'
GO
sp_depends 'Order Details'
GO
sp_depends 'CustomerCustomerDemo'
GO
sp_depends 'CustomerDemographics'
GO
sp_depends 'Region'
GO
sp_depends 'Territories'
GO
sp_depends 'EmployeeTerritories'
GO
sp_depends 'Employees'
GO
sp_depends 'Categories'
GO
"Julia" wrote:

> Hi All,
> Is there any script to get all the dependencies on all the tables or all the
> Stored Procedures in a database? I need to check the dependencies are still
> there after I upgrade a database.
> Thanks
> Julia

script for all dependencies

Hi All,
Is there any script to get all the dependencies on all the tables or all the
Stored Procedures in a database? I need to check the dependencies are still
there after I upgrade a database.
Thanks
JuliaTry this script. The output from this is the sql code you can run.
select 'sp_depends ' + '''' + name + '''' + char(13) + 'GO' from sysobjects
where type = 'U' and name not like 'dt%'
The output will look something like this:
sp_depends 'Orders'
GO
sp_depends 'Products'
GO
sp_depends 'Order Details'
GO
sp_depends 'CustomerCustomerDemo'
GO
sp_depends 'CustomerDemographics'
GO
sp_depends 'Region'
GO
sp_depends 'Territories'
GO
sp_depends 'EmployeeTerritories'
GO
sp_depends 'Employees'
GO
sp_depends 'Categories'
GO
"Julia" wrote:
> Hi All,
> Is there any script to get all the dependencies on all the tables or all the
> Stored Procedures in a database? I need to check the dependencies are still
> there after I upgrade a database.
> Thanks
> Julia

script for all dependencies

Hi All,
Is there any script to get all the dependencies on all the tables or all the
Stored Procedures in a database? I need to check the dependencies are still
there after I upgrade a database.
Thanks
JuliaTry this script. The output from this is the sql code you can run.
select 'sp_depends ' + '''' + name + '''' + char(13) + 'GO' from sysobjects
where type = 'U' and name not like 'dt%'
The output will look something like this:
sp_depends 'Orders'
GO
sp_depends 'Products'
GO
sp_depends 'Order Details'
GO
sp_depends 'CustomerCustomerDemo'
GO
sp_depends 'CustomerDemographics'
GO
sp_depends 'Region'
GO
sp_depends 'Territories'
GO
sp_depends 'EmployeeTerritories'
GO
sp_depends 'Employees'
GO
sp_depends 'Categories'
GO
"Julia" wrote:

> Hi All,
> Is there any script to get all the dependencies on all the tables or all t
he
> Stored Procedures in a database? I need to check the dependencies are sti
ll
> there after I upgrade a database.
> Thanks
> Julia

Tuesday, February 21, 2012

SCOPE_IDENTITY plzzzzz help me

this is my code, i really want a basic easy way without using procedures to do a simple task to response.write(last record added) using scope_identity...
asp.net/VB
===================================================================================
Sub click_addnew(sender as object, e as system.eventargs)

Dim oDR as System.Data.SQLClient.SQLDataReader
Dim oCom As System.Data.SQLClient.SqlCommand
Dim oConn as System.Data.SQLClient.SQLConnection
Dim recnumber as integer
try
oConn = New System.Data.SQLClient.SQLConnection ("server=xxx.xxx.xx; initial catalog=xxx;uid=xxx;pwd=xxx")
oConn.Open()
oCom = New System.Data.SQLClient.SqlCommand()
oCom.Connection = oConn

oCom.CommandText = "INSERT INTO hooliganproducts (hooligantitle, hooliganprice, hooligandescription, hooliganpartno, hooligancata) VALUES ('test' , '100' , 'test' , 'test' , 'test') select scope_identity"
oDR = oCom.ExecuteReader()
response.Write(oDR) 'THIS IS WHERE I WANT TO DISPLAY THE NUMBER OF THE LAST RECORD

catch
Response.Write("Error:" & err.Description)
Finally
oDR = Nothing
oCom = Nothing
oConn.Close()
oConn = Nothing
end try

End Sub
=============================================================================

Please can someone help, feel like i have been banging my head up a brick wall all day, have spent the whole day trying to find an answer.
Thank you in advance
Darren

Multiple SQL commands in a batch should be separated by semicolons (;). Try putting a semicolon between theINSERT statement and theselect scope_identity statement.
|||(1) You need brackets after SCOPE_IDENTITY as in SCOPE_IDENTITY().
(2) You might want to use ExecuteScalar since you are only getting backone value. So you can also avoid the overhead of creating a datareader.
So your code would look something like :
oConn = New System.Data.SQLClient.SQLConnection ("server=xxx.xxx.xx; initial catalog=xxx;uid=xxx;pwd=xxx")
'oConn.Open() - OPEN ONLY WHEN YOU NEED AND CLOSE IMMEDIATELY.
oCom = New System.Data.SQLClient.SqlCommand()
oCom.Connection = oConn
oCom.CommandText= "INSERT INTO hooliganproducts (hooligantitle, hooliganprice,hooligandescription, hooliganpartno, hooligancata) VALUES ('test' ,'100' , 'test' , 'test' , 'test') select SCOPE_IDENTITY()"
Dim newId as Integer
try
oConn.Open()
newId = oCom.ExecuteScalar()
response.Write(newId) 'THIS IS WHERE I WANT TO DISPLAY THE NUMBER OF THE LAST RECORD

catch
Response.Write("Error:" & err.Description)
Finally
oCom = Nothing
oConn.Close()
oConn = Nothing
end try
|||Thank you both. feel much better now, got it working.