- What are the different types of joins and what dies each do?
- What are the four main query statements?
- What is a sub-query? When would you use one?
- What is a NOLOCK?
- What are three SQL keywords used to change or set someone’s permissions?
- What is the difference between HAVING clause and the WHERE clause?
- What is referential integrity? What are the advantages of it?
- What is database normalization?
- Which command using Query Analyzer will give you the version of SQL server and operating system?
- Using query analyzer, name 3 ways you can get an accurate count of the number of records in a table?
- What is the purpose of using COLLATE in a query?
- What is a trigger?
- What is one of the first things you would do to increase performance of a query? For example, a boss tells you that “a query that ran yesterday took 30 seconds, but today it takes 6 minutes”
- What is an execution plan? When would you use it? How would you view the execution plan?
- What is the STUFF function and how does it differ from the REPLACE function?
- What does it mean to have quoted_identifier on? What are the implications of having it off?
- What are the different types of replication? How are they used?
- What is the difference between a local and a global variable?
- What is the difference between a Local temporary table and a Global temporary table? How is each one used?
- What are cursors? Name four types of cursors and when each one would be applied?
- What is the purpose of UPDATE STATISTICS?
- How do you use DBCC statements to monitor various aspects of a SQL server installation?
- How do you load large data to the SQL server database?
- How do you check the performance of a query and how do you optimize it?
- How do SQL server 2000 and XML linked? Can XML be used to access data?
- What is SQL server agent?
- What is referential integrity and how is it achieved?
- What is indexing?
- What is normalization and what are the different forms of normalizations?
- Difference between server.transfer and server.execute method?
- What id de-normalization and when do you do it?
- What is better - 2nd Normal form or 3rd normal form? Why?
- Can we rewrite subqueries into simple select statements or with joins? Example?
- What is a function? Give some example?
- What is a stored procedure?
- Difference between Function and Procedure-in general?
- Difference between Function and Stored Procedure?
- Can a stored procedure call another stored procedure. If yes what level and can it be controlled?
- Can a stored procedure call itself(recursive). If yes what level and can it be controlled.?
- How do you find the number of rows in a table?
- Difference between Cluster and Non-cluster index?
- What is a table called, if it does not have neither Cluster nor Non-cluster Index?
- Explain DBMS, RDBMS?
- Explain basic SQL queries with SELECT from where Order By, Group By-Having?
- Explain the basic concepts of SQL server architecture?
- Explain couple pf features of SQL server
- Scalability, Availability, Integration with internet, etc.)?
- Explain fundamentals of Data ware housing & OLAP?
- Explain the new features of SQL server 2000?
- How do we upgrade from SQL Server 6.5 to 7.0 and 7.0 to 2000?
- What is data integrity? Explain constraints?
- Explain some DBCC commands?
- Explain sp_configure commands, set commands?
- Explain what are db_options used for?
- What is the basic functions for master, msdb, tempdb databases?
- What is a job?
- What are tasks?
- What are primary keys and foreign keys?
- How would you Update the rows which are divisible by 10, given a set of numbers in column?
- If a stored procedure is taking a table data type, how it looks?
- How m-m relationships are implemented?
- How do you know which index a table is using?
- How will oyu test the stored procedure taking two parameters namely first name and last name returning full name?
- How do you find the error, how can you know the number of rows effected by last SQL statement?
- How can you get @@error and @@rowcount at the same time?
- What are sub-queries? Give example? In which case sub-queries are not feasible?
- What are the type of joins? When do we use Outer and Self joins?
- Which virtual table does a trigger use?
- How do you measure the performance of a stored procedure?
- Questions regarding Raiseerror?
- Questions on identity?
- If there is failure during updation of certain rows, what will be the state?
The Msbiinfo provides maximum information about ssis,ssrs,sql server technologies and provides interview questions and videos and real time scenarios.
Showing posts with label datepart in sql serverdatename in sql server. Show all posts
Showing posts with label datepart in sql serverdatename in sql server. Show all posts
Friday, November 25, 2011
SQL SERVER Interview Questions
Thursday, October 20, 2011
SQL SERVER Interview Questions
1.What is DTS in SQL Server ?
Data Transformation Services is used to transfer the data from one source to our required destination. Considering am having some data in sql server and I need to transfer the data to Excel destination. Its highly possible with dialogue based tool called Data Transformation services. More customization can be achieved using SSIS. A specialized tool used to do such migration works.
2.What is the significance of NULL value and why should we avoid permitting null values?
Null means no entry has been made. It implies that the value is either unknown or undefined.We should avoid permitting null values because Column with NULL values can't have PRIMARY KEY constraints. Certain calculations can be inaccurate if NULL columns are involved.
3.Difference between primary key and Unique key?
Both constraints will share a common property called uniqueness. The data in the column should be unique. The basic difference is,
· Primary key won’t allow null value. Whereas, unique key will accept null value but only one null value.
· On creating primary key, it will automatically format the data inturn creates clustered index on the table. Whereas, this characteristics is not associated with unique key.
· Only one primary key can be created for the table. Any number of Unique key can be created for the table.
5.What is the difference between UNION ALL Statement and UNION ?
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.
8.What is a view?
If we have several tables in a db and we want to view only specific columns from specific tables we can go for views. It would also suffice the needs of security some times allowing specfic users to see only specific columns based on the permission that we can configure on the view. Views also reduce the effort that is required for writing queries to access specific columns every time.
9.What is an Index?
When queries are run against a db, an index on that db basically helps in the way the data is sorted to process the query for faster and data retrievals are much faster when we have an index.
Data Transformation Services is used to transfer the data from one source to our required destination. Considering am having some data in sql server and I need to transfer the data to Excel destination. Its highly possible with dialogue based tool called Data Transformation services. More customization can be achieved using SSIS. A specialized tool used to do such migration works.
2.What is the significance of NULL value and why should we avoid permitting null values?
Null means no entry has been made. It implies that the value is either unknown or undefined.We should avoid permitting null values because Column with NULL values can't have PRIMARY KEY constraints. Certain calculations can be inaccurate if NULL columns are involved.
3.Difference between primary key and Unique key?
Both constraints will share a common property called uniqueness. The data in the column should be unique. The basic difference is,
· Primary key won’t allow null value. Whereas, unique key will accept null value but only one null value.
· On creating primary key, it will automatically format the data inturn creates clustered index on the table. Whereas, this characteristics is not associated with unique key.
· Only one primary key can be created for the table. Any number of Unique key can be created for the table.
4.What is a stored procedure:
Stored procedures are precompiled T-SQL statements combined to perform a single task of several tasks. Its basically like a Macro so when you invoke the Stored procedure, you actually run a set of statements. As, its precompiled statement, execution of Stored procedure is compatatively high when compared to an ordinary T-SQL statement.
Stored procedures are precompiled T-SQL statements combined to perform a single task of several tasks. Its basically like a Macro so when you invoke the Stored procedure, you actually run a set of statements. As, its precompiled statement, execution of Stored procedure is compatatively high when compared to an ordinary T-SQL statement.
5.What is the difference between UNION ALL Statement and UNION ?
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.
6.Example for Stored Procedure?
They are three kinds of stored procedures,1.System stored procedure – Start with sp_2. User defined stored procedure – SP created by the user.3. Extended stored procedure – SP used to invoke a process in the external systems.Example for system stored proceduresp_helpdb - Database and its propertiessp_who2 – Gives details about the current user connected to your system. sp_renamedb – Enable you to rename your database
They are three kinds of stored procedures,1.System stored procedure – Start with sp_2. User defined stored procedure – SP created by the user.3. Extended stored procedure – SP used to invoke a process in the external systems.Example for system stored proceduresp_helpdb - Database and its propertiessp_who2 – Gives details about the current user connected to your system. sp_renamedb – Enable you to rename your database
7.What is a trigger?
Triggers are precompiled statements similar to Stored Procedure. It will automatically invoke for a particular operation. Triggers are basically used to implement business rules.
8.What is a view?
If we have several tables in a db and we want to view only specific columns from specific tables we can go for views. It would also suffice the needs of security some times allowing specfic users to see only specific columns based on the permission that we can configure on the view. Views also reduce the effort that is required for writing queries to access specific columns every time.
9.What is an Index?
When queries are run against a db, an index on that db basically helps in the way the data is sorted to process the query for faster and data retrievals are much faster when we have an index.
10.What are the types of indexes available with SQL Server?
There are basically two types of indexes that we use with the SQL ServerClustered -
1. It will format the entire table, inturn physically sort the table.
2. Only one clustered index can be created for a table.
3. Data will be located in the leaf level.
4. By default, primary key will create clustered index on the table.
Non-Clustered Index
1. It wont touch the structure of the table.
2. It forms an index table as reference to the exact data.
3. A reference to the data will be located in the leaf level.
4. For a table, we can create 249 non clustered index.
11.Extent Vs Page?
Pages are low level unit to store the exact data in sql server. Basically, the data will be stored in the mdf, ldf, ndf files. Inturn, pages are logical units available in sql server.The size of the page is 8KB.
Eight consecutive pages will form an extent 8 * 8KB = 64KB.
Thus I/O level operation will be happening at pages level.The pages will hold a template information at the start of each page (header of the page).
They are,
1. page number,
2. page type,
3. the amount of free space on the page,
4. the allocation unit ID of the object that owns the page.
Extents will be classifed into two types,
1. Uniform extents
2. Mixed extents
Uniform Extents:It occupied or used by a single object. Inturn, a single object will hold the entire 8 pages.Mixed
Extents:Mulitple objects will use the same extent. SQL Server will allow a max of eight objects to use a shared extent.
Property of SQL Server :Initally if an object is created, sql server will allocate the object to the mixed extent and once if the size reaches 8 pages and more... immediately, a new uniform extent will be provided for that particular object.
Herecomes, our fragmentation and reindexing concepts.
some information of sql server:
Maximum Number of tables : No restrictions (Until your harddisk size you can create tables)
Maximum bytes per row in the table : 8060 bytes
Maximum tables in a select statment - 256
Maxiumu references per table - 253
Maximum rows in the table - Unlimited (Depends on the storage)
Maximum columns per base table : 1024
Maximum columns per insert statment : 1024
Maximum columns per Select statment : 1024 * 4 = 4096
Bytes per Group by or Order by = 8000
Index:
Maximum clustered index per table - 1
Maximum Non-clustered index per table - 249
Maximum Columns in an index (composite index) - 16
Keys:
Maximum Columns in a Primary key - 16
Maximum Columns in a Foreign key - 16
Objects:
Nested Stored procedure levels- 32
Nested triggers levels- 32
Parameters per stored procedure - 2100
Parameters per User defined functions - 2100
Identifier length - 16
Database Level Details:
Number of instances for a server - 50
Files per database - 32767
Filegroups per database - 32767
Databases per instance of SQL Server - 32767
Maximum bytes per row in the table : 8060 bytes
Maximum tables in a select statment - 256
Maxiumu references per table - 253
Maximum rows in the table - Unlimited (Depends on the storage)
Maximum columns per base table : 1024
Maximum columns per insert statment : 1024
Maximum columns per Select statment : 1024 * 4 = 4096
Bytes per Group by or Order by = 8000
Index:
Maximum clustered index per table - 1
Maximum Non-clustered index per table - 249
Maximum Columns in an index (composite index) - 16
Keys:
Maximum Columns in a Primary key - 16
Maximum Columns in a Foreign key - 16
Objects:
Nested Stored procedure levels- 32
Nested triggers levels- 32
Parameters per stored procedure - 2100
Parameters per User defined functions - 2100
Identifier length - 16
Database Level Details:
Number of instances for a server - 50
Files per database - 32767
Filegroups per database - 32767
Databases per instance of SQL Server - 32767
12.MSDE vs SQL Server :
MSDE is the downgrade version of SQL Server, the same code with initial release of SQL Server was named as MSDE (Microsoft Desktop Enginer).
13.Extent Vs Page:
Pages are 8 KB size smallest unit to store the data. Inturn, 8 Pages will form the extent.
14.Delete VS Truncate:
Delete will delete row by row in the table. The syntax is,
delete from tablename
We can give where conditions for deleting the data.
Each delete will be logged in the log file.
Its a DML statement
Trucate will deallocate the reference in the pages instead of deleting the data.
Its DDL statement. The syntax is,
Truncate table tablename
We can provide truncate with tables having foreign key relationships. (Because it wont do any cascade delete on the table).
It wont log any information in the log file.
Delete or truncate the data at a stretch and wont do any row by row manipulation.
MSDE is the downgrade version of SQL Server, the same code with initial release of SQL Server was named as MSDE (Microsoft Desktop Enginer).
13.Extent Vs Page:
Pages are 8 KB size smallest unit to store the data. Inturn, 8 Pages will form the extent.
14.Delete VS Truncate:
Delete will delete row by row in the table. The syntax is,
delete from tablename
We can give where conditions for deleting the data.
Each delete will be logged in the log file.
Its a DML statement
Trucate will deallocate the reference in the pages instead of deleting the data.
Its DDL statement. The syntax is,
Truncate table tablename
We can provide truncate with tables having foreign key relationships. (Because it wont do any cascade delete on the table).
It wont log any information in the log file.
Delete or truncate the data at a stretch and wont do any row by row manipulation.
15.What do you mean by acid property?
Atomicity : The value should be atomic.
Consistency : The data in the database should be consistent. It indicates, if we are maintaining data in two different places. Those data should resemble. If it differs, then it will create confusions. Am I right?
Isolation : Transaction should be isolated and it should not affect the other transactions. If the transactions occured on the same data. Appropriate locks should be posted before starting the transactions.
Durability: The data should be stable.
Wednesday, October 19, 2011
DATEPART and DATENAME Functions in SQL SERVER
DATE Functions in SQL SERVER :
DATEPART(): datepart() is a SQL Server function that extracts a specific part of the date/time value. Its syntax is as follows:
DATEPART (part_of_day, expression)examples:
1.SELECT DATEPART(month, GETDATE()) AS 'Month Number'2.SELECT DATEPART(m, 0), DATEPART(d, 0), DATEPART(yy, 0)
DATENAME(): datename() function returns a string value. With the DATENAME function, the only units of time that return values different than the DATEPART function are the WEEKDAY and MONTH.
Unit of time Abbreviations Query Result
DATEDIFF(): DATEDIFF function is used to calculate the difference between two days, and is used in MySQL and SQL Server. The syntax for this date function is different between these two databases, so each one is discussed below:
MySQL:
The usage for the DATEDIFF function
DATEDIFF (expression1, expression2
example: SELECT DATEDIFF('2000-01-10','2000-01-05');
GETDATE(): this function is used to retrieve the current database system time in SQL Server. Its syntax is
GETDATE()
GETDATE does not require any argument.
Example: The SQL statement
SELECT GETDATE();
yields the following result:
2011-10-22 11:27:10.247
GETDATE function is most useful when we need to record the time a particular transaction happens. In SQL Server, we simply insert the value of the GETDATE() function into the table to achieve this. We can also set the default value of a column to be GETDATE() to achieve the same purpose.
| DATEPART (The @Date value used is '2011-09-25 19:47:00.8631597') | |||
| Unit of time | Abbreviations | Query | Result |
| ISO_WEEK | isowk, isoww | SELECT DATEPART(ISO_WEEK,@Date) | 38 |
| TZoffset | tz | SELECT DATEPART(TZoffset,@Date) | 0 |
| NANOSECOND | ns | SELECT DATEPART(NANOSECOND,@Date) | 863159700 |
| MICROSECOND | mcs | SELECT DATEPART(MICROSECOND,@Date) | 863159 |
| MILLISECOND | ms | SELECT DATEPART(MS,@Date) | 863 |
| SECOND | ss, s | SELECT DATEPART(SS,@Date) | 0 |
| MINUTE | mi, n | SELECT DATEPART(MINUTE,@Date) | 47 |
| HOUR | hh | SELECT DATEPART(HH,@Date) | 19 |
| WEEKDAY | dw | SELECT DATEPART(DW,@Date) | 1 |
| WEEK | wk, ww | SELECT DATEPART(WEEK,@Date) | 40 |
| DAY | dd, d | SELECT DATEPART(DAY,@Date) | 25 |
| DAYOFYEAR | dy, y | SELECT DATEPART(DAYOFYEAR,@Date) | 268 |
| MONTH | mm, m | SELECT DATEPART(MM,@Date) | 9 |
| QUARTER | qq, q | SELECT DATEPART(QUARTER,@Date) | 3 |
| YEAR | yy, yyyy | SELECT DATEPART(YYYY,@Date) | 2011 |
| DATENAME (The @Date value used is '2011-09-25 19:47:00.8631597') | |||
| Unit of time | Abbreviations | Query | Result |
| WEEKDAY | dw | SELECT DATENAME(WEEKDAY,@Date) | Sunday |
| MONTH | mm, m | SELECT DATENAME(MM,@Date) | September |
Subscribe to:
Posts (Atom)