Counter of Festivals

Ashok Blog for SQL Learners and Beginners and Experts

Wednesday, 12 December 2012

Rajinis Special 12.12.12 Birthday

சூப்பர் ஸ்டார் ரஜினியின் ரசிகர்களுக்கு 12.12.12 ஒரு சூப்பர் நாள். 100ஆண்டுகளுக்கு ஒருமுறை வரும் அபூர்வ நாள் என்பதால் மட்டுமல்ல, தமிழ் சினிமாவில் அபூர்வ ராகமாக ஒலித்த ரஜினியின் பிறந்த நாள். 12.12.12 என்பதை கூட்டினால் 36. சூப்பர் ஸ்டார் திரைப்படத்துக்கு வந்து 36 ஆண்டுகளை கடந்து விட்டார். 36ஐ அப்படியே திருப்பிப் போட்டால் 63 அதுதான் அவருக்கு வயது. அதுமட்டுமல்ல மரணத்தின் வாயிலை எட்டிப்பார்த்துவிட்டு அதை எட்டி உதைத்துவிட்டு திரும்பியிருக்கும் சூப்பர் ஸ்டார் மறுபிறவிக்கு இது முதல் பிறந்த நாள். இப்படி பல சிறப்பு அம்சங்களுடன் பிறக்கிறது 12.12.12. சூப்பர் ஸ்டாரின் சினிமா பயணம் 1975ல் தொடங்கியது. அன்று முதல் இன்று வரையிலான அவரது சினிமா பாதையில் கற்களும், முற்களும் நிறைந்திருந்தது. பூக்களும் கொட்டிக் கிடந்தது. அதிலிருந்து தேர்ந்தெடுக்கப்பட்ட 36.

1. ரஜினி நடித்த முதல் படம் அபூர்வ ராகங்கள். அதில் அவர் பேசிய முதல் வசனம் "பைரவி வீடு இதுதானே..."என்பது தான்.  நடித்த காட்சிகள் 6.

2. ரஜினி சிகரெட் ஸ்டைல் மிகவும் புகழ்பெற்றது. அது அறிமுகமான படம் மூன்று முடிச்சு.

3. வில்லனாக நடித்துக் கொண்டிருந்த ரஜினி ஹீரோவாக நடித்த படம் பைரவி. இதில்தான் அவருக்கு சூப்பர் ஸ்டார் பட்டம் வழங்கப்பட்டது. வழங்கியவர் கலைப்புலி எஸ்.தாணு. நான் போட்ட சவால் படத்தின் டைட்டில் கார்டில்தான் சூப்பர் ஸ்டார் என்ற பட்டம் போடப்பட்டது.

4. ரஜினி பேசிய முதல் பன்ஞ் டயலாக் "இது எப்படி இருக்கு?: படம் 16 வயதினிலே. இந்த வசனத்தையே "ஹவ் இஸ் இட்?" என்று ஆங்கிலத்திலும், "இப்புடு சூடு" என்று தெலுங்கிலும் பின்னாளில் பேசினார். இந்த பன்ஞ் டயலாக்கை தலைப்பாக வைத்து ஒரு படமும் வெளிவந்தது.

5. மூன்று முடிச்சு தொடங்கி எந்திரன் வரை பல படங்களில் வில்லனாக நடித்திருந்தாலும் கொடூர வில்லனாக நடித்தது ஆடுபுலி ஆட்டம் படத்தில்தான். வில்லத்தனங்களை செய்து விட்டு "இது ரஜினி ஸ்டைல்" என்பார்.

6. ரஜினி நடித்த முதல் திகில் படம் ஆயிரம் ஜென்மங்கள். நீண்ட இடைவெளிக்குப் பிறகு நடித்த படம் சந்திரமுகி.

7. ரஜினி நடிக்க மறுத்த படம் "நீயா?" ஸ்ரீப்ரியாவின் சொந்தப் படத்தில் அவர் ரஜினியை நடிக்க கேட்டபோது நான்கைந்து ஹீரோக்களுடன் நடிக்க மாட்டேன் என்று மறுத்து விட்டார். பின்னர் அந்த கேரக்டரில் நடித்தவர் கமல்.

8. பிராமண லாங்குவேஜ் பேசி நடித்த படம் சதுரங்கம், சென்னைத் தமிழ் பேசி நடித்த படம் தப்புத் தாளங்கள்.

9. வணக்கத்துக்குரிய காதலியே ரஜினியின் முதல் தோல்விப் படம்.

10. ரஜினிக்கு பிடித்த படம் "முள்ளும் மலரும்". பிடித்த இயக்குனர் "மகேந்திரன்". பிடித்த நடிகர் "கமல், பிடித்த நடிகை "ஷோபா.

11. சிவாஜியுடன் நடித்த முதல் படம் "ஜஸ்டிஸ் கோபிநாத்". இதில் அவர் சிவாஜியின் வளர்ப்பு மகனாக நடித்தார். பிற்காலத்தில் சொந்த மகன் போல் சிவாஜியால் பார்க்கப்பட்டார். அவருடன் நடித்த கடைசிப் படம் "படையப்பா".

12. முதல் பேண்டசி படம் "அலாவுதீனும் அற்புத விளக்கும்". இதில் கமல் அலாவுதீனாக நடித்தார். ஒரிஜினல் கதையில் இல்லாத கமருதீன் என்ற கேரக்டர் ரஜினிக்காக உருவாக்கப்பட்டது.

13. முதன் முதலில் இரட்டை வேடத்தில் நடித்த படம் "பில்லா". மூன்று வேடங்களில் நடித்த படம் "மூன்று முகம்".

14. குறுகிய காலத்தில் நடித்த படம் "அன்புள்ள ரஜினிகாந்த்". 6 நாட்களில் நடித்துக் கொடுத்தார். 9 நாட்களில் நடித்த படம் "மாங்குடி மைனர்".

15. மேனியாக் டிப்ரெசிங் நோயால் பாதிக்கப்பட்டு அதிலிருந்து குணமான பிறகு நடித்த படம் "தர்மயுத்தம்". அந்தப் படத்திலும் அந்த நோயால் பாதிக்கப்பட்டவராகவே நடித்தார்.

16. முதல் சினிமாஸ்கோப்  படம் "பொல்லாதவன்". முதல் 70எம்எம் படம் "மாவீரன்". முதல் 3டி படம் "சிவாஜி". முதல் அனிமேஷன் படம் "கோச்சடையான்".

17. ரஜினி தயாரித்த முதல் படம் "மாவீரன்". திரைக்கதை வசனம் எழுதிய படம் "வள்ளி". பாடல் பாடிய படம் "மன்னன்".

18. எம்.ஜி.ஆரின் போஸ்ட்டரை பார்த்து வீரம் வந்து சண்டை போடுபவராக, அவரது ரசிகராக நடிக்க மறுத்தார். இன்னொருவர் புகழில் குளிர்காயக்கூடாது என்பது அவரது கருத்து.

19. "பாண்டியன்", "அருணாசலம்" படங்கள் தன் நண்பர்களுக்காக ரஜினி நடித்துக் கொடுத்த படம்.

20. ரஜினியின் அதிக படங்களை இயக்கியவர் எஸ்.பி.முத்துராமன். அதிக படங்களில் ஜோடியாக நடித்தவர் ஸ்ரீப்ரியா. அதிக படங்களுக்கு கதை வசனம் எழுதியவர் பஞ்சு அருணாசலம்.

21. ரஜினியின் 50வது படம் "டைகர்(தெலுங்கு)". 100வது படம் "ஸ்ரீராகவேந்திரர்". ரங்கா படத்தில் ரஜினியின் அக்காவாக ஜெயலலிதா நடிப்பதாக இருந்தது. எம்.ஜி.ஆர் அவரை அரசியலுக்கு அழைத்துச் சென்றதால் நடிக்கவில்லை. ஸ்ரீராகவேந்திரர் படத்தை எஸ்.பி.முத்துராமன் இயக்க மறுத்தார். பின்னர் ரஜினியின் அன்புக்காக இயக்கினார்.

22. எம்.ஜி.ஆர் நடிக்க இருந்த படம் "ராணுவ வீரன்". அவர் முதல்வரானதால் நடிக்க முடியாமல் போக அந்தக் கதையில் ரஜினி நடித்தார்.

23. ரஜினி நடித்த சில படங்களின் பெயர்கள் கடைசி நேரத்தில் மாற்றப்பட்டது. "நானே ராஜா நீயே மந்திரி" என்ற டைட்டில் "தம்பிக்கு எந்த ஊரு" என்று மாறியது. "நான் காந்தி அல்ல", "நான் மகான் அல்ல" என மாறியது. "காலம் மாறிப்போச்சு" என்ற டைட்டில் "தர்மதுரை" ஆனது.

24. முதன் முதலாக ஜப்பான் மொழியில் டப் செய்யப்பட்ட இந்திய படம் "முத்து". ஜப்பானில் ரசிகர் மன்றம் தொடங்கப்பட்ட முதல் இந்திய நடிகர் ரஜினி.

25. ரஜினி எடிட் செய்த படம் "படையப்பா". படப்பிடிப்பு முடிந்து பார்த்தபோது படம் 21 ஆயிரம் அடி வந்திருந்தது. எந்தக் காட்சியையும் குறைக்க முடியவில்லை. படத்துக்கு 2 இடைவேளை விடலாமா என்று யோசித்தார்கள். தான் நடித்த காட்சிகளை வெட்டத் தயங்குகிறார்கள் என்று நினைத்த ரஜினி. தானே எடிட்டிங்கில் உட்கார்ந்து காட்சிகளை குறைத்தார். இதுபற்றி அவர் சொன்ன கருத்து "ரசிகனை ரொம்ப கொடுமைப்படுத்தக்கூடாது" என்பது.

26. அதிக நாள் ஓடிய படம் "சந்திரமுகி". அதிக பட்ஜெட்டில் எடுக்கப்பட்ட படம் "எந்திரன்". குறைந்த பட்ஜெட்டில் எடுக்கப்பட்ட படம் "அன்புள்ள ரஜினிகாந்த்".

27. "மூன்று முடிச்சு", "மாப்பிள்ளை", "மன்னன்", "படையப்பா" படங்களில் ரஜினியோடு மோதுபவர்கள் பெண்கள்.

28. "முள்ளும் மலரும்", "மூன்று முகம்", "முத்து", "படையப்பா", "சந்திரமுகி", "சிவாஜி" படங்களுக்காக மாநில விருதைப் பெற்றார். பத்மஸ்ரீ, பத்மபூஷன் மத்திய அரசு வழங்கிய விருதுகள்.

29. மீசையில்லாமல் நடித்த முதல் படம் "தில்லு முல்லு", முதல் முழு நீள காமெடி படமும் அதுதான்.

30. ரஜினியின் பேவரேட் பாம்பு சீன் முதலில் இடம் பெற்றது பைரவியில் புகழ் பெற்றது அண்ணாமலையில்.

31. இளைஞன், நடுத்தர வயது குடும்பஸ்தன். தள்ளாடும் முதியவர் என்ற மூன்று கெட்அப்களில் நடித்த படம் "6லிருந்து 60 வரை". ரஜினிக்கு தேசிய விருது எதிர்பார்க்கப்பட்ட படம்.

32. கோடிக் கணக்கில் சம்பளம் தர முன்வந்தும் ரஜினி இதுவரை ஒரு விளம்பரப் படத்தில்கூட நடித்ததில்லை. நான் உபயோகிக்காத ஒரு பொருளை மற்றவர்களை உபயோகிக்கச் சொல்வது தவறு என்பது அவர் கருத்து.

33. நிஜ வாழ்க்கையில் கண்டக்டராக இருந்த ரஜினி எந்தப் படத்திலும் கண்டக்டராக நடிக்கவில்லை. "ஆறு புஷ்பங்கள்" படத்தில் விஜயகுமார் கண்டக்டராக நடிக்க ரஜினி டிரைவராக நடித்திருந்தார். பாட்ஷா படத்தில் ஒரே ஒரு பாட்டில் கண்டக்டராக வருவார்.

34. ரஜினிக்கு எதிர்பாராத வெற்றியைக் கொடுத்த படம் "முரட்டுக்காளை", "சந்திரமுகி". எதிர்பாராத தோல்வியைக் கொடுத்த படம் "ஸ்ரீராகவேந்திரர்" மற்றும் "பாபா".

35. ரஜினி நடித்த ஹாலிவுட் திரைப்படம் பிளட் ஸ்டோன். ரஜினின் பல படங்கள் தெலுங்கு, இந்தி, கன்னடம், பெங்காலி மொழிகளில் டப் செய்யப்பட்டிருக்கிறது. நேரடியாக நடித்த இந்திப் படம் 16.

36.  தமிழ் சினிமாவில் அதிகமான புத்தகங்கள் வெளிவந்திருப்பது ரஜினி பற்றித்தான். அவரது வாழ்க்கை பற்றி நிறையபேர் எழுதியிருக்கிறார்கள். ரஜினியை சுயசரிதை எழுதச் சொல்லிக் கேட்டார்கள். அதற்கு அவர் சொன்ன பதில் "சுயசரிதை எழுதும் அளவுக்கு என் வாழ்க்கை பரிசுத்தமானதல்ல. அந்த அளவுக்கு பெரிதாக சாதித்தவனும் அல்ல. நான் நடிச்சு மக்களை சந்தோஷப்படுத்துறேன். அவர்கள் பணமாக எனக்கு திருப்பித் தந்து என்னை சந்தோஷப்படுத்துகிறார்கள் அவ்வளவுதான்" என்பார். அதுதான் சூப்பர் ஸ்டார்.

பிறந்தநாள் வாழ்த்துக்கள் ரஜினி...!

Default trace to find Who have done?


Default trace

To Find out recent update/delete/loginchange/anyevent:

SELECT *   FROM ::fn_trace_getinfo(default)

Note: 

Run the 1 st query and paste the C:\programmefile\..trc and paste it to second query and run it.

mostly 5 log sizes are available so we have to replace and search it 


SELECT  top 15
     loginname,
     textdata,
     RoleName,
     TargetLoginName,
     starttime,
     e.name as EventName,
     hostname,
     applicationname,
     servername,
     databasename,
     objectName,
     e.category_id,
     cat.name,
     duration,
     eventclass,
     eventsubclass,
     loginsid,
     endtime,
     spid
    
FROM ::fn_trace_gettable('C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\log_4192.trc',0)
     INNER JOIN sys.trace_events e
          ON eventclass = trace_event_id
     INNER JOIN sys.trace_categories AS cat
ON e.category_id = cat.category_id
where e.name='Audit Add Login to Server Role Event'
order by starttime desc

select getdate() [currentdate and time]

We have all been subject to or know someone who has been in a situation where an object has been altered/created/deleted, without our knowledge, and the application comes to a screeching halt. After fixing the problem, your boss asks you some questions, like what happened, why did it happen, and who did it. SQL Server 2005 introduced a new type of trigger called a DDL trigger that can provide all the answers we need; however, you did not get a chance to implement this functionality. So... what do you do?
Some would tell their boss "I do not know, but I can find out" and then search franticly for 3rd party tools to read the transaction log, hoping for instantaneous salvation. What these few do not know is an answer is silently running in the background. SQL Server 2005 has built in functionality that gives administrators the answers to all these questions.
The answers lie in a new background trace called the default trace. The default trace is exactly what the name specifies, a trace. Default trace is always running in the background of your instance capturing events that administrators can use to troubleshoot problems. The default trace is enabled by default and does not burden the system because it is fairly lightweight. Chances are you had not even noticed this trace running on your instance. To those concerned about overhead, yes there is overhead, but in my mind the benefits far outweigh the minimal overhead. The default trace is not intended to replace DDL trigger functionality and should be used as a means to monitor an SQL Instance, or quickly obtain detailed information about problematic events.
The default trace does not capture all trace events, but captures enough information to become a powerful tool in your toolkit. The default trace captures key information including auditing events, database events, error events, full text events, object creation, object deletion and object alteration. From my experiences and observations on forums, I will be focusing on object level events. It seems that a greater number of people want the "who done it" answer for object DDL events.
The first piece of code is to check the default trace to see if it is enabled.
SELECT * FROM sys.configurations WHERE configuration_id = 1568
If this feature is not available, you will have to configure the advanced option "default trace enabled". Below is the code to enable the trace. Note: you will need the ALTER SETTNGS permission or be in the sysadmin or serveradmin fixed server role to reconfigure.
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'default trace enabled', 1;
GO
RECONFIGURE;
GO
The next piece of information we need is the default trace file path, and the function below will return the current trace file. You can grab the initial trace file (log.trc) and rollup every trace file into a single table, but there is a higher overhead associated to bringing more data in. You should use the trace file that best represents the information you are looking for.
Note: the path is defaulted to the \MSSQL\LOG directory, but we can use the function below to get the path
--get the current trace rollover file
SELECT * FROM ::fn_trace_getinfo(0)
Now that we have all the information we need we can get into the trace data. Let's start by creating a new database call TraceDB.
USE [master]
GO
CREATE DATABASE TraceDB
Now open the trace file, as shown below. As you can see, we were able to gather some pretty significant information about who created the database and when the database was created. I have used category id of 5 and a trace_event_id of 46 to filter the data correctly. Event ID 46 represents Object:Created and category 5 is objects. I will provide queries that list all events and categories at the end of this article.
** Make sure to use your trace file path below. Yours may be different than mine.
SELECT 
     loginname,
     loginsid,
     spid,
     hostname,
     applicationname,
     servername,
     databasename,
     objectName,
     e.category_id,
     cat.name as [CategoryName],
     textdata,
     starttime,
     eventclass,
     eventsubclass,--0=begin,1=commit
     e.name as EventName
FROM ::fn_trace_gettable('C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\log.trc',0)
     INNER JOIN sys.trace_events e
          ON eventclass = trace_event_id
     INNER JOIN sys.trace_categories AS cat
          ON e.category_id = cat.category_id
WHERE databasename = 'TraceDB' AND
      objectname IS NULL AND --filter by objectname
      e.category_id = 5 AND --category 5 is objects
      e.trace_event_id = 46 
      --trace_event_id: 46=Create Obj,47=Drop Obj,164=Alter Obj
  • You will see more than one entry per object create because these objects have two event sub classes -begin and commit. Each subclass will have an entry.
  • You can remove the databasename filter to get object creation events for all databases.
Results (Trimmed for Simplicity):


Now, we have seen what default trace is capable of. Let's create another object and repeat the query. This time around we are going to create a table called "MyTable". Use the following code to create the table.
USE [TraceDB]
GO
CREATE TABLE [dbo].[MyTable](
 [id] [int] IDENTITY(1,1) NOT NULL,
 [sometext] [char](3) NULL
) ON [PRIMARY]
Now query the default trace using the same query as above. Note you can use the ObjectName column to filter for the specific object you are looking for; otherwise all created database objects are returned.
WHERE databasename = 'TraceDB' AND
      objectname = 'MyTable' AND --filter by objectname
      e.category_id = 5 AND --category 5 is objects
      e.trace_event_id = 46
      --trace_event_id: 46=Create Obj,47=Drop Obj,164=Alter Obj
Results (Trimmed for Simplicity):



Let's take the demo a step further by altering MyTable. Issue an alter table statement and add a new column to MyTable, as shown below.
USE [TraceDB]
GO
ALTER TABLE MyTable
ADD col INT
We can now search trace information on the alter event for MyTable. We can use the same query as before but need to make a small modification. You must change the trace_event_id to 164 because event 164 represents the object:Altered event.
WHERE databasename = 'TraceDB' AND
      objectname = 'MyTable' AND --filter by objectname
      e.category_id = 5 AND --category 5 is objects
      e.trace_event_id = 164 
      --trace_event_id: 46=Create Obj,47=Drop Obj,164=Alter Obj
Results (Trimmed for Simplicity):


Now lets drop MyTable and view the trace details. You must change the trace_event_id to 47 because event 47 represents the object:Deleted event, as shown below.
USE [TraceDB]
GO

DROP TABLE MyTable
We can view trace data by changing the trace_event_id to 47.
WHERE databasename = 'TraceDB' AND
      objectname = 'MyTable' AND --filter by objectname
      e.category_id = 5 AND --category 5 is objects
      e.trace_event_id = 47 
      --trace_event_id: 46=Create Obj,47=Drop Obj,164=Alter Obj
Results (Trimmed for Simplicity):


As you can see, default trace gives an administrator the ability to find the history of any DDL transaction. I want to point out that default trace is not limited to object DDL history. Among other things, default trace captures log growth events, which can be invaluable to troubleshooting disk capacity problems.
For example, say your log file spontaneous grows enormous. It is important to understand why the log grew spontaneously. No one would argue that one of the first place to look may be SQL Jobs. There are many commands within a job that can potentially cause the log to grow enormous, like reindexing, bulk inserts, bulk deletes etc. By using the trace data you can more easily identify the problem because you can pin-point the exact time the log file began to grow. This greatly reduces the number of possible suspects, which reduces the amount of time required to find the culprit.
The query below will pull all trace data using the log auto growth event. Note: You will not have any log growth for TraceDb because we have not done in large inserts to make the log grow. You should apply this query to another database where you want to monitor log growth.
SELECT 
     loginname,
     loginsid,
     spid,
     hostname,
     applicationname,
     servername,
     databasename,
     objectName,
     e.category_id,
     cat.name,
     textdata,
     starttime,
     endtime,
     duration,
     eventclass,
     eventsubclass,
     e.name as EventName
FROM ::fn_trace_gettable('C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\log.trc',0)
     INNER JOIN sys.trace_events e
          ON eventclass = trace_event_id
     INNER JOIN sys.trace_categories AS cat
          ON e.category_id = cat.category_id
WHERE databasename = 'TraceDB' AND
      e.category_id = 2 AND --category 2 is database
      e.trace_event_id = 93 --93=Log File Auto Grow

Summary:

The default trace is a valuable tool for the modern DBA's tool belt. It offers a wealth of information, while minimally impacting the system. The default trace is not a widely publicized feature of SQL Server 2005, but is slowly gaining fame. The default trace gives administrators the ability to get detailed information about auditing events, database events, error events, full text events, object creation, object deletion and object alteration events. With this much information at their fingertips, administrators are more productive and can more easily identify problems in a production environment. My recommendations are to look through the events and see what information already exists for your instances. Default trace should not only be used reactively but proactively. A proactive mentality will reveal small problems before they escalate to bigger problems.

Event and Category Queries

--list of events 
SELECT *
FROM sys.trace_events
--list of categories 
SELECT *
FROM sys.trace_categories
--list of subclass values
SELECT *
FROM sys.trace_subclass_values
--Get trace Event Columns
SELECT 
     t.EventID,
     t.ColumnID,
     e.name AS Event_Descr,
     c.name AS Column_Descr
FROM ::fn_trace_geteventinfo(1) t
     INNER JOIN sys.trace_events e 
          ON t.eventID = e.trace_event_id
     INNER JOIN sys.trace_columns c 
          ON t.columnid = c.trace_column_id

Thursday, 6 December 2012

Test Your Skills For SQL Server

Test 1:

 1 ) Which wildcard usage will help you find all last names starting with R?

 2 ) You want to find all first names that have the letter A as the second letter and do not end with the letter Y. Which SQL code would you use?
3 ) Look at the following SQL statement:
SELECT * 

  FROM Employee LEFT OUTER JOIN Location

  ON Location.LocationID = Employee.LocationID

 4 ) What is the correct way to alias the sales table? Choose the correct answer
5 ) Can you create a table with zero fields? Choose the correct answer
 6 ) Which of the following is not a way to run a SQL script? Choose the correct answer
7 ) Which statement describes the difference between the DROP and DELETE clauses for tables? Choose the correct answer
 8 ) You want to create a stored procedure called GetWagesByManager that takes a parameter called EmpID. What would be the first line of your statement? Choose the correct answer
 9 ) What is a dirty record? Choose the correct answer
 10 ) If you granted Phil control to the server, but denied his ability to create databases, what would his effective permissions be? Choose the correct answer

Test 2:

* 1 ) You have a table named Performance.

The [Duration] field shows the total time, in milliseconds, it took for a query to run. You have a field, called CPU, which shows the processing time in millisecondYou have a field, called EventClassID.The company worries there may be queries running slowly in the CPU, or quickly in the CPU but spending too much time for the total duration. You want to find all records from EventClassID 7 that are taking more than 1 second of CPU time or more than 2 seconds of total duration. Which predicate do you use?

* 2 ) Your manager wants to see all employees in alphabetical order for each state. She has asked you to sort by State, LastName, and FirstName columns. Without creating any additional tables how can you view this report? Choose the correct answer.

* 3 ) You have a table named Products defined with the following code:


CREATE TABLE Products

(ProductID int IDENTITY (1,1) ,

ProductRating int NOT NULL,

ProductName varchar(50),

CreationDate datetime NOT NULL)


You must insert a new Product record with a rating of 75 called “Go Duck” with today’s Creation datetime. Which statement should you use?



* 4 ) Your JProCo database has two tables named Customers and Orders. Not all customers have placed an order yet. You would like to see a list of customers and the total number of orders listed next to the CustomerID. Which query should you use? Choose the correct answer

* 5 ) You want to display each grant in your [Grant] table and have an expression field that shows the total amount of all Grants. Which query should you use? Choose the correct answer

* 6 ) You have 1 million rows to delete from the TempProducts table. If the field called “PlsDelete” is marked with a 1, then that row should be deleted. You have been asked to delete 5000 rows at a time. You need to write a TransactSQL batch that will delete exactly 5000 rows. Which TransactSQL batch should you use?

* 7 ) You want to find the top 2% of all students’ Grade Point Averages (GPA). Which NTILE would you use? Choose the correct answer

* 8 ) You have two tables named CurrentProducts and RetiredProducts that have the same field names and data types. In fact the structure of the two tables is identical. You write the following two queries.


SELECT * FROM CurrentProducts

SELECT * FROM RetiredProducts


Between these two queries you want to use the correct T-SQL Operator to display the records that are common between both tables. Which operator would you use?


* 9 ) Which code uses a CTE (Common Table Expression)?
* 10 ) You have two tables, named Customer and SalesOrder. You need to identify all customers that have not made any purchases or those who have never ordered more than 40 at any given time. Which query should you use? Choose the correct answer

Test 3:

* 1 ) You have a table named Feedback that contains every record of how a customer felt about their purchase. One field is called Complaint, where 0 is no complaint and 1 is a complaint.

You also have a field called Rating that ranges from 0 to 100. If a customer complains they should not be giving a perfect rating of 100. If they complain then they can enter a score between 0 and 90. If they don’t then it can be between 1 and 100.
Which check constraint would you use?


* 2 ) You want to perform a test insert against your dbo.Employee table which has an insert trigger on it. You are not allowed to delete the trigger but want to perform this insert without the trigger firing. How can you do this? Choose the correct answer

* 3 ) Which statement will never fire a DDL trigger? Choose the correct answer

* 4 ) What happens to a view if the underlying base table is dropped? Choose the correct answer

* 5 ) You are creating a view that queries your Employee table. You need to prevent the Employee table from being dropped as long as your view exists. Which option should you use when you create the view? Choose the correct answer

* 6 ) Your stored procedure named GetEmployeeByCity has a default parameter of ‘Seattle’. When you execute the stored procedure, you supply “Boston” as the parameter. What is the result of your execute statement. Choose the correct answer

* 7 ) What is the difference between SCOPE_IDENTITY( ) and @@IDENTITY? Choose the correct answer

* 8 ) The following query finds all reports for leap year months since 1950:


SELECT *

FROM Reports

WHERE  ???????? (rMonth, rYear)  = 29

AND rYear > 1950


If, for a specified year, the month of February will contain 29 days, you want the query to include the record in your query. Which object should you use in your query predicate?


* 9 ) Which SQL Server error action happens for errors with a severity of 11-16 when you set the XACT_ABORT setting to OFF? Choose the correct answer

* 10 ) You have tables named CurrentProducts and SalesInvoiceHeader. The CurrentProducts table has a foreign key relationship with the SalesInvoiceHeader table on the ProductID column. . You are deleting ProductID 77 from the Product table and then trying to insert a sale for Product77 into the SalesInvoiceHeader table.





BEGIN TRY

  BEGIN TRANSACTION

      DELETE FROM CurrentProducts  WHERE ProductID = 77;

      BEGIN TRANSACTION

        INSERT INTO SalesInvoiceHeader VALUES ( 95894, 77, 2 );

      COMMIT TRANSACTION

  COMMIT TRANSACTION

END TRY

BEGIN CATCH

  ROLLBACK TRANSACTION

  PRINT ERROR_MESSAGE( );

END CATCH


What will be the outcome when you run this query?


Ans????????

I will submit to you soon till you just guess ur answer and patient!!!!!!!!!!!!!!!!!!!!!!!!!!! thankxxxxxxx for patient.




Tuesday, 4 December 2012

Why is my log file full? & Common Table Expression(CTE) in Sql server 2005 and Solve maximum number of user connections has already been reached


“Why is my log file growing?” and “Why is my log file full” are heard regularly. Or, the variation, “I ran a full backup but the log file is still full/growing.” occasionally comes up. The people asking these questions are frequently, even appropriately, frantic. I’m writing this blog post for two reasons. First, to try to add a little bit of weight to what must surely be one of the most searched for phrases on the internet when it comes to SQL Server. Second, just to have a shorthand to answer the question, “Here, check my blog post.”
Right off the bat, database backups are not backing up the log. There. That’s out of the way. Yes, I’m serious. Database backups do not backup the log. They backup all committed data in the database (which might include some or all of what might be in your log file) and they backup some transactions that completed during the backup process as part of the cleanup at the end of the backup (that would be, by definition, be in the log file). But they do not backup the log file. Why is this important?
The transaction log on the database represents the work you are doing to that database. It records the row you inserted, the twenty you deleted and the five that were updated. It records the fact that you dropped a table or truncated a table (and yes, truncation is a logged operation). All of these logged events are written to the log. They are written to the log regardless of the recovery model. What recovery model you ask? Ah, and there we begin to hit our problem.
There are three recovery models, full, bulk-logged and simple. The first and third are the ones that most people use, so they’re all I’m going to worry about for this post. Full recovery means that committed transactions (transactions that have been successfully completed) that are written to the log are retained, even after a checkpoint operation. Simple recovery means that committed transactions are removed from the log when the checkpoint operation runs. A checkpoint is basically when everything in memory gets written out to disk (yes, there’s more to it, but that’s enough for our current conversation). Checkpoints occur at irregular intervals.
Assuming your database is in simple recovery, the log only needs to be big enough to hold the transactions that are uncommitted between checkpoints. Depending on the size and number of your transactions, this could mean a small log, or a huge one. Note, I have not said that your log shrinks at checkpoint. It does not. In simple recovery your log is emptied of committed transactions at checkpoint (and yes, I’m repeating myself). This means any space allocated for the log remains allocated for the log. This is one of the reasons that your log file grows and does not shrink. Now let’s talk about the big one.
I first mentioned full recovery and said that the logs are kept, even beyond a checkpoint. This means they stay in the log, waiting. More transactions are run, and assuming your log is growing by default, it gets bigger and more transactions are in the log waiting. This continues until you finally run a log backup process. This is completely independent from your full backups (although a marker for the last full backup is maintained as a part of the recovery process). The basic syntax looks like this:


BACKUP LOG MyDatabaseName
TO SomeLocationOrDevice

This is a problem for two basic reasons. By default, new databases are created in full recovery mode AND by default, no one has set up log backups on your system. That means it’s up to you. You have to set up log backups. You have to set them and you have to schedule them and you have to ensure they run if you want to recover your database to a point in time, which is also known as, Full Recovery.
This is the important point, yes, setting the database to simple recovery can largely eliminate the problem of the ever-growing log file. But, simple recovery takes away your ability to recover to a point in time, meaning, crash occurs at 4:57PM. Your last full backup was at 6:00AM. In simple recovery mode, you just lost almost eleven hours worth of business because you can only recovery to the full backup. With Full Recovery, you can do what is known as a tail log backup, and take that in combination with all the other backups and recover your database, at least up to the last log backup, but possibly even right up to when the error occurred.
You need to ask your business, how much data are they prepared to lose. If they can deal with eleven hours, like our example above, great, you don’t need log backups. If, like most businesses I’ve worked with, they expect to recover everything, all the time, you’d better have log backups and full recovery.

select log_reuse_wait, log_reuse_wait_desc ,*          from sys.databases


       log_reuse_wait:


Reuse of transaction log space is currently waiting on one of the following:
0 = Nothing
1 = Checkpoint
2 = Log backup
3 = Active backup or restore
4 = Active transaction
5 = Database mirroring
6 = Replication
7 = Database snapshot creation
8 = Log Scan
9 = Other (transient)
log_reuse_wait_desc:

                     Description of reuse of transaction log space is currently waiting on one of the following:
NOTHING
CHECKPOINT
LOG_BACKUP
If the reason is LOG_BACKUP, it may take two backups to actually free the space.
ms178534.note(en-US,SQL.90).gif
ACTIVE_BACKUP_OR_RESTORE
ACTIVE_TRANSACTION
DATABASE_MIRRORING
REPLICATION
DATABASE_SNAPSHOT_CREATION
LOG_SCAN
OTHER_TRANSIENT


Common Table Expression(CTE) in SQL Server 2005:


Most of the developers while writing the stored procedures they create the temp tables or table variables. They need some table to store the temporary results in order to manipulate the data in the other tables based on this temp result.

The temp variables will be stored on the tempdb and it needs to be deleted in the tempdb database.

The table variable is best when compare with the temp tables. Because the table variable initially will be there in the memory for the certain limit of size and if the size increase then it will be moved to the temp database. However the scope of the table variable is only up to that program. When compare with table variable the CTE is best. It just store the result set like normal view.

CTE (Common Table Expression):

The CTE is one of the essential features in the sql server 2005.It just store the result as temp result set. It can be access like normal table or view. This is only up to that scope.

The syntax of the CTE is the following.

WITH name (Alias name of the retrieve result set fields)
AS
(
//Write the sql query here
)
SELECT * FROM name

Here the select statement must be very next to the CTE. The name is mandatory and the argument is an optional. This can be used to give the alias to the retrieve field of the CTE.

CTE 1: Simple CTE

WITH
ProductCTE
AS(  SELECT ProductID AS [ID],ProductName AS [Name],CategoryID AS [CID],UnitPrice AS [Price]
  FROM Products
)SELECT * FROM ProductCTE

Here all the product details like ID, name, category ID and Unit Price will be retrieved and stored as temporary result set in the ProductCTE.

This result set can be retrieved like table or view.

CTE2:Simple CTE with alias

WITH
ProductCTE(ID,Name,Category,Price)AS(  SELECT ProductID,ProductName,CategoryID,UnitPrice
  FROM Products
)SELECT * FROM ProductCTE

Here there are four fieds retrieves from the Products and the alias name have given in the arqument to the CTE result set name.

It also accepts like the following as it is in the normal select query.

WITH
ProductCTE
AS(  SELECT ProductID AS [ID],ProductName AS [Name],CategoryID AS [CID],UnitPrice AS [Price]
  FROM Products
)SELECT * FROM ProductCTE

CTE 3: CTE joins with normal table

The result set of the CTE can be joined with any table and also can enforce the relationship with the CTE and other tables.

WITH
OrderCustomer
AS(  SELECT DISTINCT CustomerID FROM Orders
)SELECT C.CustomerID,C.CompanyName,C.ContactName,C.Address+', '+C.City AS [Address] FROM Customers C INNER JOIN OrderCustomer OC ON OC.CustomerID = C.CustomerID

Here the Ordered Customers will be placed in the CTE result set and it will be joined with the Customers details.

CTE 4: Multiple resultsets in the CTE

WITH
MyCTE1
AS(  SELECT ProductID,SupplierID,CategoryID,UnitPrice,ProductName FROM Products
), 
MyCTE2
AS(  SELECT DISTINCT ProductID FROM "Order Details"
)SELECT C1.ProductID,C1.ProductName,C1.SupplierID,C1.CategoryID FROM MyCTE1 C1 INNER JOIN MyCTE2 C2 ON C1.ProductID = C2.ProductID

Here, there are two result sets that will be filtered based on the join condition.

CTE 5: Union statements in the CTE

WITH
PartProdCateSale
AS(SELECT ProductID FROM Products WHERE CategoryID = (SELECT CategoryID FROM Categories WHERE CategoryName='Condiments')UNION ALL
SELECT
ProductID FROM Products WHERE CategoryID = (SELECT CategoryID FROM Categories WHERE CategoryName='Seafood')
)
SELECT OD.ProductID,SUM(OD.UnitPrice*OD.Quantity) AS [Total Sale] FROM "Order Details" OD INNER JOIN PartProdCateSale PPCS ON PPCS.ProductID = OD.ProductID
GROUP BY OD.ProductID

Normally when we combine the many result sets we create table and then insert into that table. But see here, we have combined with the union all and instead of table, here CTE has used.

CTE 6: CTE with identity column

WITH
MyCustomCTE
   AS   (      SELECT CustomerID,row_number() OVER (ORDER BY CustomerID) AS iNo FROM
         Customers
   )SELECT * FROM MyCustomCTE


SQL SERVER – FIX: Could not connect because the maximum number of ‘1’ user connections has already been reached

We quickly started desktop sharing and we noticed the below error while connecting from SSMS.
TITLE: Connect to Database Engine
——————————
Cannot connect to DBSERVER.
——————————
ADDITIONAL INFORMATION:
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: Shared Memory Provider, error: 0 – No process is on the other end of the pipe.) (Microsoft SQL Server, Error: 233)
——————————
No process is on the other end of the pipe
——————————
BUTTONS:
OK
——————————
This was a very generic error, so I asked to check the Application Event Log.
Log Name:      Application
Source:        MSSQLSERVER
Event ID:      17809
Task Category: Logon
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      DBSERVER.SomeDomain.in
Description:
Could not connect because the maximum number of ‘1’ user connections has already been reached. The system administrator can use sp_configure to increase the maximum value. The connection has been closed.
As per above message the number of user connections was set to 1 and all we need to do is change that value to 0 as shown below
SQL SERVER - FIX: Could not connect because the maximum number of ‘1’ user connections has already been reached max-conn-01
Sounds simple, but the situation here was that someone was grabbing connection so quickly that we were not able to connect. I recalled an earlier blog, where I wrote about single user mode.
So, we followed the blog, start SQL with /mSQLCMD parameter, connected to the SQL server instance in single user mode via SQLCMD and then executed following command.
exec sp_configure 'user connections',0
go
reconfigure with override
go
Then we restarted SQL Server and after which we were able to connect successfully using SSMS and application also started working.