References to Views/Stored Procedures - sql-server-2000

How can I find out what other views/stored procedures are using a specific view/stored procedure? Thanks Lennie

sp_depends will:
Displays information about database
object dependencies, such as the views
and procedures that depend on a table
or view, and the tables and views that
are depended on by the view or
procedure.
Note:
This feature will be removed in a
future version of Microsoft SQL
Server. Avoid using this feature in
new development work, and plan to
modify applications that currently use
this feature. Use
sys.dm_sql_referencing_entities and
sys.dm_sql_referenced_entities
instead.
As #marc mentioned, Redgate's SQL Dependency Tracker is worth the investment.

The quickest SQL way with no 3rd party tools is to search the view/proc/udf definition
SELECT OBJECT_NAME(object_id) FROM sys.sql_modules WHERE definition LIKE '%WhatToLookFor%"
For SQL Server 2000 (as per your tag), use syscomments
The internal dependency tracking of SQL Server is notoriously, er, shit, at least before sys.sql_expression_dependencies (related to Mitch's answer). And definitely in SQL Server 2000.

There are excellent tools out there that help you with this - e.g. Red-Gate's SQL Dependency Tracker. Well worth the investment - finding dependencies is a challenge you'll face over and over again.

Related

Is my SQL version determined by the database I'm accessing or by my SQL client?

I have a SQL query I want to optimize, so I asked the database owner what version of SQL they were using (since ordinary methods didn't seem to have support). They answered that my version of SQL is not decided by them but by my local SQL client. They claimed to use a system called "DB2", with support for multiple SQL dialects.
I then went on to ask our IT department which version of SQL our client was using (that client being Squirrel SQL). After some fiddling around they logged on to the database, queried it and reported the version of SQL to be DB2.[sequence of decimals].
This is probably a stupid question, but would someone mind clarifying this?
Is the version of SQL I'm using determined by the database I'm accessing or by my SQL client?
If the version of SQL is decided by the database, then which version of SQL is DB2 associated with? Does it use its own version?
"They answered that my version of SQL is not decided by them but by my local SQL client"
That's complete and utter nonsense - those people apparently have no idea what they are talking about.
The SQL dialect that is understood by the server is only defined by that server. The client has absolutely nothing to do with that. If the database server doesn't support some specific feature, no SQL client will change that.
There is an industry standard called ANSI SQL that database vendors implement. Then on top of that they tack on non-standard proprietary stuff, extra commands, keywords, procedural stuff like stored procedures and triggers and cursors, that are not covered by a standard but which they expect will provide useful features that will differentiate them from the competition.
For Db2 11’s compliance with standards see https://www.ibm.com/support/knowledgecenter/SSEPGG_11.1.0/com.ibm.db2.luw.common.doc/doc/c0011215.html. The actual spec is behind a paywall so this is not that helpful. See https://www.whoishostingthis.com/resources/ansi-sql-standards/#sql-ansi-standards-for-database-administration for an explanation of ANSI SQL standards.
Different db2 products (Z/OS, LUW) might have different extensions. Z/OS has to do horrible mainframey stuff that LUW can do without. But you wouldn’t be given a choice, you have to use the commands implemented by the database that you are connected to. The SQL client doesn’t have a role in this.

Oracle procedures vs MS procedures vs Oracle packages

I was told by someone that when you create procedures in Oracle you should create a Package with procedures in it. Is this a true statement? Are procedures in MS the same as Oracle?
You do not have to put your procedures and functions inside a package, but it is generally considered a best practice. Bundle them by function and they are a lot easier to organize.
One exception to this is the AUTHID clause. That can only be specified for an entire package or a standalone procedure/function. Different procedures inside a single package cannot have different privileges.
Procedures in Oracle and MS are similar, but yes, in Oracle, you make a package declaring the procedure, then you define the procedure in the package body
This has some good info on how to build an Oracle package
Stored procedures and functions are very similar between Oracle and SQL Server (or MySQL, PostgreSQL, etc). A SQL function is intended to always return a SQL data type; a stored procedure can return a SQL data type but doesn't by default.
An Oracle package is an awesome tool.
SQL Server has assemblies, but they aren't as immediately accessible as Oracle packages.
Besides being a container for functions and stored procedures, Oracle packages support variable declaration when other alternatives would only expose via functions.
Oracle packages also allow for logical grouping of functionality, without needing to setup schemas (for namespacing). Because of what's contained in a package, you deploy the package -- not the functions/stored procedures individually.
My only regret was that IME (Oracle 9i, 10g), you could not drill into the specific function/stored procedure/line when tracing references.
There's nothing requiring you to use Oracle Packages, but you really stand to benefit by using them vs not. I don't understand why other vendors haven't reproduced the functionality in their own way.
There are a ton of reasons to use packages over standalone procedures/functions, and a few situations when you wouldn't use packages. Instead of trying to rehash them from memory, I'll point you to an excellent article from pl/sql guru Steve Feuerstein.
Note: The article is several years old, but the rationale still holds imo

What's the steps for SQL optimization and changes without reflect live system?

we have a big portal that build using SharePoint 2007 , asp.net 3.5 , SQL Server 2005 .. many developers work in it since 01/2008 and we are now doing huge analysis for current SQL Databases [not share-point DB ] to optimize and enhance it.
The main db have about 330 table and 1720 stored procedure (SP) created from 01/2008 till now
Many table names / Columns is very long and we want to short it
we found SP names is written in 25 format :( , some of them are very complex and also we want to rename
many SP parameters need to be renamed
one of the biggest table is Registered user table, that will be spitted in more than one table for some optimization, many columns name will be changed
I searched for the way that i can rename table names ,columns and i found SQL refactor tool but i still trying it ..
my questions :
Is SQl Refactor is the best tool for renaming ? or is there any other one ?
if i want to make it manually, is there any references or best practice for that ?
How can i do such changes in fast and stable way .. i search for recommendations and case studies if exist ?
This is why people have written coding standards (with defined naming conventions) and have code reviews!! Make sure you implement those procedures right now, to prevent his from getting any worse in the future.
Also for around $300, SQL Refactor™ is an excellent tool. If you were to use search and replace, you'd have countless errors and spend hours and hours editing code. I wouldn't even consider using anything other than SQL Refactor, and would never even try using a manual search and replace method on something as large as you describe.
You can use Visual Studio 2005 Database Edition, 2008 Database Edition or 2010 ultimate to load up your DB schema. This provides refactor capabilities, as well as database "builds" that check references in stored procedures, views and functions to ensure all tables and columns referenced actually exist.

What is best tool to compare two SQL Server databases (schema and data)? [duplicate]

This question already has answers here:
What is a free tool to compare two SQL Server Databases? [closed]
(7 answers)
Closed 3 years ago.
I would like to compare two SQL Server databases including schema (table structure) and data in tables too. What is best tool to do this?
I use schema and data comparison functionality built into the latest version Microsoft Visual Studio 2015 Community Edition (Free) or Professional / Premium / Ultimate edition. Works like a charm!
http://channel9.msdn.com/Events/Visual-Studio/Launch-2013/VS108
Red-Gate's SQL data comparison tool is my second alternative:
(source: spaanjaars.com)
http://www.red-gate.com/products/sql-development/sql-compare/
http://www.red-gate.com/products/sql-development/sql-data-compare/
I like Open DBDiff.
While not the most complete tool, it works great, it's free, and it's very easy to use.
I am using Red-Gate's software:
http://www.red-gate.com
SQL Admin Studio from http://www.simego.com/Products/SQL-Admin-Studio is now free, lets you manage your SQL Database, SQL Compare and Synchronise, Data Compare and Synchronise and much more. Also supports SQL Azure and some MySQL Support too.
[UPDATE: Yes I am the Author of the above program, as it's now Free I just wanted to Share it with the community]
I'm partial to AdeptSQL. It's clean and intuitive and it DOESN'T have the one feature that scares the hell out of me on a lot of similar programs. One giant button that it you push it will automatically synchronize EVERYTHING without so much as a by-your-leave. If you want to sync the changes you have to do it yourself and I like that.
There is one tool with source code available at
http://www.codeproject.com/Articles/205011/SQL-Server-Database-Comparison-Tool
That should give flexibility as code is available.
dbghost is the best i have used to date. one of the best features i have seen is that it will generate SQL code to go between versions of a database based on the SQL you keep in source control, as well as a database. simple and easy to use.
I've used SQL Delta before (http://www.sqldelta.com/), it's really good. Not free however, not sure how prices compare to Red-Gates
Try DBComparer, it's free and fast:
http://dbcomparer.com/
Database Workbench can made it too
http://www.upscene.com/products.dbw.index.php
Cross database development
Use the Schema Compare and Migration
Tools to compare testing and deployed
databases, migrate existing databases
to different database systems.
you can also made it with database Comparer
http://www.clevercomponents.com/products/dbcomparer/dbcomparer.asp
I use it for Firebird and it works well.
Try dbForge Data Compare for SQL Server. It can compare and sync any databases, even very large ones. Quick, easy, always delivers a correct result.
Try it on your database and comment upon the product.
We can recommend you a reliable SQL comparison tool that offer 3 time’s faster comparison and synchronization of table data in your SQL Server databases. It's dbForge Data Compare for SQL Server and dbForge Schema Compare for SQL Server
Main advantages:
Speedier comparison and synchronization of large databases
Support of native SQL Server backups
Custom mapping of tables, columns, and schemas
Multiple options to tune your comparison and synchronization
Generating comparison and synchronization reports
Plus free 30-day trial and risk-free purchase with 30-day money back guarantee.
We are using an inhouse developed solution that is basicly a procedure with arguments of what you want included in the comparision (SP's, Full SP code, table structure, defaults, indices, triggers.. etc)
Depending on your needs and budget, it might be a good way to go for you as well.
It is quite easily developed as well, then we just redirect output of procedure to textfiles and do text comparisions between the files.
One good thing about it is that its possible to save the output in source control.
/B
I've used Red Gate's tools and they are superb.
However, if you can't spend any money you could try Open DBDiff to compare schemas.
I would definitely go with AdeptSQL if you're using MSSQL. It's the least good looking but the most talented db compare tool amongst the ones I've tried. It can compare both the structure and the data. It tells you which tables exist on one db but does not exist on the other, compares the structure and data of the common ones and it can produce the script to synchronize the two. It's not free but has a 30 day trial (as far as I can remember)
I tried OpenDiff Tool . Great tool that is free and easy to use .

Why should I upgrade from SQL2000 to SQL2005?

I'm looking for the single biggest reason you are glad that you've already made the jump from SQL2000 to SQL2005.
Recursion without creating temporary tables.
Native Exception support (Try/Catch instead of if #Error goto)
Because:
Microsoft would like to remind customers that support for SQL Server 2000 Service Pack 3a (SP3a) will end on July 10, 2007.
Native XML support is big for us here.
SSIS support. Blows DTS away and is quite handy. :)
SSRS - A really huge advantage for my organization is having the free reporting tools that come with SQL Server 2005. Reporting Services allows me to produce nice looking reports that have exactly the fields that our managers need in very little time. It has a built in tool so they can convert to excel, pdf, or several other formats. Lots of value here.
SSIS - Integration services in 2005 is very powerful for ETL (export, transform, load) functions. You can set up automated processes to run on a schedule.
SSAS - Analysis services looks promising. I have not made any data cubes yet because I want to organize an actual data warehouse. Once you have that, robust data mining algorithms are already built in.
Take a look at these three tools that are included with SQL Server 2005. If i had to pick one as the single biggest reason to move to 2005, it would be SSRS.
At this point, I would suggest looking at SQL Server 2008.
Pagination without (manually) creating temporary tables is a basic, but huge improvement.
However, if you are then going to drag & drop some GridViews in your ASP.NET app directly from the data table, you'd be paging in the app...
CLR integration
Row Versioning-Based Transaction Isolation
I think the single biggest reason is that SQL 2000 is not supported on Vista. I had to move to SQL 2005 because of that.
I don't know if it's just me, but Linq2SQL doesn't exactly work perfectly with SQL 2000. Ordinarily its supposed to automatically generate and populate child collections based on inferences from your schema's keys, foreign keys, RI, etc. Works fine in 2005 but i haven't had much luck in 2000.
Common Table Expressions have proven incredibly useful.
Exception handling... how did we ever manage on SQL 2000...?
PIVOT. That beautiful little statement has saved me more time then any other SQL Server 2005 enhancement.
YOU CAN'T EXPORT TABLES with a "right click" anymore. This is more of a problem than a good reason.
Dynamic Management Views
for Optimisation and to quickly find out the state of the server.