Monday, October 13, 2008

Attaching SQL Server .mdb without .ldf file

If you're using SQL Server 2005:
create a database of equal size to the one you're trying to attach
shutdown the server
swap in the old mdf file
bring up the server and let the database attempt to be recovered and then go into suspect mode
put the database into emergency mode with ALTER DATABASE
run DBCC CHECKDB (dbname, REPAIR_ALLOW_DATA_LOSS) which will rebuild the log and run full repair
Your database will be available again but you'll have lost data and the data won't be transactionally consistent - see the following blog posts:
https://blogs.msdn.com/sqlserverstorageengine/archive/2006/06/15/632398.aspx
https://blogs.msdn.com/sqlserverstorageengine/archive/2006/06/16/633645.aspx
https://blogs.msdn.com/sqlserverstorageengine/archive/2006/06/18/636105.aspx
If you're on SQL Server 2000, you can still do this but you'll need to use the undocumented DBCC REBUILD_LOG at your own risk.

original post on MSDN

Labels:

Monday, August 6, 2007

Too Many Stored Procedures

Is there such a thing as Too Many Stored Procedures?
Jeff Atwood at Coding Horror makes some great points that reflect my own thoughts over at:
http://www.codinghorror.com/blog/archives/000117.html

I think SQL Server's Object Explorer needs to have a built-in mechanism for managing the thousands of stored procedures that occupy a database, instead of trusting that a sensible naming convention will be used.  In my experience, eventually any naming convention breaks down after time, as new developers and technologies arrive.

Linked to in Atwood's post is this by Frans Bouma, who seems to be the main promoter of cautionary use of Stored Procedures: http://weblogs.asp.net/fbouma/archive/2003/11/18/38178.aspx

Labels: , ,

Friday, June 15, 2007

T-SQL Searching through the schema

For SQL Server 2005:


Some examples:
select * from sys.objects
select * from sys.sql_modules <-- Stored Procedures and Views
select * from sys.columns
select * from sys.triggers


Searching the text of all stored procedures:
select o.name from sys.sql_modules m
inner join sys.objects o
on m.object_id = o.object_id
where m.definition like '%string you are looking for%'

Searching for tables that contain the column (field) you want:
select a.name
from sys.objects a
inner join sys.columns b
on a.object_id = b.object_id
where b.name='column name you are looking for'

For SQL Server 2000:


Searching the text of all stored procedures:
select object_name(id)
from syscomments
where objectproperty(id,'IsProcedure') = 1
and [text] like '%string you are looking for%'

Labels: , ,