| There was a great event held by Microsoft and PASS (Professional Association of SQL Server) in Ahmedabad on 3rd October 2009. This was very big event where 250+ attendees attend the excellent session of Vinod Kumar, Pinal Dave, Jacob Sebastian and Prabhjot Singh Bakshi. There were Four technical sessions by these excellent speakers. First session is of Vinod Kumar. He is Microsoft Evangelist. There was excellent session of Three hours where he give features of Windows 7 and Office 2010. Second session is of Pinal Dave, SQL MVP. He presented session on the subject - "SQL Server - The Other Side of Index". This was also excellent way to know more about SQL Index. and How to use index. That is really nice session for SQL Developers to know, How to optimize query. It gives proper understanding of indexes. Third session is of Jacob Sebastian, SQL MVP. He presented session on '"The Best Practices for Exception Handling and Defensive Programming in Microsoft SQL Server". This was also very great session where developer can get more idea about When exception occur and how to handle that exception. It was presented in a way so all attendees get clear idea about it and understand it properly. Forth and last session is of Prabhjot Singh Bakshi, MCT(Microsoft Certified Trainer). He presented session on "NET Framework 4.0". He also presented very nice session about featured of .Net Framework 4.0. He developed .Net code to give clear understanding of new features. Click with Vinod kumar and Jacob Sebastian: Overall, that was excellent day for Ahmedabad. I hope this type of TechDays scheduled in near future. Reference: Tejas Shah ( http://www.SQLYoga.com) |
Learn SQL and database management at SQLYoga for articles, tutorials, and tips to improve your skills and streamline data operations. Join our community!
October 7, 2009
Community TechDays at Ahmedabad - Great Event
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS
September 16, 2009
SQL SERVER: Agenda of Community TechDays at Ahmedabad
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS
September 15, 2009
SQL SERVER: Community Tech Days in our City at Ahmedabad on 3rd October 2009
| Microsoft Community Tech Days are in 11 cities in INDIA with 19 insightful Technical Sessions. These insightful Technical sessions are available in our city "Ahmedabad", Gujarat on 3rd October 2009. So book your calendar for this day and be a part of this TechDays. Limited seats are available , so please register yourself with this event: |
|
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS
September 5, 2009
SQL SERVER: Difference between DELETE and TRUNCATE commands
| We interviewed many people my company as recruitments are going on for developers. When I asked this SQL SERVER question to person "What is difference between DELETE and TRUNCATE in SQL SERVER?". I got the following answers from most of them are, which are incorrect: 1. I can not use WHERE condition with TRUNCATE command 2. I can not use TRUNCATE command if foreign key is there on table. 3. TRUNCATE is faster than the DELETE, as DELETE write records them in Log file in case it is needed to rollback in future from LOG files. etc.. These answers are correct. I also got this answer, which is Incorrect: "DELETE can be rolled back while TRUNCATE can not be rolled back" I asked them what does it mean?, give me an example. See what they say, if I have Transaction and if I have used DELETE then ROLLBACK will let them back to original state. In case of TRUNCATE within Transaction, will not allow me to original state. This is incorrect. We can ROLLBACK changes made by DELETE and TRUNCATE if the it is used in Transaction. Lets see this in detail by example: Create one table table and insert some data in it like: CREATE Test TABLE(ID INT IDENTITYText VARCHAR(5))GOINSERT INTO Test(Text) VALUES('A')INSERT INTO Test(Text) VALUES('B')INSERT INTO Test(Text) VALUES('C')INSERT INTO Test(Text) VALUES('D')GO Lets try to use TRUNCATE within Transaction as follows: So, we found that we can found all values in the table. We can ROLLBACK the TRUNCATE command as same as other commands.BEGIN TRAN --Start TransactionTRUNCATE TABLE Test --Use this command--Check the data from table. See transaction is still in progress not commit/Rollback yet This is place where most of the developers can not give accurate answer. I hope by this article they can have clear idea. Let me know if there is any confusion. CONCLUSION: DELETE and TRUNCATE both can be rolled back when used with TRANSACTION. If Transaction is done, means COMMITED, then we can not rollback TRUNCATE command, but we can still rollback DELETE command from LOG files, as DELETE write records them in Log file in case it is needed to rollback in future from LOG files. Reference: Tejas Shah( http://www.SQLYoga.com ) |
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS
August 12, 2009
SQL SERVER: Check if Node exists in XML or not
| Today, I have one requirement to check dynamically if a node exists in my xml or NOT. I have a stored procedure that receives XML and I need to check if the message information xml contains one Node or NOT. If that node exists then I need to execute that Stored Procedure by different logic and if not it should run with different logic. I figure it out by using EXISTS. This is my XML, that I got as parameter. Now I need to check if "BulkData" node exists in XML, then I need to write different logic to get the result.DECLARE @ExportData XMLSELECT @ExportData ='<Data Number="A123"><BulkData><EachData Parts="Test1" /><EachData Parts="Test2" /><EachData Parts="Test3" /></BulkData></Data>' So, I used this This will return "1" if node is exists else return "0".SELECT @ExportData.exist('(//BulkData)') That's it. I can write based on the return result by this statement. Let me know if it helps you. Reference : Tejas Shah(http://www.SQLYoga.com) |
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS
July 31, 2009
SQL SERVER: Use CONTEXT_INFO
CREATE TABLE tblA( ID INT IDENTITY, ColVal VARCHAR(100) )
CREATE PROC TestA
AS
BEGIN
INSERT INTO tblA(ColVal)
SELECT 'Allow To insert'
END
CREATE PROC TestB
AS
BEGIN
DECLARE @UID VARBINARY(128)
SELECT @UID = CAST('TestB' AS VARBINARY(128))
SET CONTEXT_INFO 0x5465737442
INSERT INTO tblA(ColVal)
SELECT 'Not Allow To insert'
END
CREATE TRIGGER trg_TblA
ON tblA
AFTER INSERT,DELETE,UPDATE
AS
BEGIN
SET NOCOUNT ON;
DECLARE @Message varbinary(128)
SELECT @Message = cast('TestB' as varbinary(128))
IF @Message = CONTEXT_INFO() BEGIN
RAISERROR('Not Allowed to Insert/Update/Delete from SP: TestB',15,1)
ROLLBACK TRAN
END
END
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS
July 15, 2009
SQL SERVER: Reset Setup Values, when SQL SERVER is started/restarted
| We have a requirements to clear all setup values when SQL SERVER is started/restarted and we need to setup default values to setup table. I found one Stored Procedure provided by MS SQL SERVER. Let me share it with all of you. SQL SERVER provides this SP: “sp_procoption”, which is auto executed every time when SQL SERVER service has been started. I found this SP and it helps me to figure it out the solution for the request as following way. Let me show you how to use it Syntax use this SP: EXEC SP_PROCOPTION @ProcName, should be Stored procedure name which should be executed when SQL SERVER is started. This stored procedure must be in “master” database. @OptionName, should be “startup” always. @OptionValue, this should be set up to execute this given sp or not. If it is “true/on”, given sp will be execute every time when SQL SERVER is started. If it is “false/off”, it will not. That’s it, lets take an example. I have one Database called Test, I have created setup table: CREATE TABLE SetupTable( Lets insert some default values to this table: INSERT INTO SetupTable VALUES('A') What I need to do is, I need to wipe out this values when SQL SERVER is started and fill it with the same default values, because these values might be updated by application.So, I created one stored procedure in master database, named, CREATE PROC ClearAllData and set up this stored procedure as auto executed every time when SQL SERVER is started as: EXEC SP_PROCOPTION Now, restart SQL SERVICES, and you find that old values will be deleted and new values with ‘X’, ‘Y’, and ‘Z’ will be inserted automatically. If now you want to stop it to execute automatically, we just need to execute this with “false” as: EXEC SP_PROCOPTION I hope this is very clear to use this feature. Reference : Tejas Shah (http://www.SQLYoga.com) |
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS
May 12, 2009
SQL SERVER: Configure Database Mail with SQL SERVER 2005
We used Database mail to send mail to client on each updates.
This is a very simple process to configure. Let me share how to configure Database mail with sql server 2005 with all of you.
After setting up Profile and Account properly, you just need to write following code to send a mail to client:
Step 1:
Step 2:
Step 3:
Step 4: You might get this message:
Step 5: Create Profile
Step 6 : Create Account
That's it.
exec msdb.dbo.sp_send_dbmail
@profile_name = 'ProfileName', IN our CASE, 'Tejas'
@recipients = 'Client Email Address' ,
@blind_copy_recipients = 'BCC Address',
@subject = 'Subject',
@BODY = 'Message Body',
@body_format = 'Message Type', it could be text OR html
Let me know if you have any complexity or comments in setting up Database mail.
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS
May 4, 2009
SQL SERVER: Read values from Comma Separated variable
SET @xmlIDs = '' ' + REPLACE(@str, ',', ' ') + ' ' + '
1 6 7 8 20
SELECT x.v.value('.','INT')
FROM @xmlIDs.nodes('/IDs/ID') x(v)
CREATE PROC Test_ReadValuesFromCommaSeparatedVariable
@str VARCHAR(100)
AS
DECLARE @XmlIDs XML
SET @xmlIDs = '
' + REPLACE(@str, ',', ' ') + ' ' +
' '
UPDATE TableName
SET Flag = 1
WHERE ID IN(
SELECT x.v.value('.','INT')
FROM @xmlIDs.nodes('/IDs/ID') x(v)
)
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS
April 26, 2009
SQL SERVER - Query to compare number of Rows between different Databases
| We have two databases in the same SQL server instance. Both of the databases are copy of the production database, so both contains same tables. We added some records in Test Database’s some tables to update some features. We have added data in many tables of test database. Now we need to also update Production DB with the updated data. To update Production Database, we need to make sure in which tables we have updated data and then we will check and update production database accordingly. We have many numbers of tables, and we have updated many tables, so its not possible for us to check it manually. So, we need to make query to compare rows of each table with the another database tables, to find out which tables has different rows then the original database. Solution: As I need to solve this problem, I write a query which will give me Rows of each table in one Database. As I need to compare it with another database I write the following query to come out with the solution. Example: I have two databases. Database A and Database B. I need to make a report, which will give me details of each table and rows. I made this Stored Procedure in Database A. CREATE PROC CompareRowsBetweenDatabas This will give me results as I need. Let me know if it helps you. |
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS