Tweet
Hire Me on Freelancer.com
Protected by Copyscape Web Plagiarism Finder
Showing posts with label sql server interview questions and answers. Show all posts
Showing posts with label sql server interview questions and answers. Show all posts

Wednesday, 24 October 2012

Mostly asked SQL Server 2005 2008 Interview Qusetion and Answers (Part 1)

Asp.net interview, .NET Interview Questions and Answers, asp.net interview questions, asp.net interview questions and answers, C# interview questions and answers, IIS interview questions and answers, sql server interview questions and answers, vb.net interview questions and answers, XML interview questions and answers, Asp.Net 3.5,Asp.Net 4.0,Asp.Net4.5, Asp.Net C#, VB.Net.



SQL: Queries

1. Write a query to select the second highest salary from a table.
Answer: SELECT max (salary) AS salary2 FROM orders WHERE salary < (SELECT max (salary) AS salary1 FROM orders)

2. Write a query to select the 5th highest salary from a table.
Answer: SELECT min (salary) AS high5 FROM employee WHERE salary IN (SELECT DISTINCT TOP 5 salary FROM orders ORDER BY salary DESC)

3. How to find duplicate records with the number they are duplicated?
Answer: SELECT Id, count (*) as number records from table group by id having count (*) > 1.

SQL: Questions

1. What is the difference between Delete and Truncate command in SQL?
Answer: Delete command and truncate command both will delete the data, however the truncate command cannot be rolled back as delete can be. The delete command can be used for selected records using the where clause but with the truncate command we have to lose data. DELETE statement is a logged operation and hence takes more time then truncate.

2. What is Magic Table in SQL?
Answer: The insert and Delete commands are known as magic tables in SQL.

3. Can Primary key is a Foreign Key on the same table?
Answer: Yes, Consider a category table in an e-commerce web site.
Category_Id, Category Name, Parent_Category_ID. In this table all the parent categories are also categories. When we create a self join category id will be treated as foreign key to the same table.

4. What is Normalization? What are its rules?
Answer: Normalization is the technique in the database design where the idea is to reduce the redundancy of non key data items across the table.

1.       Rule 1: There should be a one-to-one relationship between the instances of an entity and the rows of the table.
2.       Rule 2: A field should have the same meaning in each row of the table.
3.       Rule 3: Each table should represent at most one entity.
4.       Rule 4: Multiple instances of an entity should be represented by multiple rows in a table.
5.       Rule 5: Joins should be based only on primary and foreign-key equality.
6.       Rule 6: Make sure keys are linked correctly.

5. What are the advantages and disadvantages of Normalization?
Answer: There are several advantages of normalization as under:

1.       Faster sorting and index creation.
2.       A larger number of clustered indexes.
3.       Narrower and more compact indexes.
4.       Fewer indexes per tables, which improve the performance of INSERT, UPDATE, and DELETE statements
5.       Fewer null values and less opportunity for inconsistency, which increase database compactness.
6.       Beside the above benefits there are few disadvantages as well:
7.       Increased amount of Normalization increases the amount of complexity of joins between tables and that hinders the performance.

6. What are the conditions to achieve the normalization?
Answer: There are few conditions to achieve the normalization:

1.       There should be a unique row identifier.
2.       A table should store only data for a single type of entity. For e.g. details for book’s publisher and book’s author should be saved under different table.
3.       A table should avoid columns which can be null-able.
4.       A table should avoid duplication of data and columns.

7. What is a Stored Procedure? State its advantage.
Answer: A stored procedure is a set of pre-compiled SQL commands (query statements), which are stored in the server. It is faster than the loose SQL statements processed on client, as it is pre-compiled. It can execute more than one SQL commands once as they are bundled in a single entity. We can use control statements within the stored procedure, which will allow us to repeat some SQL command. It can send return values depending upon the result. Stored procedures are used to reduce network traffic.

8. What is a Trigger?
Answer: Triggers are a special type of stored procedure, which gets invoked upon a certain event. They can be performed upon an INSERT, UPDATE and DELETE.

9. What is a Clustered Index?
Answer: The data rows are stored in order based on the clustered index key. Data stored is in a sequence of the index. In a clustered index, the physical order of the rows in the table is the same as the logical (indexed) order of the key values. A table can contain only one clustered index. A clustered index usually provides faster access to data than does a non-clustered index

10. What is a Non-Clustered Index?
Answer: The data rows are not stored in any particular order, and there is no particular order to the sequence of the data pages. In a non-clustered index, the physical order of the rows in the table is not same as the logical (indexed) order of the key values.

11. Describe the three levels of data abstraction?
They are three levels of abstraction:

1.       Physical level: The lowest level of abstraction describes how data are stored.
2.       Logical level: The next higher level of abstraction, describes what data are stored in database and what relationship among those data.
3.       View level: The highest level of abstraction describes only part of entire database.

12. What is DDL (Data Definition Language)?
Answer: A data base schema which is specified by a set of definitions expressed by a special language is called DDL. Data Definition Language (DDL) is used to define and manage all the objects in an SQL database.

13. What is DML?
Answer: It is a special language used to manipulate the Data. Data Manipulation Language (DML), which is used to select, insert, update, and delete data in the objects defined using DDL.

14. What is a PRIMARY KEY?
Answer: The PRIMARY KEY is the column(s) used to uniquely identify each row of a table.

15. What is a FOREIGN KEY?
Answer: A FOREIGN KEY is one or more columns whose values are based on the PRIMARY or CANDITATE KEY values from the database.

16. What is a UNIQUE KEY?
Answer: A UNIQUE KEY is one or more columns that must be unique for each row of the table.

17. What is the difference between UNIQUE and PRIMARY KEY?
Answer: The UNIQUE KEY column restricts entry of duplicate values but entry of NULL value is allowed. In case of PRIMARY KEY columns entry of duplicate as well as <NULL> value is also restricted.
18. What is a VIEW?
Answer: A View is a database object that is a logical representation of a table. It is derived from a table but has no storage space of its own and often may be used in the same manner as a table.
19. What is a ROWID?
Answer: ROWID is the logical address of a row, and it is unique within the database.

20. What is INDEX?
Answer: INDEX is a general term for an SQL feature used primarily to speed up execution and impose UNIQUENESS upon data. You can use an index to gain fast access to specific information in a database table. An index is a structure that orders the values of one or more columns in a database table. The index provides pointers to the data values stored in specified columns of the table, and then orders those pointers according to the sort order you specify.
21. What is a cursor?
Answer: An entity that maps over a result set and establishes a position on a single row within the result set. After the cursor is positioned on a row, operations can be performed on that row, or on a block of rows starting at that position. The most common operation is to fetch (retrieve) the current row or block of rows.
22. The Difference between ‘Count’ and ‘Count (*)’?
Answer: ‘Count’: Counts the number of non-null values. ‘Count (*)’: Counts the number of rows in the table, including null values and duplicates.

i will appreciate your comments and time for using my blog.
"Necessity is the mother of Invention"

Mostly asked Asp.Net Interview Qusetion and Answers 3.5 , 4.0 (Part 1)

Asp.net interview, .NET Interview Questions and Answers, asp.net interview questions, asp.net interview questions and answers, C# interview questions and answers, IIS interview questions and answers, sql server interview questions and answers, vb.net interview questions and answers, XML interview questions and answers, Asp.Net 3.5,Asp.Net 4.0,Asp.Net4.5, Asp.Net C#, VB.Net.


1. Difference between Classic ASP and ASP.Net?
Answer:
1.       ASP is Interpreted language based on scripting languages like Jscript or VBScript.
2.       ASP has Mixed HTML and coding logic.
3.       Limited development and debugging tools available.
4.       Limited OOPS support.
5.       Limited session and application state management.
6.       Poor Error handling system.
7.       No in-built support for XML.
8.       No fully distributed data source support.
Where
1.       ASP.Net is supported by compiler and has compiled language support.
2.       Separate code and design logic possible.
3.       Variety of compilers and tools available includes the Visual studio.Net.
4.       Completely Object Oriented.
5.       Complete session and application state management.
6.       Full proof error handling possible.
7.       Full XML Support for easy data exchange.
8.       Fully distributed data source support.

2. What’s the difference between Response? Write () and Response.Output.Write ()?
Answer: Response.Output.Write allows us to write the formatted out put.

3. Can you explain the difference between an ADO.NET Dataset and an ADO Recordset?
Answer:

1.       A Dataset can represent an entire relational database in memory, complete with tables, relations, and views, A Record set cannot.
2.       A Dataset is designed to work without any continuing connection to the original data source; Recordset maintains the contentious connection with the original data source.
3.       There’s no concept of cursor types in a DataSet, They are bulk loaded, while Recordset work with cursors and they are loaded on demand.
4.       Datasets have no current record pointer, you can use For Each loops to move through the data. Recordsets have pointers to move through them.
5.       You can store many edits in a DataSet, and write them to the original data source in a single operation. Recordset can have a single edit at a time.
6.       Dataset can fetch source data from many tables at a time, for Recordset you can achieve the same only using the SQL joins.

4. What is the difference between an abstract method & virtual method?
Answer: An Abstract method does not provide an implementation and forces overriding to the deriving class (unless the deriving class also an abstract class), where as the virtual method has an implementation and leaves an option to override the it in the deriving class. Thus Virtual method has an implementation & provides the derived class with the option of overriding it. Abstract method does not provide an implementation & forces the derived class to override the method.

5. What are the different types of assemblies? Explain.
Answer: Assemblies can be static or dynamic. Static assemblies can include .NET Framework types (interfaces and classes), as well as resources for the assembly (bitmaps, JPEG files, resource files, and so on). Static assemblies are stored on disk in portable executable (PE) files. You can also use the .NET Framework to create dynamic assemblies, which are run directly from memory and are not saved to disk before execution. You can save dynamic assemblies to disk after they have executed.

6. What are the difference between Structure and Class?
Answer:

1.       Structures are value type and Classes are reference type.
2.       Structures cannot have constructors or destructors. Classes can have both contractors and destructors.
3.       Structures do not support Inheritance, while Classes support Inheritance.

7. What are the difference between const and readonly?
Answer:

1.       A const cannot be static, while read-only can be static.
2.       A const need to be declared and initialized at declaration only, while a readonly can be initialized at declaration or by the code in the constructor.
3.       A const’s value is evaluated at design time, while a readonly’s value is evaluated at runtime.

8. Differences between dataset.clone and dataset.copy
Answer: dataset.clone copies just the structure of dataset (including all the datatables, schemas, relations and constraints.), However it doesn’t copy the data. On the other hand dataset.copy, copies both the dataset structure and the data.

9. Describe the difference between inline and code behind.
Answer: Inline code written along with the html and design blocks in an .aspx page. Code-behind is code written in a separate file (.cs or .vb ) and referenced by the .aspx page.

10. What is Difference between Namespace and Assembly?
Answer: Namespace is a logical design-time naming convenience, whereas an assembly establishes the name scope for types at run time.

11. What is the difference between early binding and late binding?
Answer: Calling a non-virtual method, decided at a compile time is known as early binding. Calling a virtual method (Pure Polymorphism), decided at a runtime is known as late binding.

12. What is the difference between User Control and Custom Control?
Answer: Custom Controls are compiled code (Dlls), easier to use, difficult to create, and can be placed in toolbox. Drag and Drop controls. Attributes can be set visually at design time. Can be used by Multiple Applications (If Shared Dlls), Even if Private can copy to bin directory of web application add reference and use. Normally designed to provide common functionality independent of consuming Application. User Controls are similar to those of ASP include files, easy to create, cannot be placed in the toolbox and dragged – dropped from it. A User Control is shared among the single application files.

13. What is the difference between ASP Session State and ASP.Net Session State?
Answer: ASP session state relies on cookies, serializes all requests from a client, does not survive process shutdown, and cannot maintained across machines in a Web farm.

14. What is the difference between Data Reader and Dataset?
Answer: Data Reader represents only one database record at a time. You must call the Read () method to fetch each new record from the underlying database table into memory. Each time you call Read () again, the previously fetched record is lost. Dataset is on the other hand, enables you to represent the results of a database query in your server’s memory. Because a Dataset provides you with a memory-resident representation of data, you can work with the results of a database query as a whole. Data Reader must remain connected to a database table. A Data Reader is tied down to its underlying data source. The Dataset object is central to supporting disconnected and distributed data scenarios with ADO.NET. The Dataset is a memory-resident representation of data that provides a consistent relational programming model regardless of the data source. It might be helpful to think of a Data Reader as a forward-only record set. A Dataset, on the other hand, is similar to a disconnected, client-side, static record set. Datasets also require more overhead to create and populate than Data Readers.

 Abbreviations
·         CLR = Common Language Runtime
·         CLS = Common Language Specifications
·         CTS = Common Type Specifications
·         GC = Garbage Collector.
·         WSDL = Web Services Description Language.
·         MSIL = Microsoft Intermediate Language.
·         CIL = Common Intermediate Language – MSIL.
·         JIT = Just In Time.
·         PE = Portable Executable – A file format.
·         COFF = Common Object File Format – A file format.
·         GAC = Global Assembly Cache.
·         DDL = Data Definition Language.
·         DML = Data Manipulation Language.
·         CAS = Code Access Security.
·         RCW = Runtime Callable Wrapper.
·         COM = Component Object Model.
·         CCW = COM Callable Wrapper.
·         DOM = Document Object Model.
·         DNA = Distributed internet Applications Architecture.
·         GUID = Globally Unique Identifier.
·         MS-DTC = Microsoft Distributed Transaction Coordinator.
·         OLTP = Online Transaction Processing.
·         OLAP = Online Analytical Processing.
·         RAD = Rapid Application Development.
·         SMTP = Simple Mail Transfer Protocol.
·         SOAP = Simple Object Access Protocol.
·         TCP = Transport Control Protocol.
·         TLB = Type Library.
·         UDF = Uniform Data Format.
·         UDDI = Universal Description, Discovery and Integration.

True/False
1. A Web service can only be written in .NET?
Answer: False (Java also)

2. To test a Web service you must create a windows application or Web application to consume this service?
Answer: False, the web service comes with a test page and it provides HTTP-GET method to test it.

i will appreciate your comments and time for using my blog.
"Necessity is the mother of Invention"