Friday, 3 May 2019

SQL server tricky questions

1. Suppose we have EmpTbl as below



And Data like


Now we have queries like 

1.  Select maximum salary from EmpTbl
Ans. Select max(Salary) as Salary from EmpTbl
You will get the output like below


2. Select Salary and Name in Descending Order
Ans. 1st Way :
         Select max(salary) as Salary, Name from EmpTbl Group by Name order by Salary desc
         2nd Way : 
         Select Salary, Name from EmpTbl  Order by Salary desc
You will get the output like below

3. Select employee name with highest salary Department wise.
Ans. Select Salary, Name, Department from EmpTbl where Salary in (select max(Salary) from EmpTbl Group by Department)
You will get the output like below

4. Select the second highest Salary from the table.
Ans. 1st Way :
         Select Top(1) * from (select top(2) Salary from EmpTbl order by Salary desc) As T Order by               Salary asc 
         2nd Way :
         Select  Max(Salary) from EmpTbl where Salary <(Select Max(Salary) from EmpTbl)  
You will get the output like below

5. Select Sum of Salary Department wise.
Ans. Select Sum(Salary) as Salary, Department from EmpTbl Group by Department
You will get the output like below

6. Select Department whose Sum of Salary is greater than 25000.
Ans. Select Sum(Salary) as Salary, Department from EmpTbl Group by Department having Sum(Salary)>25000
You will get the output like below
7. Select the name of the employees whose Salary is between 10000 to 50000.
Ans. Select Name, Salary from EmpTbl where Salary between 10000 and  50000       
You will get the output like below.


8. Select Salary whose name starts with 'R'.
Ans. Select Name, Salary from EmpTbl where Name like 'R%'
You will get the output like below








9. Select the name of all employees as comma separated.
Ans. SELECT Name + ', ' From EmpTbl For XML PATH('')
You will get the output like below.

10. How to swap the department Asp.net and PHP?
Ans UPDATE EmpTbl 
   SET Department = CASE  
                WHEN Department = 'Asp.net' THEN 'PHP'  
                ELSE Case When Department= 'PHP' then 'Asp.net'  End 
                END Where Department='Asp.net' or Department='PHP'

11. Get the name of Employees whose salary is the same.
Ans. select e1.Salary,e1.Name from EmpTbl as e1,EmpTbl as e2
Where e1.Salary=e2.Salary and e1.EmpId!=e2.EmpId

12. How to find the duplicate records?

Ans. select EmpId,Name,Department,Salary,BirthDate ,Count(*) as Cnt
from EmpTbl Group by EmpId,Name,Department,Salary,BirthDate having Count(*)>1




13. Select employee names whose age is greater than 30.
Ans. select Name from EmpTbl  
where datediff(year,BirthDate, getdate()) >30 














14. Select the names of the employees whose Birthdate date is between 01/01/1988 to 01/01/1999.

Ans. SELECT DISTINCT Name FROM EmpTbl
WHERE BirthDate BETWEEN '01/01/1988' AND '01/01/1999'

15. What will be the output of the query

Select Null/0
Ans. NULL

16. What will be the output of the query

Select SUM(NULL)
Ans. Error

17.What will be the output of the query

Select 4 from EmpTbl
Ans.


18. What will be the output of the query

Select (1/2)*10

Ans. 0


19. How to fetch the first 10 characters of the string?

A. SELECT SUBSTRING(Name,1,10) AS EmployeeName FROM EmpTbl

20. How to add column LastName in EmpTbl?

Ans. ALTER TABLE EmpTbl ADD LastName nvarchar(max)

21. How to get the list of all the tables of a database?

Ans. SELECT * from sys.Tables



Saturday, 13 April 2019

30 - ADO.Net - multiple choice questions

1. DateSet contains one or more DataTables?
A. True
B. False
C. Can't say
D. None of the above

---------------------------------------------------------------------


2. Can we use DataView to Filter rows in a DataTable?

A. Yes by setting Filter property
B. Yes by setting FilterRow property
C. Yes by setting the SetFilter method
D. None of the above

---------------------------------------------------------------------


3. Which method is used to retrieve the single value?

A. ExecuteScalar
B. ExecuteReader
C. ExecuteSingle
D. ExecuteNonQuery

---------------------------------------------------------------------


4. How to load XML in DataSet?

A. Using the ReadXml method
B. Using the GetXml method
C. Both of the above
D. None of the above

---------------------------------------------------------------------


5. Which method is used to fill DataSet?

A. Populate
B. Fill
C. Open
D. Close

---------------------------------------------------------------------


6. Which object is used to Fill DataSet using the query in SQL Server?

A. DataSet
B. DataTable
C. DataAdapter
D. None of the above

---------------------------------------------------------------------


7. Which object will be used to sort the data of DataSet?

A. DataView object
B. DataSet
C. DataTable
D. DataAdapter

---------------------------------------------------------------------


8. DataSet object is

A. disconnected
B. connected
C. Can't say
D. None of the above

---------------------------------------------------------------------


9. Which is Read-only forward-only recordset?

A. DataSet
B. DataReader
C. DataAdapter
D. DataCommand

---------------------------------------------------------------------


10. Which namespace is used to fetch data from Oracle database?

A. Sql.Data
B. Sql.Data.SqlClient
C. Sql.Data.OracleClient
D. None of the above

---------------------------------------------------------------------


11. Which ADO.net object is very fast to get data from the database?

A. SqlDataAdapter
B. DataSet
C. SqlDataReader
D. None of the above

---------------------------------------------------------------------


12. What is the default specified timeout period for "SQLCommand.CommandTimeout" property?

A. 30 seconds
B. 60 Seconds
C. 90 Seconds
D. 120 Seconds

---------------------------------------------------------------------


13. What is the Full form of ADO.Net?

A. Active Display Object
B. ActiveX Data Object
C. Asp Data Object
D. Active Dot Object

---------------------------------------------------------------------


14. Which Adapter is used to get the data from the Access Database?

A. DataAdapter
B. OledbDataAdapter
C. SQLDataAdapter
D. OracleDataAdapter

---------------------------------------------------------------------


15. Which ADO.Net class provides a connected environment?

A. DataSet
B. DataReader
C.Both
D. None

---------------------------------------------------------------------


16. When to use the OleDbConnection object?

A. When we want to connect to the Oracle database.
B. When we want to connect to the Sql server database
C. When we want to connect to Office Access database
D. None of the above

---------------------------------------------------------------------


17. Which is the return type of the ExecuteScalar class?

A. System.Int32
B. object
C. Both
D. None of the above

---------------------------------------------------------------------


18. Which are command object methods?

A. ExecuteScalar
B. ExecuteNonQuery
C. ExecuteReader
D. All of the above


---------------------------------------------------------------------

19. Which of the following is not the method of DataAdapter

A. Fill
B. FillSchema
C. ReadDate
D. Update

---------------------------------------------------------------------


20. Which of the following is the benefit of the ADO.Net?

A. Interoperability
B. Disconnected Data Access
C. Store Data in multiple tables
D. All of the above

---------------------------------------------------------------------


21. ADO.Net provides the ability to process and create an in-memory database which is called

A. DataSets
B. Views
C. Tables
D. Relations

---------------------------------------------------------------------


22. It is not required to open the connection when I am using DataAdapter.

A. True
B. False

---------------------------------------------------------------------


23. Which CommandType is used to define the StoredProcedure?

A. Command.TableDirect
B. CommandType.StoredProcedure
C. CommandType.TableDirect
D. Command.Stored

---------------------------------------------------------------------


24. Which namespace is used to access the connection string from the Web.Config file?

A. Web.Configuration
B. Web.Config
C. System.Configuration
D. System.Web.Configuration

---------------------------------------------------------------------


25. SqlConnection object is used for?

A. MySql database
B. Oracle database
C. Microsoft SQL Server database
D. Access database

---------------------------------------------------------------------


26. Which method is suited best when we have aggregate values in the SELECT statement?

A. ExecuteScalar()
B. ExecuteNoQuery().
C. ExecuteReader()
D. None of the above

----------------------------------------------------------------------


27. On which object we set the properties to create a primary key for DataTable?

A. DataSet
B. DataTable
C. DataRelation
D. DataColumn

---------------------------------------------------------------------


28. Which of the following are the events of the DataTable object?

A. RowChanged
B. ColumnChanged
C. RowChanging
D. All Of the above

---------------------------------------------------------------------


29. Which Data Provider gives the maximum performance when connected to SQL Server?

A. SqlClient Data Provider
B. OLEDB Data Provider
C. Oracle Data Provider
D. All of the above


---------------------------------------------------------------------


30. If we want that the command object should return XML data then which Command object will be used?

A. GetXMLData
B. GetXml
C. ExecuteXmlReader
D. None of the above

Friday, 12 April 2019

16 - XML multiple choice questions

1. What s the full form of XML?
A. XML markup language
B Extensible markup language
C. Xaml markup language
D. Example markup language

-------------------------------------------------------------------------

2. What is the main use of XML?

A. To transport data
B. To verify data
C. To design data
D. All of the above

-------------------------------------------------------------------------

3. How to write a comment in an XML document?

A. <?----?>
B. <!-- !>
C. <!-- -->
D. </-- --/>

-------------------------------------------------------------------------

4. XML uses the features from language?

A. SGML
B. HTML
C. XSLT
D. XHTML

-------------------------------------------------------------------------

5. DTD stands for?

A. Document Test Document
B. Document Type Definition
C. Dynamic Type Document
D. All of the above

-------------------------------------------------------------------------

6. Which of the following is not XML function?

A. Store Data
B. Style Data
C. Structure Data.
D. Transport Data

-------------------------------------------------------------------------

7. Is it easy to process XML than HTML?

A. True
B. False
C. Both
D. Can't say

-------------------------------------------------------------------------

8. DOM stands for?

A. Document oriented Model.
B. Document Object Model
C. D Object Model
D. None of the above

-------------------------------------------------------------------------

9. What is used to check XML syntax errors?

A. XML validator
B. XML parser
C. Browser
D. None of the above

-------------------------------------------------------------------------

10. Which attribute is used to define namespace?

A. XMLattribute
B. Xmlns
C. XMLNamespace
D. None of the above

-------------------------------------------------------------------------

11. How to define empty XML element?

A. <simple></simple>
B. <//Simple>
C. <//Simple><//Simple>
D. None of the above

-------------------------------------------------------------------------

12. XML Schema consists

A. Properties & Methods
B. Elements & Attributes
C. Structure & Data
D. Tables & Relationships


------------------------------------------------------------------------- 
13. XML tags are
A. Case Sensitive
B. Case Insensitive
C. Complex
D. None of the above

-------------------------------------------------------------------------

14. Does XML used to Replace HTML?

A. No
B. Yes
C. Can't SAy
D. None of the  above

-------------------------------------------------------------------------

15. Which allows Hyperlinks to point to specific parts of the XML documents?

A. XPath
B. XSLT
C. XLINK
D. Xpointer

-------------------------------------------------------------------------

16. Which are the predefined attributes in XML?

A. xml:lang
B. xml:space
C. Both
D. None

Sunday, 7 April 2019

16 - XML Interview questions



      1.  What is XML?
       Ans. XML stands for "Extensible Markup Language”. It must have a .xml extension. Its case sensitive markup language.

       2. What is the difference between HTML and XML?
       Ans.
       1. HTML has its own defined tags while XML has no specific tag.
       2. HTML may not contain closing tag but for XML its necessary to close tag.
       3. HTML is not case sensitive but XML is case sensitive.
       4. HTML document must have an htm or html extension while XML document must have xml extension.
     
      3. What is the version in XML?
      Ans. XML version shows which version of XML is used.

4. What are rules to write the XML document?

      Ans. 
             It should have a root element.
             Spaces are not allowed in tag names.
             All tags must be closed.
             All tags must be nested properly.
             Attributes value should appear in quotes.

5. Is XML case sensitive?

       Ans. Yes

6. What is attribute in XML?

       Ans. Attribute provides more information about an element.
`              <Employee name="Sapna">
                Here name is the attribute.

7. Can we have empty XML tags?

       Ans. Yes, empty XML tags define that elements have no textual content.  

8. What is XQuery?

       Ans. XQuery is a query language which is used to fetch data from XML document.
       
       9. Which namespace is used to work with class XmlReader?
       Ans. using System.Xml;

 10. How comment is represented in XML?

       Ans. <!- –  XML comments – ->

 11. What is XML namespace?

       Ans. XML namespace is used to avoid conflict between two tags of the same name but the different sources.XML namespace is defined using xmlns attribute at the top of the XML document.

       12. Is XML,SGML,HTML same thing?

       Ans. No

13. How Soap is related to XML?

       Ans. Soap (Simple object access protocol) uses XML to define a protocol to exchange data in distributed servers.

 14. What is XML DOM?

       Ans. XML DOM stands for Document Object Model which describes the logical structure of the XML.

15. What is XSL?

      Ans. XSL stands for the Extensible Stylesheets Language which describes how to display XML document.

16. Which language is used to describe web service in XML?
Ans. WSDL

Sunday, 31 March 2019

40 - HTML multiple choice questions

1. HTML stands for?
A. Hello text markup language
B. Hyper text markup language
C. High text markup language
D. None of these

-------------------------------------------------------------------------

2. HTML language is a set of markup
A. Tags
B. Sets
C. Attributes
D. Groups

-------------------------------------------------------------------------

3. HTML file extension?
A. .hml
B. .html
C. htnl
D. .hnl

-------------------------------------------------------------------------

4. HTML is considered as?
A. Markup language
B. Programming language
C. OOPS language
D. Middle level language

-------------------------------------------------------------------------
5. Which tag is used to display pictures in HTML?

A. image
B. Picture
C. img
D. video

-------------------------------------------------------------------------

6. HTML tags are case sensitive?
A. true
B. false

-------------------------------------------------------------------------

7. Which tag is used for scrolling text?
A. <marquee>
B. <p>
C. <div>
D. <mg>

-------------------------------------------------------------------------

8. Which tag is used to make the text as italic?
A. <b>
B <br>
C. <i>
D. <h1>

-------------------------------------------------------------------------

9. Which tag is used to make the text as bold?
A. <b>
B. <i>
C. <br>
D. <span>

-------------------------------------------------------------------------
10. Which element is used for the largest heading?

A. <h6>
B. <h1>
C. <head>
D. <heading>

-------------------------------------------------------------------------

11. HTML is a subset of
A. SGML
B. SGBML
C. Both
D. None of the above

-------------------------------------------------------------------------

12. Which element is used for line break?
A. <break>
B.  <b>
C.  <br>
D.  <linebreak>

-------------------------------------------------------------------------

13. Which is the correct sequence of HTML tags for the web page to be started?
A. head, title, html
B. title, body, html
C. body, html, head
D. html, head title

-------------------------------------------------------------------------

14. Which tag is used to add links to your page?
A. <a>
B. <b>
C. <br>
D. <img>

-------------------------------------------------------------------------

15. Which tag is used to make the text italic?
A. <text>
B. <i>
C. <italic>
D. <italictext>

-------------------------------------------------------------------------
16. Which is the root tag of the HTML document?

A. body
B. html
C. head
D. title

-------------------------------------------------------------------------
17. Which tag is not found in the head tag?

A. <table>
B. <title>
C. <style>
D. all of the above

-------------------------------------------------------------------------
18. What is the meaning of vlink?

A. active link
B. visited link
C. visible link
D. All of the above

-------------------------------------------------------------------------

19. Which tag is used to define inline styles?
A. style
B. styles
C. class
D. font

-------------------------------------------------------------------------
20. What is the use of inline styles?

A. To apply css to all HTML pages
B. To apply unique style to single page
C. Both of the above
D. none of above

-------------------------------------------------------------------------

21. Which is the correct position to place the <title> tag?
A. <body>
B. <table>
C. <head>
D None of the above

-------------------------------------------------------------------------

22. Which are two methods used while submitting HTML form?
A. GET
B. POST
C. SUBMIT
D. Both A & B

-------------------------------------------------------------------------

23. Default value for attribute BORDER is?
A. 1 px
B.  2px
C. 3 px
D. 4 px

-------------------------------------------------------------------------

24. Select correct HTML to add background color.
A. <body style="background-color:yellow">
B. <body background="yellow">
C. <body yellow>
D. All of the above

-------------------------------------------------------------------------
25. How to create an email link?

A. <a href="mailto:sapnagiyanwani@gmail.com">
B. <mail>
C. <a>malto</a>
D. None of the above

-------------------------------------------------------------------------


26. What is the abbreviation for  XHTML?

A. Extensible Hyper text markup language
B. Extensible High text markup language
C. None of the above

-------------------------------------------------------------------------

27. Which HTML tag is for the container of metatags?
A. <html>
B. <title>
C. <head>
D. <body>

-------------------------------------------------------------------------
28. Which tag is used for the client side script?

A. <body>
B. <css>
C. <style>
D. <script>

-------------------------------------------------------------------------

29. Which attribute is used to uniquely identify an HTML element?
A. id
B. #
C. style
D. css

-------------------------------------------------------------------------

30. Which attribute is used to merge two columns in the table tag?
A. rowspan
B. colspan
C. tr
D. td

-------------------------------------------------------------------------

31. What is the REFRESH meta tag used for?
A. Refresh page
B. Redirect to new domain
C. None of the above
D.Can't say

-------------------------------------------------------------------------

32. Which of the following is not an empty element?
A. <br>
B. <hr>
C. <p>
D. both <br> and <hr>

-------------------------------------------------------------------------


33. Can a Data cell contain image?

A. Yes
B. No

-------------------------------------------------------------------------


34. How to resize the image?

A. Using size attribute
B. Using width and height attribute
C. Both A & B.
D. None of the above

-------------------------------------------------------------------------


35. In which tag colspan is used?

A. <table>
B. <tr>
C. <td>
D. All of the above

-------------------------------------------------------------------------


36. Which attribute is used to identify an element uniquely?

A. id
B. class
C. style
D. All of the above

-------------------------------------------------------------------------


37. Which tag is used for the title text for row and column?

A. td
B. tr
C. th
D. None

38. Page designed in HTML is called

A. Web Page
B. Server Page
C. Front Page
D. Text Page

39. The symbol used at the beginning of the href tag is

A. @
B. #
C. $
D. %

40. Where do you place the title tag?

A. Body
B. Head
C. Meta
D. None

SQL server tricky questions