.

Wednesday, June 11, 2008

SQL SERVER INTERVIEW QUESTIONS

Question: What is Cascade and Restrict when we use DROP table in SQL SERVER ?
Answer:-
When we are using Drop table in SQL the syntax is simple.
Drop table table_name(CASCADE / RESTRICT)
We use cascade to drop table although it have some dependencies just like triggers,stroeprocrdure,primarykey,foreignkey it will delete first.
But if we use restrict a error message is shown on using of DROP if the table have relation Trigger,storeprocedure.

Question: What is COMMIT & ROLLBACK statement in SQL ?
Answer:
Commit statement helps in termination of the current transaction and do all the changes that occur in transaction persistent and this also commits all the changes to the database.COMMIT we can also use in store procedure.
ROLLBACK do the same thing just terminate the currenct transaction but one another thing is that the changes made to database are ROLLBACK to the database.


Question:-What is diffrence between OSQL and Query Analyzer ?
Answer:-
Both are the same but ther eis little diffrence OSQL is command line tool whic is execute qery and display the result same a query analyzer but query analyzer is graphical and OSQL is a command line tool.OSQL have not ability like query analyzer to analyze queries and show statics on speed of execution and other usefull thing about OSQL is that its helps in scheduling.


Question: What is SQL whats its uses and its component ?
Answer:
The Structured Query Language (SQL) is foundation for all relational database systems. Most of the large-scale databases use the SQL to define all user and administrator interactions. QL is Non-Procedural language . Its allow the user to concentrate on specifying what data is required rather than concentrating on the how to get it.

The DML component of SQL comprises four basic statements:
*
SELECT
to get rows from tables
* UPDATE
to update the rows of tables
* DELETE
to remove rows from tables
* INSERT
to add new rows to tables

Question: What is DTS in SQL Server ?
Answer:
If a organization is big then it is also there that there is multiple option to store data some people are using EXCEL some are using ACCESS and some of they are using SQL SERVER and in some other format also but there a problem is arise that how to merge that data into one format there is diffrent tool are there for doing this funtion. One of product of SQL SERVER-2000 DTS helps in this problem it provides a set of tool from that tool we can customise are database acording to our need DTSRun is a command-prompt utility used to execute existing DTS packages.


Question: What is the diffrence between SQL and Pl/Sql ?
Answer:
We can get modify, Retrieve by single command or statement in SQL but PL/SQL process all SQL statements one at a time. With PL/SQL, an entire block of statements process in a single command line.sql is structured query language ,various queries are used to handle the database in a simplified manner. while pl/sql is procedural language contains various types of variable,functions and procedures and other major diffrence is Sql as the name suggest it is just structured query language wheareas PLSQL is a commbination of Programming language & SQL.


Question: Can You explain integration between SQL Server 2005 and Visual Studio 2005 ?
Answer:
This intergration provide wider range of development with the help of CLR for database server.Becasue CLR helps developers to get flexibility for developing database applications and also provides language interoperability just like Visual C++, Visual Basic .Net and Visual C# .Net. The CLR helps developers to get the arrays, classes and exception handling available through programming languages such as Visual C++ or Visual C# which is use in stored procedures, functions and triggers for creating database application dynamically and also provide more efficient reuse of code and faster execution of complex tasks. We particularly liked the error-checking powers of the CLR environment, which reduces run-time errors


Question: What are Checkpoint in SQL Server ?
Answer:
When we done operation on SQL SERVER that is not commited directly to the database.All operation must be logged in to Transaction Log files after that they should be done on to the main database.CheckPoint are the point which alert Sql Server to save all the data to main database if no check point is there then log files get full we can use Checkpoint command to commit all data in the SQL SERVER.When we stop the SQL Server it will take long time because Checkpoint is also fired.


Question: What is the difference between UNION ALL Statement and UNION ?
Answer:-
The main difference between UNION ALL statement and UNION is UNION All statement is much faster than UNION,the reason behind this is that because UNION ALL statement does not look for duplicate rows, but on the other hand UNION statement does look for duplicate rows, whether or not they exist.


Question: Write some disadvantage of Cursor ?
Answer:-
Cursor plays there row quite nicely but although there are some disadvantage of Cursor .
Because we know cursor doing roundtrip it will make network line busy and also make time consuming methods. First of all select query gernate output and after that cursor goes one by one so roundtrip happen.Another disadvange of cursor are ther are too costly because they require lot of resources and temporary storage so network is quite busy.



Question: What is Log Shipping and its purpose ?
Answer:
In Log Shipping the transactional log file from one server is automatically updated in backup database on the other server and in the case when one server fails the other server will have the same DB and we can use this as the DDR(disaster recovery) plan.


Question: What are the null values in SQL SERVER ?
Answer:
Before understand the null values we have some overview about what the value is. Value is the actual data stored in a particular field of particular record. But what is done when there is no values in the field.That value is something like .Nulls present missing information. We can also called null propagation.


Question: What is difference between OSQL and Query Analyzer ?
Answer:
Both are same for functioning but there is a little difference OSQL is command line tool which execute query and display the result same a Query Analyzer do but Query Analyzer is graphical.OSQL have not ability like Query Analyzer to analyze queries and show statistics on speed of execution .And other useful thing about OSQL is that its helps in scheduling which is done in Query Analyzer with the help of JOB.


Question: Explain some SQL Server 2000 Query?
Answer:
Here are some sql server 2000 query like Sql Insert Query, Delete Sql Query, Update Sql Query and Sql Create Query:
1) Sql Insert Query:
a) How to encrypt data by using Sql Insert Query.
--: insert
into table_name(Tablecolumn1, tablecolumn2,. . . . .) values ('value1', pwdencrypt('value'),. . . .)

b) How to copy data from one table to another with the help of Sql Insert Query.

--: insert into table_name(column1,column2,. . . . ) select column1, column2, . . . . from table_name2

c) Sql Insert Query using where clause
--: insert into tablename(column1,column2) select column1,column2 from tablename2 where id=value.

Question: What is different in Rules and Constraints ?
Answer:
Rules and Constraints are similar in functionality but there is a An little diffrence between them.Rules are used for backward compatibility . One the most exclusive diffrence is that we an bind rules to a datatypes whereas constraints are bound only to columns.So we can create our own datatype with the help of Rules and get the input according to that.


Question: What is defaults in Sql Server and types of Defaults ?
Answer:
Defaults are used when a field of columns is allmost common for all the rows for example in employee table all living in delhi that value of this field is common for all the row in the table if we set this field as default the value that is not fill by us automatically fills the value in the field its also work as intellisense means when user inputing d it will automatically fill the delhi . There are two types of defaults object and definations.
Object deault:-These defaults are applicable on a particular columns . These are usually deined at the time of table designing.When u set the object default field in column state this column in automatically field when u left this filed blank.
Defination default:-When we bind the datatype with default let we named this as dotnet .Then every time we create column and named its datatype as dotnet it will behave the same that we set for dotnet datatype.

Question: what is Relational Database ?
Answer: Although there are different ways to organize data in a database, relational databases are one of the most effective. Relational database systems are an application of mathematical set theory to the problem of effectively organizing data. In a relational database, data is collected into tables (called relations in relational theory). A table represents some class of objects that are important to an organization. For example, a company may have a database with a table for employees, another table for customers, and another for stores. Each table is built of columns and rows (called attributes and tuples in relational theory). Each column represents some attribute of the object represented by the table. For example, an Employee table would typically have columns for attributes such as first name, last name, employee ID, department, pay grade, and job title. Each row represents an instance of the object represented by the table. For example, one row in the Employee table represents the employee who has employee ID 12345. When organizing data into tables, you can usually find many different ways to define tables. Relational database theory defines a process called normalization, which ensures that the set of tables you define will organize your data effectively.

Question: SQL Server runs on which TCP/IP port and From where can you change the default port?
Answer:
SQL Server runs on port 1433 but we can also change it for better security and From the network Utility TCP/IP properties -->Port number.both on client and the server.

Question: What is the use of DBCC commands?
Answer:
DBCC stands for database consistency checker. We use these commands to check the consistency of the databases, i.e., maintenance, validation task and status checks.DBCC CHECKDB - Ensures that tables in the db and the indexes are correctly linked.and DBCC CHECKALLOC To check that all pages in a db are correctly allocated. DBCC SQLPERF - It gives report on current usage of transaction log in percentage. DBCC CHECKFILEGROUP - Checks all tables file group for any damage.


Question: What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?
Answer:
Having Clause is basically used only with the GROUP BY function in a query. WHERE Clause is applied to each row before they are part of the GROUP BY function in a query.


Question: Can you explain what View is in SQL ?
Answer:
View is just a virtual table nothing else which is based or we can say devlop with SQL SELECT query.So we can say that its a real database table (it has columns and rows just like a regular table),but one difference is that real tables store data,but views can’t. View data is generated dynamically when the view is referenced.And view can also references one or more existing database tables or other views. We can say that it is filter of database.


Question: Can you tell me the difference between DELETE &TRUNCATE commands?
Answer:
Delete command removes the rows from a table based on the condition that we provide with a WHERE clause. Truncate will actually remove all the rows from a table and there will be no data in the table after we run the truncate command.

No comments:

.