Răzvan Cosma's scratchpad

random scripts of random value

Browsing Posts in SQL

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)) + ‘) ‘ […]


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 (“”, “user”, “pass”) or die (“Could not connect to SQL server”); //.mssql_get_last_message() mssql_select_db (“thedb”, $con) or […]

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’

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 141 access attempts in the last 7 days.