Search This Blog

Tuesday, December 16, 2014

Restart Computer rule falied

While installing sql server 2008 you might get error: Restart Computer Failed


Cause : A previous program installation created pending file operations on the installation machine.
Solution: 1. Go Registry path "Open HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager".


2. Double click "PendingFileRenameOperations"


3. Press the key "Delete" on your keyboard.

4. Press OK and close the registry.
5. Try now to run SQL Server 2008 setup

Tuesday, August 19, 2014

List of valid and Invalid special characters for URL.

Character Purpose in URL Encoding
: Separate protocol (http) from address %3A
/ Separate domain and directories %2F
# Separate anchors %23
? Separate query string %3F
& Separate query elements %24
@ Separate username and password from domain %40
% Indicates an encoded character %25
+ Indicates a space %2B
<space> Invalid in URLs %20 or +
; Invalid in URLs %3B
= Invalid in URLs $3D
$ Invalid in URLs %26
, Invalid in URLs %2C
< Invalid in URLs %3C
> Invalid in URLs %3E
~ Invalid in URLs %25
^ Invalid in URLs %5E
` Invalid in URLs %60
\ Invalid in URLs %5C
[ Invalid in URLs %5B
] Invalid in URLs %5D
{ Invalid in URLs %7B
} Invalid in URLs %7D
| Invalid in URLs %7C
" Invalid in URLs %22

Thursday, August 14, 2014

How to remove Cache and Buffers in MS SQL Server

To remove procedure/TSQL cache and buffers execute below queries.

DBCC FREEPROCCACHE
DBCC DROPCLEANBUFFERS

Thursday, January 23, 2014

How to rename a column name or table name in sql

1. You can rename column name as below:
sp_Rename 'tblusers.Name' , 'UserName', 'column'

2. Using below sql statement you can change object name ( table name, stored procedure name..etc)
sp_Rename 'tblusers', 'tblGlobalUsers'

Friday, January 17, 2014

how to delete top n records using sql delete statement?

DELETE top (n) FROM Table1
Note : This statement will work in sql server 2005 and above but for below version use following sql statement

DELETE tbl FROM (Select Top n * FROM Table1 ) tbl

Sunday, June 16, 2013

How to delete referential records from a sql table?

If there is a foreign key relationship between two table then you can not delete a record which is referenced by another table.

Solution:
Use On DELETE CASCADE

Example:
Alter Table Employee
DROP Constraint FK_Employee_Department
GO
ALTER Table Employee
Add Constraint FK_Employee_Department Foreign key (DeptID)
References Department(id)
On DElete Cascade


Note: If you delete a record from department table then all the associated records from Employee will be deleted.

How to find missing Identity id from a sql table?

Below is the sql statement to find the missing identity Id from sql table '#tmp1'
'#tmp1' content
IDName
1Arvind
2Kapil
5Mohit
8Rakesh


SQL Statement
With missing as
(
Select 1 as mins, max(Id) as maxs from #tmp1
UNION ALL
Select mins + 1 , maxs from missing m
--Inner join #tmp1 t ON t.ID = m.mins
where mins < maxs
)
Select * from missing m
left outer join #tmp1 t ON t.ID = m.mins
where t.Id is null

Missing Identity

IDName
3Raj
4Mangesh
6Rajesh
7Ravindra