Find / change the datatype for multiple columns/tables

Find all columns of type datetime: DECLARE @DataType VARCHAR(50) SELECT @DataType = ‘datetime’ SELECT * FROM Information_Schema.Columns WHERE Data_Type = @DataType order by table_name Find all varchar columns, change to nvarchar: — SQL 2005 SELECT ‘ALTER TABLE ‘ + quotename(o.name) + ‘ ALTER COLUMN ‘ + quotename(c.name) + ‘ nvarchar(‘ + ltrim(str(c.max_length)) + ‘) ‘ […]

How to connect to MS SQL from PHP

1. Install FreeTDS. (./configure && make && make install) 2. Install PHP with freetds support (./configure –with-sybase=DIR, where DIR is wherever you placed freetds usually /usr/local) 3. Read a bit of /etc/freetds.conf (not mandatory) 4. ini_set(‘mssql.secure_connection’,’On’); $con = mssql_connect (“1.2.3.4”, “user”, “pass”) or die (“Could not connect to SQL server”); //.mssql_get_last_message() mssql_select_db (“thedb”, $con) or […]

How (the fuck) do I link two instances of SQL Server using the Management Studio?

Never thought I’ll actually miss Enterprise Manager, but the newer one is even more confusing. So – no clue so far how to do such a simple task via the graphical interface, just execute the stuff below: EXEC master.dbo.sp_addlinkedserver @server = N’server.domain.com\instance,tcport’, @srvproduct=N’SQL Server’ EXEC master.dbo.sp_addlinkedsrvlogin N’server.domain.com\instance,tcport’, false, null, ‘sa’, ‘thesapassword’

How to generate passwords for a list of users?

Ugly hack set nocount on declare @a int declare @b varchar(128) set @a=0 drop table #rp create table #rp(p varchar(128)) While 1=1 Begin set @a=(Select Min(theindexfield) from thetable Where theindexfield>@a) If @a is null break else delete from #rp insert into #rp exec random_password 8,’simple’ update thetable set thepassfield=(select p from #rp) where id=@a continue […]

Bad Behavior has blocked 207 access attempts in the last 7 days.