SELECT EmployeeID, EmployeeName, Email, BirthDate
FROM Employee
WHERE DATEDIFF(w, BirthDate, GETDATE()) = 0
Saturday, November 14, 2009
Get all employees have birthday this week
Labels: SQL Server, SQL Server Tip
Get top 10 customers by revenue
Using TOP keyword.
SELECT TOP 10 CustomerID, CustomerName, Revenue
FROM dbo.Customer
ORDER BY Revenue DESC
Labels: SQL Server, SQL Server Tip
Get all customers established this month
SELECT CustomerID, CustomerName, EstablishedDate, Email, Address
FROM dbo.Customer
WHERE DATEDIFF(m, EstablishedDate, GETDATE()) = 0
Labels: SQL Server, SQL Server Tip
Try/Catch in T-SQL
Applied from SQL Server 2005
BEGIN TRY
BEGIN TRAN
--Your T-SQL code here
COMMIT TRAN
END TRY
BEGIN CATCH
DECLARE @ErrorMessage NVARCHAR(4000);
SELECT @ErrorMessage = ERROR_MESSAGE();
ROLLBACK TRAN;
RAISERROR(@ErrorMessage, 16, 1);
END CATCH
Labels: SQL Server 2005, SQL Server 2008, SQL Server Tip
Using cursor
DECLARE Cur CURSOR FOR
SELECT AccountID, AccountName
FROM Account
OPEN Cur
FETCH FROM Cur
INTO @AccountID, @AccountName
WHILE @@FETCH_STATUS = 0
BEGIN
--Do your tasks here
FETCH FROM Cur
INTO @AccountID, @AcountName
END
CLOSE Cur
DEALLOCATE Cur
Labels: SQL Server, SQL Server Tip
Friday, November 13, 2009
A six-part series on getting the most out of SharePoint Designer 2007
As a DBA, I think you also need some knowledge about SharePoint and SharePoint Designer so that you can use it to modify your SharePoint site when necessary. You can read this article for more detail A six-part series on getting the most out of SharePoint Designer 2007.
Labels: SharePoint, SharePoint Designer
Monday, November 9, 2009
Delete all foreign keys in a database
DECLARE @Table VARCHAR(255)
DECLARE @ForeignKey VARCHAR(255)
DECLARE @STRSQL VARCHAR(8000)
DECLARE Cur CURSOR FOR
select t1.name as [Table], t2.name as [ForeignKey]
from sysobjects t1 inner join
sysobjects t2 on t1.id = t2.parent_obj
where t1.xtype = 'U' and t2.xtype = 'F'
OPEN Cur
FETCH FROM Cur
INTO @Table, @ForeignKey
WHILE @@FETCH_STATUS = 0
BEGIN
SET @STRSQL = 'ALTER TABLE ' + @Table +
' DROP CONSTRAINT ' + @ForeignKey
EXECUTE(@STRSQL)
FETCH FROM Cur
INTO @Table, @ForeignKey
END
CLOSE Cur
DEALLOCATE Cur
Labels: SQL Server, SQL Server 2000, SQL Server 2005, SQL Server Tip
Friday, October 9, 2009
Get table script
You can use this function dbms_metadata.get_ddl to generate the create script of your table.
SELECT dbms_metadata.get_ddl('TABLE', 'Your table', 'Your owner')
FROM dual;
Labels: Oracle, Oracle Query, PL/SQL
Tuesday, October 6, 2009
Active Directory Maximum Limits - Scalability
Do you know the limitation of Active Directory? If not, please read this article Active Directory Maximum Limits - Scalability
