Posts

Showing posts from February, 2013

Select n random rows from SQL Server table

select top 10 percent * from [yourtable] order by newid() In response to the "pure trash" comment concerning large tables: you could do it like this to improve performance. select * from [yourtable] where [yourPk] in (select top 10 percent [yourPk] from [yourtable] order by newid()) The cost of this will be the key scan of values plus the join cost, which on a large table with a small percentage selection should be reasonable.

Verifying that a string contains only letters in C#

Only letters: Regex.IsMatch(input, @"^[a-zA-Z]+$"); Only letters and numbers: Regex.IsMatch(input, @"^[a-zA-Z0-9]+$"); Only letters, numbers and underscore: Regex.IsMatch(input, @"^[a-zA-Z0-9_]+$");

Reset Identity column after deleting record from table

DBCC CHECKIDENT can reseed (reset) the identity value of the table. For example, YourTable has 25 rows with 25 as last identity. If we want next record to have identity as 35 we need to run following T SQL script in Query Analyzer DBCC CHECKIDENT (yourtable, reseed, 34)

The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine

changed the application configuration to x86