ict.ken.be

Delivering solid user friendly software solutions since the dawn of time.

Moving SQL table with text or image to a new filegroup 

Categories: SQL Server
  • In MS SQL Management Studio click "Tools - Options - Designer" and UNcheck the "Prevent saving changes that require table re-creation" box.
  • Right-click the table and select "Design" for SQL 2008 or "Modify" for SQL 2005.
  • Press F4 to open the "properties" window.
  • Make sure that you have the table (!) selected on top of the "properties" window.
  • Change the "text filegroup" for the table.
  • DO NOT save your changes. The SQL-server most likely will throw a timeout error for your large table.
  • Instead choose "Generate change script" and copy the resulting text to the new query window.
  • Run the query.
  • Be patient. 

Thanks to http://blog.jitbit.com

Tables by column name 

Categories: SQL Server

select o.name, *
from sys.columns c
inner join sys.objects o on o.object_id = c.object_id
where c.Name = N'COLUMN_NAME_TO_FIND'

 

--get all with table row count

CREATE TABLE #foo(name varchar(128),rows int)

DECLARE @objectName nvarchar(128)

DECLARE cursorTables CURSOR FOR

select o.name 

from sys.columns c

inner join sys.objects o on o.object_id = c.object_id

where c.Name = N'u_username'

OPEN cursorTables

FETCH NEXT FROM cursorTables INTO @objectName

WHILE @@FETCH_STATUS = 0

BEGIN

INSERT INTO #foo

EXEC ('SELECT ''' + @objectName + ''' as NAME,COUNT(*) FROM ' + @objectName)

FETCH NEXT FROM cursorTables INTO @objectName

END 

CLOSE cursorTables

DEALLOCATE cursorTables

SELECT * FROM #foo ORDER BY rows DESC

DROP TABLE #foo

Objects recently created 

Categories: SQL Server

select top 100 *
from sysobjects o (NOLOCK)
where xtype in ('U')
order by crdate desc

select top 100 *
from sysobjects o (NOLOCK)
where xtype in ('V')
order by crdate desc

select top 100 *
from sysobjects o (NOLOCK)
where xtype in ('P')
order by crdate desc

Page 39 of 43 << < 20 32 33 34 35 36 37 38 39 40 41 42 43 > >>