<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4905884173788197974</id><updated>2011-07-30T14:57:01.639-07:00</updated><category term='Control-of-Flow Language'/><category term='Create Table'/><category term='Table'/><category term='Index'/><category term='Trigger'/><category term='Procedure'/><category term='Rule'/><category term='Default'/><category term='Alter Table'/><category term='Miscellaneous'/><category term='Table and Index'/><category term='Create Database'/><category term='Create view'/><category term='Functions'/><category term='Transactions'/><title type='text'>sqldemo</title><subtitle type='html'>Sql Server Queries and Interview Question!</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://sqldemo.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://sqldemo.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>thangadurai</name><uri>http://www.blogger.com/profile/16066274107687970274</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>15</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4905884173788197974.post-3279192286576382657</id><published>2009-06-27T06:16:00.000-07:00</published><updated>2009-06-27T06:26:02.535-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Miscellaneous'/><title type='text'>Sql Server Interview Question: Miscellaneous</title><content type='html'>&lt;span style="font-weight:bold;"&gt;What is entity?&lt;/span&gt;&lt;br /&gt;In English Query, an entity is a real-world object, referred to by a noun (person, place, thing, or idea), such as people, products, shipments, cities, and so on. Entities are semantic objects.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Define entity integrity?&lt;/span&gt;&lt;br /&gt;A state in which all the rows in a database have a not-null primary key value, all tables have primary keys, and no table has any duplicate primary key values. This ensures that there are no duplicate entries for anything represented in the database.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is domain integrity?&lt;/span&gt;&lt;br /&gt;An integrity mechanism that enforces the validity of entries for a given column. The mechanism, such as the CHECK constraint, can restrict the possible data values by data type, format, or range of values allowed.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Define data integrity?&lt;/span&gt;&lt;br /&gt;A state in which all the data values stored in the database are correct. If incorrect data values have been stored in a database, the database is said to have lost data integrity.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Define primary key (PK)?&lt;/span&gt;&lt;br /&gt;A column or set of columns that uniquely identify all the rows in a table.&lt;br /&gt;Primary keys do not allow null values. No two rows can have the same primary key value; therefore, a primary key value always uniquely identifies a single row.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is Candidate key?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;More than one key can uniquely identify rows in a table, each of these keys is called a candidate key. Only one candidate can be chosen as the primary key of a table;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is Alternate keys?&lt;/span&gt;&lt;br /&gt;all other candidate keys are known as alternate keys. Although tables are not required to have primary keys, it is good practice to define them.&lt;br /&gt;&lt;br /&gt;In a normalized table, all of the data values in each row are fully dependent on the primary key. For example, in a normalized employee table that has EmployeeID as the primary key, all of the columns should contain data related to a specific employee. This table does not have the column DepartmentName because the name of the department is dependent on a department ID, not on an employee ID.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is referenced key?&lt;/span&gt;&lt;br /&gt;A primary key or unique key referenced by a foreign key.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Define referential integrity (RI)?&lt;/span&gt;&lt;br /&gt;A state in which all foreign key values in a database are valid. For a foreign key to be valid, it must contain either the value NULL, or an existing key value from the primary or unique key columns referenced by the foreign key.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is foreign key (FK)?&lt;/span&gt;&lt;br /&gt;The column or combination of columns whose values match the primary key (PK) or unique key in the same or another table. Also called the referencing key.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;&lt;br /&gt;Define foreign table?&lt;/span&gt;&lt;br /&gt;A table that contains a foreign key.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;UNIQUE constraints?&lt;/span&gt;&lt;br /&gt;Constraints that enforce entity integrity on a nonprimary key. UNIQUE constraints ensure that no duplicate values are entered and that an index is created to enhance performance.&lt;br /&gt;&lt;br /&gt;unique index?&lt;br /&gt;An index in which no two rows are permitted to have the same index value, thus prohibiting duplicate index or key values. The system checks for duplicate key values when the index is created and checks each time data is added with an INSERT or UPDATE statement.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;uniqueidentifier data type?&lt;/span&gt;&lt;br /&gt;A data type containing a unique identification number stored as a 16-byte binary string used for storing a globally unique identifier (GUID).&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is candidate key?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A column or set of columns that have a unique value for each row in a table. Each candidate key value uniquely identifies a single row in the table. Tables can have multiple candidate keys. One candidate key in a table is specified by the database designer to be the primary key for the table, and any other candidate key is called an alternate key.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is CHECK constraints?&lt;/span&gt;&lt;br /&gt;Defines which data values are acceptable in a column. You can apply CHECK constraints to multiple columns, and you can apply multiple CHECK constraints to a single column. When a table is dropped, CHECK constraints are also dropped.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Define composite key?&lt;/span&gt;&lt;br /&gt;A key composed of two or more columns.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Define table-level constraint?&lt;/span&gt;&lt;br /&gt;Constraints that allow various forms of data integrity to be defined on one column (column-level constraint) or several columns (table-level constraints) when the table is defined or altered. Constraints support domain integrity, entity integrity, and referential integrity, as well as user-defined integrity.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is declarative referential integrity (DRI)?&lt;/span&gt;&lt;br /&gt;FOREIGN KEY constraints defined as part of a table definition that enforce proper relationships between tables. The constraints ensure that proper actions are taken when DELETE, INSERT, and UPDATE statements remove, add, or modify primary or foreign key values. The DRI actions enforced by FOREIGN KEY constraints can be supplemented with additional referential integrity logic defined in triggers on a table.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is default?&lt;/span&gt;&lt;br /&gt;A data value, option setting, collation, or name assigned automatically by the system if a user does not specify the value, setting, collation, or name. An action taken automatically at certain events if a user has not specified the action to take.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is DEFAULT constraint?&lt;/span&gt;&lt;br /&gt;A property defined for a table column that specifies a constant to be used as the default value for the column. If any subsequent INSERT or UPDATE statement specifies a value of NULL for the column, or does not specify a value for the column, the constant value defined in the DEFAULT constraint is placed in the column.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Define constraint?&lt;/span&gt;&lt;br /&gt;A property assigned to a table column that prevents certain types of invalid data values from being placed in the column. For example, a UNIQUE or PRIMARY KEY constraint prevents you from inserting a value that is a duplicate of an existing value, a CHECK constraint prevents you from inserting a value that does not match a search condition, and NOT NULL prevents you from inserting a NULL value.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Define column-level constraint?&lt;/span&gt;&lt;br /&gt;A constraint definition that is specified within a column definition when a table is created or altered. The constraint applies only to the associated column.]&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;integrity constraint?&lt;/span&gt;&lt;br /&gt;A property defined on a table that prevents data modifications that would create invalid data.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is key column?&lt;/span&gt;&lt;br /&gt;A column referenced by a primary, foreign, or index key.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is denormalize?&lt;/span&gt;&lt;br /&gt;To introduce redundancy into a table in order to incorporate data from a related table. The related table can then be eliminated. Denormalization can improve efficiency and performance by reducing complexity in a data warehouse schema.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Define checkpoint?&lt;/span&gt;&lt;br /&gt;An event in which the database engine writes dirty buffer pages to disk. Dirty pages are pages that have been modified, but the modifications have not yet been written to disk. Each checkpoint writes to disk all pages that were dirty at the last checkpoint and still have not been written to disk. Checkpoints occur periodically based on the number of log records generated by data modifications, or when requested by a user or a system shutdown.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Define Concurrency?&lt;/span&gt;&lt;br /&gt;A process that allows multiple users to access and change shared data at the same time. SQL Server uses locking to allow multiple users to access and change shared data at the same time without conflicting with each other.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is cascading delete?&lt;/span&gt;&lt;br /&gt;An operation that deletes a row containing a primary key value that is referenced by foreign key columns in existing rows in other tables. On a cascade delete, all of the rows whose foreign key values reference the deleted primary key value are also deleted.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is cascading update?&lt;/span&gt;&lt;br /&gt;An operation that updates a primary key value that is referenced by foreign key columns in existing rows in other tables. On a cascade update, all of the foreign key values are updated to match the new primary key value.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Define clustered index?&lt;/span&gt;&lt;br /&gt;An index in which the logical order of the key values determines the physical order of the corresponding rows in a table.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Define composite index?&lt;/span&gt;&lt;br /&gt;An index that uses more than one column in a table to index data.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is leaf level?&lt;/span&gt;&lt;br /&gt;The bottom level of a clustered or nonclustered index. In a clustered index, the leaf level contains the actual data pages of the table. In a nonclustered index, the leaf level either points to data pages or points to the clustered index (if one exists), rather than containing the data itself.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is key range lock?&lt;/span&gt;&lt;br /&gt;A lock used to lock ranges between records in a table to prevent phantom insertions or deletions into a set of records. Ensures serializable transactions.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Define keyset-driven cursor?&lt;/span&gt;&lt;br /&gt;A cursor that shows the effects of updates made to its member rows by other users while the cursor is open, but does not show the effects of inserts or deletes.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Define static cursor?&lt;/span&gt;&lt;br /&gt;A cursor that shows the result set exactly as it was at the time the cursor was opened. Static cursors do not reflect updates, deletes, or inserts made to underlying data while the cursor is open. They are sometimes called snapshot cursors.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Define dynamic cursor?&lt;/span&gt;&lt;br /&gt;A cursor that can reflect data modifications made to the underlying data while the cursor is open. Updates, deletes, and inserts made by users are reflected in the dynamic cursor.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is forward-only cursor?&lt;/span&gt;&lt;br /&gt;A cursor that cannot be scrolled; rows can be read only in sequence from the first row to the last row.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is fragmentation?&lt;/span&gt;&lt;br /&gt;Occurs when data modifications are made. You can reduce fragmentation and improve read-ahead performance by dropping and re-creating a clustered index.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is full-text catalog?&lt;/span&gt;&lt;br /&gt;Stores all of the full-text indexes for tables within a database.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is full-text enabling?&lt;/span&gt;&lt;br /&gt;The process of allowing full-text querying to occur on the current database.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is full-text index?&lt;/span&gt;&lt;br /&gt;The portion of a full-text catalog that stores all of the full-text words and their locations for a given table.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is full-text query?&lt;/span&gt;&lt;br /&gt;As a SELECT statement, a query that searches for words, phrases, or multiple forms of a word or phrase in the character-based columns (of char , varchar , text , ntext , nchar , or nvarchar data types). The SELECT statement returns those rows meeting the search criteria.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is full-text service?&lt;/span&gt;&lt;br /&gt;The SQL Server component that performs the full-text querying.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Define function?&lt;/span&gt;&lt;br /&gt;A piece of code that operates as a single logical unit. A function is called by name, accepts optional input parameters, and returns a status and optional output parameters. Many programming languages support functions, including C, Visual Basic, and Transact-SQL. Transact-SQL supplies built-in functions, which cannot be modified, and supports user-defined functions, which can be created and modified by users.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Define Transaction?&lt;/span&gt;&lt;br /&gt;A group of database operations combined into a logical unit of work that is either wholly committed or rolled back. A transaction is atomic, consistent, isolated, and durable.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;transaction log&lt;/span&gt;&lt;br /&gt;A database file in which all changes to the database are recorded. It is used by SQL Server during automatic recovery.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;transaction rollback?&lt;/span&gt;&lt;br /&gt;Rollback of a user-specified transaction to the last savepoint inside a transaction or to the beginning of a transaction.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;write-ahead log?&lt;/span&gt;&lt;br /&gt;A transaction logging method in which the log is always written prior to the data.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Define concurrency&lt;/span&gt;&lt;br /&gt;A process that allows multiple users to access and change shared data at the same time. SQL Server uses locking to allow multiple users to access and change shared data at the same time without conflicting with each other.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is dirty pages?&lt;/span&gt;&lt;br /&gt;Buffer pages that contain modifications that have not been written to disk.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Define dirty read?&lt;/span&gt;&lt;br /&gt;Reads that contain uncommitted data. For example, transaction1 changes a row. Transaction2 reads the changed row before transaction1 commits the change. If transaction1 rolls back the change, transaction2 has read a row that never logically existed.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;isolation level?&lt;/span&gt;&lt;br /&gt;The property of a transaction that controls the degree to which data is isolated for use by one process and guarded against interference from other processes. Setting the isolation level defines the default locking behavior for all SELECT statements in your SQL Server session.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Savepoint?&lt;/span&gt;&lt;br /&gt;A marker that allows an application to roll back part of a transaction if a minor error is encountered. The application must still commit or roll back the full transaction when it is complete.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;shared lock?&lt;/span&gt;&lt;br /&gt;A lock created by nonupdate (read) operations. Other users can read the data concurrently, but no transaction can acquire an exclusive lock on the data until all the shared locks have been released.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is exclusive lock?&lt;/span&gt;&lt;br /&gt;A lock that prevents any other transaction from acquiring a lock on a resource until the original lock on the resource is released at the end of the transaction. An exclusive lock is always applied during an update operation (INSERT, UPDATE, or DELETE).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Define explicit transaction?&lt;/span&gt;&lt;br /&gt;A group of SQL statements enclosed within transaction delimiters. The first delimiter must be either BEGIN TRANSACTION or BEGIN DISTRIBUTED TRANSACTION, and the end delimiter must be one of the following:&lt;br /&gt;COMMIT TRANSACTION&lt;br /&gt;COMMIT WORK&lt;br /&gt;ROLLBACK TRANSACTION&lt;br /&gt;ROLLBACK WORK&lt;br /&gt;SAVE TRANSACTION.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;implicit transaction?&lt;/span&gt;&lt;br /&gt;A connection option in which each SQL statement executed by the connection is considered a separate transaction.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;incremental update?&lt;/span&gt;&lt;br /&gt;The set of operations that either adds new members to an existing cube or dimension, or adds new data to a partition. One of three processing options for a cube or partition. One of two processing options for a dimension.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Define deadlock?&lt;/span&gt;&lt;br /&gt;A situation when two users, each having a lock on one piece of data, attempt to acquire a lock on the other's piece. Each user would wait indefinitely for the other to release the lock, unless one of the user processes is terminated. SQL Server detects deadlocks and terminates one user's process.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Define encryption?&lt;/span&gt;&lt;br /&gt;A method for keeping sensitive information confidential by changing data into an unreadable form.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Index?&lt;/span&gt;&lt;br /&gt;In a relational database, a database object that provides fast access to data in the rows of a table, based on key values. Indexes can also enforce uniqueness on the rows in a table. SQL Server supports clustered and nonclustered indexes. The primary key of a table is automatically indexed. In full-text search, a full-text index stores information about significant words and their location within a given column.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;index page?&lt;/span&gt;&lt;br /&gt;A database page containing index rows.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;clustered index?&lt;/span&gt;&lt;br /&gt;An index in which the logical order of the key values determines the physical order of the corresponding rows in a table&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;nonrepeatable read?&lt;/span&gt;&lt;br /&gt;When a transaction reads the same row more than one time, and between the two (or more) reads, a separate transaction modifies that row. Because the row was modified between reads within the same transaction, each read produces different values, which introduces inconsistency.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;normalization rules?&lt;/span&gt;&lt;br /&gt;A set of database design rules that minimizes data redundancy and results in a database in which the database engine and application software can easily enforce integrity.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is NULL?&lt;/span&gt;&lt;br /&gt;An entry that has no explicitly assigned value. NULL is not equivalent to zero or blank. A value of NULL is not considered to be greater than, less than, or equivalent to any other value, including another value of NULL.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is equijoin?&lt;/span&gt;&lt;br /&gt;A join in which the values in the columns being joined are compared for equality, and all columns are included in the results.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Define inner join?&lt;/span&gt;&lt;br /&gt;An operation that retrieves rows from multiple source tables by comparing the values from columns shared between the source tables. An inner join excludes rows from a source table that have no matching rows in the other source tables.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;left outer join?&lt;/span&gt;&lt;br /&gt;A type of outer join in which all rows from the left-most table in the JOIN clause are included. When rows in the left table are not matched by rows in the right table, all result set columns that come from the right table are assigned a value of NULL.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;right outer join?&lt;/span&gt;&lt;br /&gt;A type of outer join in which all rows in the right-most table in the JOIN clause are included. When rows in the right table are not matched in the left table, all result set columns that come from the left table are assigned a value of NULL.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is full outer join?&lt;/span&gt;&lt;br /&gt;A type of outer join in which all rows in all joined tables are included, whether they are matched or not.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;join condition?&lt;/span&gt;&lt;br /&gt;A comparison clause that specifies how tables are related by their join columns.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;full-text index?&lt;/span&gt;&lt;br /&gt;The portion of a full-text catalog that stores all of the full-text words and their locations for a given table.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;heterogeneous data?&lt;/span&gt;&lt;br /&gt;Data stored in multiple formats. For example, data stored in a SQL Server database, a text file, and an Excel spreadsheet.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is error log?&lt;/span&gt;&lt;br /&gt;A text file that records system information from SQL Server.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Define Data Control Language (DCL)?&lt;/span&gt;&lt;br /&gt;The subset of SQL statements used to control permissions on database objects. Permissions are controlled using the GRANT and REVOKE statements.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is data definition language (DDL)?&lt;/span&gt;&lt;br /&gt;A language, usually part of a database management system, that is used to define all attributes and properties of a database, especially row layouts, column definitions, key columns (and sometimes keying methodology), file locations, and storage strategy.&lt;br /&gt;Miscellaneous&lt;br /&gt;A set of system tables, stored in a catalog, that includes definitions of database structures and related information, such as permissions.&lt;br /&gt;What is data dictionary view?&lt;br /&gt;A system table.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is data explosion?&lt;/span&gt;&lt;br /&gt;The exponential growth in size of a multidimensional structure, such as a cube, due to the storage of aggregated data.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;master database?&lt;/span&gt;&lt;br /&gt;The database that controls the operation of each instance of SQL Server. It is installed automatically with each instance of SQL Server and keeps track of user accounts, remote user accounts, and remote servers that each instance can interact with. It also tracks ongoing processes, configurable environment variables, system error messages, tapes and disks available on the system, and active locks.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;model database?&lt;/span&gt;&lt;br /&gt;A database installed with SQL Server that provides the template for new user databases. SQL Server 2000 creates a new database by copying in the contents of the model database and then expanding it to the size requested.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;system databases?&lt;/span&gt;&lt;br /&gt;A set of four databases present in all instances of SQL Server that are used to store system information:&lt;br /&gt;The master database stores all instance-level meta data, and records the location of all other databases.&lt;br /&gt;The tempdb database stores transient objects that only exist for the length of a single statement or connection, such as worktables and temporary tables or stored procedures.&lt;br /&gt;The model database is used as a template for creating all user databases.&lt;br /&gt;The msdb database is used by the SQL Server Agent to record information on jobs, alerts, and backup histories.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;table lock?&lt;/span&gt;&lt;br /&gt;A lock on a table including all data and indexes.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;table scan?&lt;/span&gt;&lt;br /&gt;A data retrieval operation where the database engine must read all the pages in a table to find the rows that qualify for a query.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;many-to-many relationship?&lt;/span&gt;&lt;br /&gt;A relationship between two tables in which rows in each table have multiple matching rows in the related table. Many-to-many relationships are maintained by using a third table called a junction table and adding the primary key columns from each of the other two tables to this table.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;many-to-one relationship?&lt;/span&gt;&lt;br /&gt;A relationship between two tables in which one row in one table can relate to many rows in another table.&lt;br /&gt;one-to-many relationship?&lt;br /&gt;In relational databases, a relationship between two tables in which a single row in the first table can be related to one or more rows in the second table, but a row in the second table can be related only to one row in the first table.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;one-to-one relationship?&lt;/span&gt;&lt;br /&gt;In relational database, a relationship between two tables in which a single row in the first table can be related only to one row in the second table, and a row in the second table can be related only to one row in the first table.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;ODBC data source?&lt;/span&gt;&lt;br /&gt;The location of a set of data that can be accessed using an ODBC driver. Also, a stored definition that contains all of the connection information an ODBC application requires to connect to the data source.&lt;br /&gt;&lt;br /&gt;ODBC driver?&lt;br /&gt;A dynamic-link library (DLL) that an ODBC-enabled application, such as Excel, can use to access an ODBC data source. Each ODBC driver is specific to a database management system (DBMS), such as SQL Server, Access, and so on.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;online analytical processing (OLAP)?&lt;/span&gt;&lt;br /&gt;A technology that uses multidimensional structures to provide rapid access to data for analysis. The source data for OLAP is commonly stored in data warehouses in a relational database.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;online transaction processing (OLTP)?&lt;/span&gt;&lt;br /&gt;A data processing system designed to record all of the business transactions of an organization as they occur. An OLTP system is characterized by many concurrent users actively adding and modifying data.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Open Database Connectivity (ODBC)?&lt;/span&gt;&lt;br /&gt;A data access application programming interface (API) that supports access to any data source for which an ODBC driver is available. ODBC is aligned with the American National Standards Institute (ANSI) and International Organization for Standardization (ISO) standards for a database Call Level Interface (CLI).&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;SQL collation?&lt;/span&gt;&lt;br /&gt;A set of SQL Server 2000 collations whose characteristics match those of commonly-used code page and sort order combinations from earlier versions of SQL Server. SQL collations are compatibility features that let sites choose collations that match the behavior of their earlier systems.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Subquery?&lt;/span&gt;&lt;br /&gt;A SELECT statement nested inside another SELECT, INSERT, UPDATE, or DELETE statement, or inside another subquery.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Correlated subqueries?&lt;/span&gt;&lt;br /&gt;the subquery depends on the outer query for its values&lt;br /&gt;In the subqueries previously discussed, SQL evaluates the subquery once, substitutes the result of the subquery in the search condition, and evaluates the outer-level SELECT based on the value of the search condition. You can also write a subquery that SQL may need to re-evaluate as it examines each new row (WHERE clause) or group of rows (HAVING clause) in the outer-level SELECT. This is called a correlated subquery.&lt;br /&gt;&lt;br /&gt;Correlated names and references&lt;br /&gt;Example: Correlated subquery in a WHERE Clause&lt;br /&gt;Example: Correlated subquery in a HAVING Clause&lt;br /&gt;Example: Correlated subquery in select-list&lt;br /&gt;Example: Correlated subqueries in an UPDATE statement&lt;br /&gt;Example: Correlated subqueries in a DELETE statement&lt;br /&gt;http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=/sqlp/rbafycorrs.htm&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4905884173788197974-3279192286576382657?l=sqldemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqldemo.blogspot.com/feeds/3279192286576382657/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-question.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/3279192286576382657'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/3279192286576382657'/><link rel='alternate' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-question.html' title='Sql Server Interview Question: Miscellaneous'/><author><name>thangadurai</name><uri>http://www.blogger.com/profile/16066274107687970274</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4905884173788197974.post-4990148834000731745</id><published>2009-06-27T06:12:00.000-07:00</published><updated>2009-06-27T06:15:40.823-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Trigger'/><title type='text'>Sql Server Interview Question:Trigger</title><content type='html'>&lt;span style="font-weight:bold;"&gt;What is trigger?&lt;/span&gt;&lt;br /&gt;Creates a trigger, which is a special kind of stored procedure that executes automatically when a user attempts the specified data-modification statement on the specified table. Microsoft® SQL Server™ allows the creation of multiple triggers for any given INSERT, UPDATE, or DELETE statement&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Can we write trigger on view?&lt;/span&gt;&lt;br /&gt;Table | view&lt;br /&gt;Is the table or view on which the trigger is executed and is sometimes called the trigger table or trigger view. Specifying the owner name of the table or view is optional.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is WITH ENCRYPTION in trigger?&lt;/span&gt;&lt;br /&gt;Encrypts the syscomments entries that contain the text of CREATE TRIGGER. Using WITH ENCRYPTION prevents the trigger from being published as part of SQL Server replication.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is AFTER trigger?&lt;/span&gt;&lt;br /&gt;Specifies that the trigger is fired only when all operations specified in the triggering SQL statement have executed successfully. All referential cascade actions and constraint checks also must succeed before this trigger executes.&lt;br /&gt;AFTER is the default, if FOR is the only keyword specified.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Can we write after trigger on views?&lt;/span&gt;&lt;br /&gt;AFTER triggers cannot be defined on views.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is INSTEAD OF trigger?&lt;/span&gt;&lt;br /&gt;Specifies that the trigger is executed instead of the triggering SQL statement, thus overriding the actions of the triggering statements.&lt;br /&gt;&lt;br /&gt;At most, one INSTEAD OF trigger per INSERT, UPDATE, or DELETE statement can be defined on a table or view. However, it is possible to define views on views where each view has its own INSTEAD OF trigger.&lt;br /&gt;&lt;br /&gt;INSTEAD OF triggers are not allowed on updateable views WITH CHECK OPTION. SQL Server will raise an error if an INSTEAD OF trigger is added to an updateable view WITH CHECK OPTION specified. The user must remove that option using ALTER VIEW before defining the INSTEAD OF trigger&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are the data modification statement execute the trigger?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;DELETE] [,] [INSERT] [,] [UPDATE] }&lt;br /&gt;Are keywords that specify which data modification statements, when attempted against this table or view, activate the trigger. At least one option must be specified. Any combination of these in any order is allowed in the trigger definition. If more than one option is specified, separate the options with commas.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are the logical table trigger can have?&lt;/span&gt;&lt;br /&gt;deleted and inserted are logical (conceptual) tables. They are structurally similar to the table on which the trigger is defined, that is, the table on which the user action is attempted, and hold the old values or new values of the rows that may be changed by the user action. For example, to retrieve all values in the deleted table, use:&lt;br /&gt;SELECT *&lt;br /&gt;FROM deleted&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are the datatypes not supported for trigger?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In a DELETE, INSERT, or UPDATE trigger, SQL Server does not allow text, ntext, or image column references in the inserted and deleted tables if the compatibility level is equal to 70.&lt;br /&gt;The text, ntext, and image values in the inserted and deleted tables cannot be accessed. To retrieve the new value in either an INSERT or UPDATE trigger, join the inserted table with the original update table.&lt;br /&gt;When the compatibility level is 65 or lower, null values are returned for inserted or deleted text, ntext, or image columns that allow null values; zero-length strings are returned if the columns are not nullable.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;How many columns we can add on update trigger?&lt;/span&gt;&lt;br /&gt;IF UPDATE (column)&lt;br /&gt;Tests for an INSERT or UPDATE action to a specified column and is not used with DELETE operations. More than one column can be specified. Because the table name is specified in the ON clause, do not include the table name before the column name in an IF UPDATE clause. &lt;br /&gt;&lt;br /&gt;To test for an INSERT or UPDATE action for more than one column, specify a separate UPDATE(column) clause following the first one. IF UPDATE will return the TRUE value in INSERT actions because the columns have either explicit values or implicit (NULL) values inserted.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you enforce business rules by trigger?&lt;/span&gt;&lt;br /&gt;Triggers are often used for enforcing business rules and data integrity. SQL Server provides declarative referential integrity (DRI) through the table creation statements (ALTER TABLE and CREATE TABLE);&lt;br /&gt;&lt;br /&gt;however, DRI does not provide cross-database referential integrity. To enforce referential integrity (rules about the relationships between the primary and foreign keys of tables), use primary and foreign key constraints (the PRIMARY KEY and FOREIGN KEY &lt;br /&gt;keywords of ALTER TABLE and CREATE TABLE).&lt;br /&gt;&lt;br /&gt; If constraints exist on the trigger table, they are checked after the INSTEAD OF trigger execution and prior to the AFTER trigger execution. If the constraints are violated, the INSTEAD OF trigger actions are rolled back and the AFTER trigger is not executed (fired).&lt;br /&gt;&lt;br /&gt;The first and last AFTER triggers to be executed on a table may be specified by using sp_settriggerorder. Only one first and one last AFTER trigger for each of the INSERT, UPDATE, and DELETE operations may be specified on a table; if there are other AFTER triggers on the same table, they are executed randomly.&lt;br /&gt;If an ALTER TRIGGER statement changes a first or last trigger, the first or last attribute set on the modified trigger is dropped, and the order value must be reset with &lt;br /&gt;&lt;br /&gt;sp_settriggerorder.&lt;br /&gt;An AFTER trigger is executed only after the triggering SQL statement, including all referential cascade actions and constraint checks associated with the object updated or deleted, has executed successfully.&lt;br /&gt;&lt;br /&gt;The AFTER trigger sees the effects of the triggering statement as well as all referential cascade UPDATE and DELETE actions caused by the triggering statement.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are Trigger Limitations?&lt;/span&gt;&lt;br /&gt;CREATE TRIGGER must be the first statement in the batch and can apply to only one table.&lt;br /&gt;&lt;br /&gt;A trigger is created only in the current database; however, a trigger can reference objects outside the current database.&lt;br /&gt;If the trigger owner name is specified (to qualify the trigger), qualify the table name in the same way.&lt;br /&gt;&lt;br /&gt;The same trigger action can be defined for more than one user action (for example, INSERT and UPDATE) in the same CREATE TRIGGER statement.&lt;br /&gt;&lt;br /&gt;INSTEAD OF DELETE/UPDATE triggers cannot be defined on a table that has a foreign key with a cascade on DELETE/UPDATE action defined.&lt;br /&gt;&lt;br /&gt;Any SET statement can be specified inside a trigger. The SET option chosen remains in effect during the execution of the trigger and then reverts to its former setting.&lt;br /&gt;&lt;br /&gt;When a trigger fires, results are returned to the calling application, just as with stored procedures. To eliminate having results returned to an application due to a trigger firing, do not include either SELECT statements that return results, or statements that perform variable assignment in a trigger.&lt;br /&gt;&lt;br /&gt;A trigger that includes either SELECT statements that return results to the user or statements that perform variable assignment requires special handling; these returned results would have to be written into every application in which modifications to the trigger table are allowed. If variable assignment must occur in a trigger, use a SET NOCOUNT statement at the beginning of the trigger to eliminate the return of any result sets.&lt;br /&gt;&lt;br /&gt;A TRUNCATE TABLE statement is not caught by a DELETE trigger. Although a TRUNCATE TABLE statement is, in effect, a DELETE without a WHERE clause (it removes all rows), it is not logged and thus cannot execute a trigger.&lt;br /&gt;&lt;br /&gt;Because permission for the TRUNCATE TABLE statement defaults to the table owner and is not transferable, only the table owner should be concerned about inadvertently circumventing a DELETE trigger with a TRUNCATE TABLE statement.&lt;br /&gt;&lt;br /&gt;The WRITETEXT statement, whether logged or unlogged, does not activate a trigger.&lt;br /&gt;These Transact-SQL statements are not allowed in a trigger:&lt;br /&gt;&lt;br /&gt;ALTER DATABASE CREATE DATABASE DISK INIT&lt;br /&gt;DISK RESIZE DROP DATABASE LOAD DATABASE&lt;br /&gt;LOAD LOG RECONFIGURE RESTORE DATABASE&lt;br /&gt;RESTORE LOG  &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is Recursive Triggers?&lt;/span&gt;&lt;br /&gt;SQL Server also allows recursive invocation of triggers when the recursive triggers setting is enabled in sp_dboption.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Recursive triggers allow two types of recursion to occur:&lt;/span&gt;&lt;br /&gt;Indirect recursion&lt;br /&gt;Direct recursion&lt;br /&gt;&lt;br /&gt;With indirect recursion, an application updates table T1, which fires trigger TR1, updating table T2. In this scenario, trigger T2 then fires and updates table T1.&lt;br /&gt;&lt;br /&gt;With direct recursion, the application updates table T1, which fires trigger TR1, updating table T1. Because table T1 was updated, trigger TR1 fires again, and so on.&lt;br /&gt;This example uses both indirect and direct trigger recursion. Assume that two update triggers, TR1 and TR2, are defined on table T1.&lt;br /&gt;&lt;br /&gt; Trigger TR1 updates table T1 recursively. An UPDATE statement executes each TR1 and TR2 one time. In addition, the execution of TR1 triggers the execution of TR1 (recursively) and TR2. The inserted and deleted tables for a given trigger contain rows corresponding only to the UPDATE statement that invoked the trigger.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How many levels we can have nested triggers?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Nested Triggers&lt;/span&gt;&lt;br /&gt;Triggers can be nested to a maximum of 32 levels. If a trigger changes a table on which there is another trigger, the second trigger is activated and can then call a third trigger, and so on. &lt;br /&gt;&lt;br /&gt;If any trigger in the chain sets off an infinite loop, the nesting level is exceeded and the trigger is canceled. To disable nested triggers, set the nested triggers option of sp_configure to 0 (off). The default configuration allows nested triggers. &lt;br /&gt;&lt;br /&gt;If nested triggers is off, recursive triggers is also disabled, regardless of the recursive triggers setting of sp_dboption.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you ALTER TRIGGER?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Alters the definition of a trigger created previously by the CREATE TRIGGER statement&lt;br /&gt;ALTER TRIGGER supports manually updateable views through INSTEAD OF triggers on tables and views. Microsoft® SQL Server™ applies ALTER TRIGGER the same way for all types of triggers (AFTER, INSTEAD-OF).&lt;br /&gt;&lt;br /&gt;The first and last AFTER triggers to be executed on a table may be specified by using sp_settriggerorder. Only one first and one last AFTER trigger may be specified on a table; if there are other AFTER triggers on the same table, they will be executed in an undefined sequence.&lt;br /&gt;&lt;br /&gt;If an ALTER TRIGGER statement changes a first or last trigger, the first or last attribute set on the modified trigger is dropped, and the order value must be reset with sp_settriggerorder.&lt;br /&gt;&lt;br /&gt;An AFTER trigger is executed only after the triggering SQL statement, including all referential cascade actions and constraint checks associated with the object updated or deleted, is executed successfully.&lt;br /&gt;&lt;br /&gt; The AFTER trigger operation checks for the effects of the triggering statement as well as all referential cascade UPDATE and DELETE actions caused by the triggering statement.&lt;br /&gt;&lt;br /&gt;When a DELETE action to a child or referencing table is the result of a CASCADE on a DELETE from the parent table, and an INSTEAD OF trigger on DELETE is defined on that child table, the trigger is ignored and the DELETE action is executed.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you DROP TRIGGER?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Removes one or more triggers from the current database.&lt;br /&gt;You can remove a trigger by dropping it or by dropping the trigger table.&lt;br /&gt;&lt;br /&gt; When a table is dropped, all associated triggers are also dropped. When a trigger is dropped, information about the trigger is removed from the sysobjects and syscomments system tables.&lt;br /&gt;&lt;br /&gt;Use DROP TRIGGER and CREATE TRIGGER to rename a trigger. Use ALTER TRIGGER to change the definition of a trigger.&lt;br /&gt;&lt;br /&gt;For more information about determining dependencies for a specific trigger, see "sp_depends" in this volume.&lt;br /&gt;&lt;br /&gt;For more information about viewing the text of the trigger, see "sp_helptext" in this volume.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you see existing trigger list?&lt;/span&gt;&lt;br /&gt;For more information about viewing a list of existing triggers, see "sp_helptrigger" in this volume.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4905884173788197974-4990148834000731745?l=sqldemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqldemo.blogspot.com/feeds/4990148834000731745/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-questiontrigger.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/4990148834000731745'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/4990148834000731745'/><link rel='alternate' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-questiontrigger.html' title='Sql Server Interview Question:Trigger'/><author><name>thangadurai</name><uri>http://www.blogger.com/profile/16066274107687970274</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4905884173788197974.post-5063696664598755118</id><published>2009-06-27T06:04:00.000-07:00</published><updated>2009-06-27T06:12:19.811-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Transactions'/><title type='text'>Sql Server Interview Question:Transactions</title><content type='html'>&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is Transactions?&lt;/span&gt;&lt;br /&gt;A transaction is a sequence of operations performed as a single logical unit of work. A logical unit of work must exhibit four properties, called the ACID (Atomicity, Consistency, Isolation, and Durability) properties, to qualify as a transaction:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is ACID?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Atomicity&lt;/span&gt;&lt;br /&gt;A transaction must be an atomic unit of work; either all of its data modifications are performed, or none of them is performed.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Consistency&lt;/span&gt;&lt;br /&gt;When completed, a transaction must leave all data in a consistent state. In a relational database, all rules must be applied to the transaction's modifications to maintain all data integrity. All internal data structures, such as B-tree indexes or doubly-linked lists, must be correct at the end of the transaction.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Isolation&lt;/span&gt;&lt;br /&gt;Modifications made by concurrent transactions must be isolated from the modifications made by any other concurrent transactions.&lt;br /&gt;&lt;br /&gt; A transaction either sees data in the state it was in before another concurrent transaction modified it, or it sees the data after the second transaction has completed, but it does not see an intermediate state. &lt;br /&gt;&lt;br /&gt;This is referred to as serializability because it results in the ability to reload the starting data and replay a series of transactions to end up with the data in the same state it was in after the original transactions were performed.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Durability&lt;/span&gt;&lt;br /&gt;After a transaction has completed, its effects are permanently in place in the system. The modifications persist even in the event of a system failure.&lt;br /&gt;&lt;br /&gt;Optimizing Transaction Log Performance&lt;br /&gt;General recommendations for creating transaction log files include:&lt;br /&gt;&lt;br /&gt;Create the transaction log on a physically separate disk or RAID (redundant array of independent disks) device. The transaction log file is written serially; therefore, using a separate, dedicated disk allows the disk heads to stay in place for the next write operation.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Set the original size of the transaction log file to a reasonable size to prevent the file from automatically expanding as more transaction log space is needed. As the transaction log expands, a new virtual log file is created, and write operations to the transaction log wait while the transaction log is expanded. If the transaction log expands too frequently, performance can be affected.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Set the file growth increment percentage to a reasonable size to prevent the file from growing by too small a value. If the file growth is too small compared to the number of log records being written to the transaction log, then the transaction log may need to expand constantly, affecting performance.&lt;br /&gt;&lt;br /&gt;Manually shrink the transaction log files rather than allowing Microsoft® SQL Server™ 2000 to shrink the files automatically. Shrinking the transaction log can affect performance on a busy system due to the movement and locking of data pages.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is Transaction Logs?&lt;/span&gt;&lt;br /&gt;A database in Microsoft® SQL Server™ 2000 has at least one data file and one transaction log file. Data and transaction log information is never mixed on the same file, and individual files are used by only one database.&lt;br /&gt;&lt;br /&gt;SQL Server uses the transaction log of each database to recover transactions. The transaction log is a serial record of all modifications that have occurred in the database as well as the transaction that performed each modification. The transaction log records the start of each transaction. It records the changes to the data and enough information to undo the modifications (if necessary later) made during each transaction. For some large operations, such as CREATE INDEX, the transaction log instead records the fact that the operation took place. The log grows continuously as logged operations occur in the database.&lt;br /&gt;&lt;br /&gt;The transaction log records the allocation and deallocation of pages and the commit or rollback of each transaction. This allows SQL Server either to apply (roll forward) or back out (roll back) each transaction in the following ways:&lt;br /&gt;&lt;br /&gt;A transaction is rolled forward when you apply a transaction log. SQL Server copies the after image of every modification to the database or reruns statements such as CREATE INDEX. These actions are applied in the same sequence in which they originally occurred. At the end of this process, the database is in the same state it was in at the time the transaction log was backed up.&lt;br /&gt;&lt;br /&gt;A transaction is rolled back when you back out an incomplete transaction. SQL Server copies the before images of all modifications to the database since the BEGIN TRANSACTION. If it encounters transaction log records indicating that a CREATE INDEX was performed, it performs operations that logically reverse the statement. These before images and CREATE INDEX reversals are applied in the reverse of their original sequence.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;At a checkpoint, SQL Server ensures that all transaction log records and database pages modified are written to disk. &lt;br /&gt;&lt;br /&gt;During the recovery process of each database that occurs when SQL Server is restarted, a transaction must be rolled forward only when it is not known whether all the data modifications in the transaction were actually written from the SQL Server buffer cache to disk.&lt;br /&gt;&lt;br /&gt; Because a checkpoint forces all modified pages to disk, it represents the point at which the startup recovery must start rolling forward transactions. &lt;br /&gt;&lt;br /&gt;Because all pages modified before the checkpoint are guaranteed to be on disk, there is no need to roll forward anything done before the checkpoint.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is Virtual Log Files?&lt;/span&gt;&lt;br /&gt;Each transaction log file is divided logically into smaller segments called virtual log files. Virtual log files are the unit of truncation for the transaction log. When a virtual log file no longer contains log records for active transactions, it can be truncated and the space becomes available to log new transactions.&lt;br /&gt;&lt;br /&gt;The smallest size for a virtual log file is 256 kilobytes (KB). The minimum size for a transaction log is 512 KB, which provides two 256-KB virtual log files. The number and size of the virtual log files in a transaction log increase as the size of the log file increases. A small log file can have a small number of small virtual log files (for example, a 5-MB log file that comprises five 1-MB virtual log files). &lt;br /&gt;A large log file can have larger virtual log files (for example, a 500-MB log file that comprises ten 50-MB virtual log files).&lt;br /&gt;&lt;br /&gt;Microsoft® SQL Server™ 2000 tries to avoid having many small virtual log files. The number of virtual log files grows much more slowly than the size. If a log file grows in small increments, it tends to have many small virtual log files.&lt;br /&gt; If the log file grows in larger increments, SQL Server creates a smaller number of larger virtual log files.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; For example, if the transaction log is growing by 1-MB increments, the virtual log files are smaller and more numerous compared to a transaction log growing at 50-MB increments. A large number of virtual log files can increase the time taken to perform database recovery.&lt;br /&gt;&lt;br /&gt;As records are written to the log, the end of the log grows from one virtual log file to the next. If there is more than one physical log file for a database, the end of the log grows through each virtual log file in each physical file before circling back to the first virtual log file in the first physical file. Only when all log files are full will the log begin to grow automatically.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Write-Ahead Transaction Log&lt;/span&gt;&lt;br /&gt;Microsoft® SQL Server™ 2000, like many relational databases, uses a write-ahead log. A write-ahead log ensures that no data modifications are written to disk before the associated log record.&lt;br /&gt;&lt;br /&gt;SQL Server maintains a buffer cache into which it reads data pages when data must be retrieved. Data modifications are not made directly to disk, but are instead made to the copy of the page in the buffer cache.&lt;br /&gt;&lt;br /&gt; The modification is not written to disk until either the database is checkpointed, or the modifications must be written to disk so the buffer can be used to hold a new page. Writing a modified data page from the buffer cache to disk is called flushing the page. A page modified in the cache but not yet written to disk is called a dirty page.&lt;br /&gt;&lt;br /&gt;At the time a modification is made to a page in the buffer, a log record is built in the log cache recording the modification. This log record must be written to disk before the associated dirty page is flushed from the buffer cache to disk.&lt;br /&gt;&lt;br /&gt; If the dirty page were flushed before the log record, it would create a modification on disk that could not be rolled back if the server failed before the log record were written to disk. &lt;br /&gt;&lt;br /&gt;SQL Server has logic that prevents a dirty page from being flushed before the associated log record. Because log records are always written ahead of the associated data pages, the log is called a write-ahead log.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Transactions Architecture&lt;/span&gt;&lt;br /&gt;Microsoft® SQL Server™ 2000 maintains the consistency and integrity of each database despite errors that occur in the system. Every application that updates data in a SQL Server database does so using transactions. &lt;br /&gt;&lt;br /&gt;A transaction is a logical unit of work made up of a series of statements (selects, inserts, updates, or deletes). If no errors are encountered during a transaction, all of the modifications in the transaction become a permanent part of the database. If errors are encountered, none of the modifications are made to the database.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;A transaction goes through several phases:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Before the transaction starts, the database is in a consistent state.&lt;br /&gt;&lt;br /&gt;The application signals the start of a transaction. This can be done explicitly with the BEGIN TRANSACTION statement. Alternatively, the application can set options to run in implicit transaction mode; the first Transact-SQL statement executed after the completion of a prior transaction starts a new transaction automatically.&lt;br /&gt;&lt;br /&gt; No record is written to the log when the transaction starts; the first record is written to the log when the application generates the first log record for a data modification.&lt;br /&gt;&lt;br /&gt;The application starts modifying data. These modifications are made one table at a time. As a series of modifications are made, they may leave the database in a temporarily inconsistent intermediate state.&lt;br /&gt;&lt;br /&gt;When the application reaches a point where all the modifications have completed successfully and the database is once again consistent, the application commits the transaction. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This makes all the modifications a permanent part of the database.&lt;br /&gt;If the application encounters some error that prevents it from completing the transaction, it undoes, or rolls back, all the data modifications. This returns the database to the point of consistency it was at before the transaction started.&lt;br /&gt;&lt;br /&gt;SQL Server applications can also run in autocommit mode. In autocommit mode each individual Transact-SQL statement is committed automatically if it is successful and rolled back automatically if it generates an error. &lt;br /&gt;&lt;br /&gt;There is no need for an application running in autocommit mode to issue statements that specifically start or end a transaction.&lt;br /&gt;All Transact-SQL statements run in a transaction: an explicit transaction, an implicit transaction, or an autocommit transaction. &lt;br /&gt;&lt;br /&gt;All SQL Server transactions that include data modifications either reach a new point of consistency and are committed, or are rolled back to the original point of consistency. Transactions are not left in an intermediate state where the database is not consistent.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you Shrinking the Transaction Log?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The size of the log files are physically reduced when:&lt;br /&gt;A DBCC SHRINKDATABASE statement is executed.&lt;br /&gt;A DBCC SHRINKFILE statement referencing a log file is executed.&lt;br /&gt;An autoshrink operation occurs.&lt;br /&gt;&lt;br /&gt;Shrinking a log is dependent on first truncating the log. Log truncation does not reduce the size of a physical log file, it reduces the size of the logical log and marks as inactive the virtual logs that do not hold any part of the logical log. &lt;br /&gt;&lt;br /&gt;A log shrink operation removes enough inactive virtual logs to reduce the log file to the requested size.&lt;br /&gt;&lt;br /&gt;The unit of size reduction is a virtual log. For example, if you have a 600 MB log file that has been divided into six 100 MB virtual logs, the size of the log file can only be reduced in 100 MB increments. The file size can be reduced to sizes such as 500 MB or 400 MB, but it cannot be reduced to sizes such as 433 MB or 525 MB.&lt;br /&gt;&lt;br /&gt;Virtual logs that hold part of the logical log cannot be freed. If all the virtual logs in a log file hold parts of the logical log, the file cannot be shrink until a truncation marks one or more of the virtual logs at the end of the physical log as inactive.&lt;br /&gt;&lt;br /&gt;When any file is shrunk, the space freed must come from the end of the file. When a transaction log file is shrunk, enough virtual logs from the end of the file are freed to reduce the log to the size requested by the user. &lt;br /&gt;&lt;br /&gt;The target_size specified by the user is rounded to the next highest virtual log boundary. For example, if a user specifies a target_size of 325 MB for our sample 600 MB file with 100 MB virtual log files, the last two virtual log files are removed and the new file size is 400 MB.&lt;br /&gt;&lt;br /&gt;In SQL Server 2000, a DBCC SHRINKDATABASE or DBCC SHRINKFILE operation attempts to shrink the physical log file to the requested size (subject to rounding) immediately:&lt;br /&gt;&lt;br /&gt;If no part of the logical log is in the virtual logs beyond the target_size mark, the virtual logs after the target_size mark are freed and the successful DBCC statement completes with no messages.&lt;br /&gt;&lt;br /&gt;If part of the logical log is in the virtual logs beyond the target_size mark, SQL Server 2000 frees as much space as possible and issues an informational message. The message tells you what actions you need to perform to get the logical log out of the virtual logs at the end of the file. After you perform this action, you can then reissue the DBCC statement to free the remaining space.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is Truncating the Transaction Log?&lt;/span&gt;&lt;br /&gt;If log records were never deleted from the transaction log, the logical log would grow until it filled all the available space on the disks holding the physical log files.&lt;br /&gt;&lt;br /&gt; At some point in time, old log records no longer necessary for recovering or restoring a database must be deleted to make way for new log records. The process of deleting these log records to reduce the size of the logical log is called truncating the log.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is Transaction Recovery?&lt;/span&gt;&lt;br /&gt;Every Microsoft® SQL Server™ 2000 database has a transaction log that records data modifications made in the database. &lt;br /&gt;&lt;br /&gt;The log records the start and end of every transaction and associates each modification with a transaction. An instance of SQL Server stores enough information in the log to either redo (roll forward) or undo (roll back) the data modifications that make up a transaction. &lt;br /&gt;&lt;br /&gt;Each record in the log is identified by a unique log sequence number (LSN). All of the log records for a transaction are chained together.&lt;br /&gt;&lt;br /&gt;An instance of SQL Server records many different types of information in the transaction log. Instances of SQL Server 2000 primarily log the logical operations performed. The operation is reapplied to roll forward a modification, and the opposite of the logical operation is performed to roll back a modification.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is dirty pages?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Each instance of SQL Server controls when modifications are written from its data buffers to disk. An instance of SQL Server may cache modifications in buffers for a period of time to optimize disk writes.&lt;br /&gt;&lt;br /&gt; A buffer page that contains modifications that have not yet written to disk is known as a dirty page. Writing a dirty buffer page to disk is called flushing the page. When modifications are cached, care must be taken to ensure that no data modification is flushed before the corresponding log image is written to the log file. This could create a modification that could not be rolled back if necessary. &lt;br /&gt;&lt;br /&gt;To ensure that they can recover all modifications, instances of SQL Server use a write-ahead log, which means that all log images are written to disk before the corresponding data modification.&lt;br /&gt;A commit operation forces all log records for a transaction to the log file so that the transaction is fully recoverable even if the server is shut down. &lt;br /&gt;&lt;br /&gt;A commit operation does not have to force all the modified data pages to disk as long as all the log records are flushed to disk. A system recovery can roll the transaction forward or backward using only the log records.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are the ways of Starting Transactions?&lt;/span&gt;&lt;br /&gt;You can start transactions in Microsoft® SQL Server™ as explicit, autocommit, or&lt;br /&gt; &lt;br /&gt;implicit transactions.&lt;br /&gt;Explicit transactions&lt;br /&gt;&lt;br /&gt;Explicitly start a transaction by issuing a BEGIN TRANSACTION statement.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Autocommit transactions&lt;/span&gt;&lt;br /&gt;This is the default mode for SQL Server. Each individual Transact-SQL statement is committed when it completes. You do not have to specify any statements to control transactions.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Implicit transactions&lt;/span&gt;&lt;br /&gt;Set implicit transaction mode on through either an API function or the Transact-SQL SET IMPLICIT_TRANSACTIONS ON statement. The next statement automatically starts a new transaction. When that transaction is completed, the next Transact-SQL statement starts a new transaction.&lt;br /&gt;&lt;br /&gt;Connection modes are managed at the connection level. If one connection changes from one transaction mode to another it has no effect on the transaction modes of any other connection&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you Ending Transactions?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You can end transactions with either a COMMIT or ROLLBACK statement.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;COMMIT&lt;/span&gt;&lt;br /&gt;If a transaction is successful, commit it. A COMMIT statement guarantees all of the transaction's modifications are made a permanent part of the database. A COMMIT also frees resources, such as locks, used by the transaction.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;ROLLBACK&lt;/span&gt;&lt;br /&gt;If an error occurs in a transaction, or if the user decides to cancel the transaction, then roll the transaction back. A ROLLBACK statement backs out all modifications made in the transaction by returning the data to the state it was in at the start of the transaction. A ROLLBACK also frees resources held by the transaction.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What does the BEGIN TRANSACTION do?&lt;/span&gt;&lt;br /&gt;Marks the starting point of an explicit, local transaction. BEGIN TRANSACTION increments @@TRANCOUNT by 1.&lt;br /&gt;BEGIN TRANSACTION represents a point at which the data referenced by a connection is logically and physically consistent.&lt;br /&gt;&lt;br /&gt;If errors are encountered, all data modifications made after the BEGIN TRANSACTION can be rolled back to return the data to this known state of consistency.&lt;br /&gt;&lt;br /&gt;Each transaction lasts until either it completes without errors and COMMIT TRANSACTION is issued to make the modifications a permanent part of the database, or errors are encountered and all modifications are erased with a ROLLBACK &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;TRANSACTION statement.&lt;/span&gt;&lt;br /&gt;BEGIN TRANSACTION starts a local transaction for the connection issuing the statement. Depending on the current transaction isolation level settings, many resources acquired to support the&lt;br /&gt;&lt;br /&gt;Transact-SQL statements issued by the connection are locked by the transaction until it is completed with either a COMMIT TRANSACTION or ROLLBACK TRANSACTION statement. Transactions left outstanding for long periods of time can prevent other users from accessing these locked resources.&lt;br /&gt;&lt;br /&gt;Although BEGIN TRANSACTION starts a local transaction, it is not recorded in the transaction log until the application subsequently performs an action that must be recorded in the log, such as executing an INSERT, UPDATE, or DELETE statement. &lt;br /&gt;&lt;br /&gt;An application can perform actions such as acquiring locks to protect the transaction isolation level of SELECT statements, but nothing is recorded in the log until the application performs a modification action.&lt;br /&gt;Naming multiple transactions in a series of nested transactions with a transaction name has little effect on the transaction. Only the first (outermost) transaction name is registered with the system.&lt;br /&gt;&lt;br /&gt;A rollback to any other name (other than a valid savepoint name) generates an error. None of the statements executed before the rollback are in fact rolled back at the time this error occurs. The statements are rolled back only when the outer transaction is rolled back.&lt;br /&gt;&lt;br /&gt;BEGIN TRANSACTION starts a local transaction. The local transaction is escalated to a distributed transaction if the following actions are performed before it is committed or rolled back:&lt;br /&gt;&lt;br /&gt;An INSERT, DELETE, or UPDATE statement is executed that references a remote table on a linked server. The INSERT, UPDATE, or DELETE statement fails if the OLE DB provider used to access the linked server does not support the ITransactionJoin interface.&lt;br /&gt;&lt;br /&gt;A call is made to a remote stored procedure when the REMOTE_PROC_TRANSACTIONS option is set to ON.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What does the COMMIT TRANSACTION do?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Marks the end of a successful implicit or user-defined transaction. If @@TRANCOUNT is 1, COMMIT TRANSACTION makes all data modifications performed since the start of the transaction a permanent part of the database, frees the resources held by the connection, and decrements @@TRANCOUNT to 0.&lt;br /&gt;&lt;br /&gt; If @@TRANCOUNT is greater than 1, COMMIT TRANSACTION decrements @@TRANCOUNT only by 1.&lt;br /&gt;&lt;br /&gt;It is the responsibility of the Transact-SQL programmer to issue COMMIT TRANSACTION only at a point when all data referenced by the transaction is logically correct.&lt;br /&gt;&lt;br /&gt;If the transaction committed was a Transact-SQL distributed transaction, COMMIT TRANSACTION triggers MS DTC to use a two-phase commit protocol to commit all the servers involved in the transaction.&lt;br /&gt;&lt;br /&gt;If a local transaction spans two or more databases on the same server, SQL Server uses an internal two-phase commit to commit all the databases involved in the transaction.&lt;br /&gt;&lt;br /&gt;When used in nested transactions, commits of the inner transactions do not free resources or make their modifications permanent.&lt;br /&gt;&lt;br /&gt; The data modifications are made permanent and resources freed only when the outer transaction is committed.&lt;br /&gt;&lt;br /&gt;Each COMMIT TRANSACTION issued when @@TRANCOUNT is greater than 1 simply decrements @@TRANCOUNT by 1. When @@TRANCOUNT is finally decremented to 0, the entire outer transaction is committed. &lt;br /&gt;&lt;br /&gt;Because transaction_name is ignored by SQL Server, issuing a COMMIT TRANSACTION referencing the name of an outer transaction when there are outstanding inner transactions only decrements @@TRANCOUNT by 1.&lt;br /&gt;&lt;br /&gt;Issuing a COMMIT TRANSACTION when @@TRANCOUNT is 0 results in an error that there is no corresponding BEGIN TRANSACTION.&lt;br /&gt;&lt;br /&gt;You cannot roll back a transaction after a COMMIT TRANSACTION statement is issued because the data modifications have been made a permanent part of the database.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What does the SAVE TRANSACTION do?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Sets a savepoint within a transaction.&lt;/span&gt;&lt;br /&gt;A user can set a savepoint, or marker, within a transaction. The savepoint defines a location to which a transaction can return if part of the transaction is conditionally canceled.&lt;br /&gt;&lt;br /&gt;If a transaction is rolled back to a savepoint, it must proceed to completion (with more Transact-SQL statements if needed and a COMMIT TRANSACTION statement), or it must be canceled altogether (by rolling the transaction back to its beginning).&lt;br /&gt;&lt;br /&gt;To cancel an entire transaction, use the form ROLLBACK TRANSACTION transaction_name. All the statements or procedures of the transaction are undone.&lt;br /&gt;SAVE TRANSACTION is not supported in distributed transactions started either explicitly with BEGIN DISTRIBUTED TRANSACTION or escalated from a local transaction.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is Explicit Transactions?&lt;/span&gt;&lt;br /&gt;An explicit transaction is one in which you explicitly define both the start and end of the transaction. Explicit transactions were also called user-defined or user-specified transactions in earlier versions of Microsoft® SQL Server™.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What does the @@TRANCOUNT  do?&lt;/span&gt;&lt;br /&gt;Returns the number of active transactions for the current connection.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4905884173788197974-5063696664598755118?l=sqldemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqldemo.blogspot.com/feeds/5063696664598755118/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/5063696664598755118'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/5063696664598755118'/><link rel='alternate' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview.html' title='Sql Server Interview Question:Transactions'/><author><name>thangadurai</name><uri>http://www.blogger.com/profile/16066274107687970274</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4905884173788197974.post-8909219450416956858</id><published>2009-06-27T06:03:00.000-07:00</published><updated>2009-06-27T06:04:56.217-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Control-of-Flow Language'/><title type='text'>Sql Server Interview Question:Control-of-Flow Language</title><content type='html'>&lt;span style="font-weight:bold;"&gt;What are  Control-of-flow language?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The table shows the Transact-SQL control-of-flow keywords.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Keyword Description&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;BEGIN...END&lt;br /&gt;Defines a statement block.&lt;br /&gt;&lt;br /&gt;BREAK&lt;br /&gt;Exits the innermost WHILE loop.&lt;br /&gt;&lt;br /&gt;CONTINUE&lt;br /&gt;Restarts a WHILE loop.&lt;br /&gt;&lt;br /&gt;GOTO label&lt;br /&gt;Continues processing at the statement following the label as defined by label.&lt;br /&gt;&lt;br /&gt;IF...ELSE&lt;br /&gt;Defines conditional, and optionally, alternate execution when a condition is FALSE.&lt;br /&gt;&lt;br /&gt;RETURN&lt;br /&gt;Exits unconditionally.&lt;br /&gt;&lt;br /&gt;WAITFOR&lt;br /&gt;Sets a delay for statement execution.&lt;br /&gt;&lt;br /&gt;WHILE&lt;br /&gt;Repeats statements while a specific condition is TRUE.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4905884173788197974-8909219450416956858?l=sqldemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqldemo.blogspot.com/feeds/8909219450416956858/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-questioncontrol-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/8909219450416956858'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/8909219450416956858'/><link rel='alternate' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-questioncontrol-of.html' title='Sql Server Interview Question:Control-of-Flow Language'/><author><name>thangadurai</name><uri>http://www.blogger.com/profile/16066274107687970274</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4905884173788197974.post-6816935137527160959</id><published>2009-06-27T05:56:00.000-07:00</published><updated>2009-06-27T06:03:11.747-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Functions'/><title type='text'>Sql Server Interview Question: Functions</title><content type='html'>&lt;span style="font-weight:bold;"&gt;What is Deterministic and Nondeterministic Functions?&lt;/span&gt;&lt;br /&gt;All functions are deterministic or nondeterministic&lt;br /&gt;&lt;br /&gt;Deterministic functions always return the same result any time they are called with a specific set of input values.&lt;br /&gt;&lt;br /&gt;Nondeterministic functions may return different results each time they are called with a specific set of input values.&lt;br /&gt;&lt;br /&gt;Whether a function is deterministic or nondeterministic is called the determinism of the function.&lt;br /&gt;&lt;br /&gt;For example, the DATEADD built-in function is deterministic because it always returns the same result for any given set of argument values for its three parameters. GETDATE is not deterministic because it is always invoked with the same argument, yet the value it returns changes each time it is executed.&lt;br /&gt;&lt;br /&gt;Earlier versions of Microsoft® SQL Server™ have no functionality that is dependent on the determinism of functions. In Microsoft SQL Server 2000, nondeterministic functions cannot be specified in two types of Transact-SQL expressions:&lt;br /&gt;&lt;br /&gt;An index cannot be created on a computed column if the computed_column_expression references any nondeterministic functions.&lt;br /&gt;&lt;br /&gt;A clustered index cannot be created on a view if the view references any nondeterministic functions.&lt;br /&gt;&lt;br /&gt;One of the properties SQL Server records for user-defined functions is whether the function is deterministic. A nondeterministic user-defined function cannot be invoked by either a view or computed column if you want to create an index on the view or computed column.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is Built-in Function Determinism?&lt;/span&gt;&lt;br /&gt;You cannot influence the determinism of any built-in function. Each built-in function is deterministic or nondeterministic based on how the function is implemented by Microsoft SQL Server.&lt;br /&gt;&lt;br /&gt;All of the aggregate and string built-in functions are deterministic except the string functions CHARINDEX and PATINDEX. For a list of these functions, see Aggregate Functions and String Functions.&lt;br /&gt;&lt;br /&gt;These built-in functions from categories of built-in functions other than aggregate and string functions are always deterministic:&lt;br /&gt;&lt;br /&gt;ABS DATEDIFF PARSENAME&lt;br /&gt;ACOS DAY POWER&lt;br /&gt;ASIN DEGREES RADIANS&lt;br /&gt;ATAN EXP ROUND&lt;br /&gt;ATN2 FLOOR SIGN&lt;br /&gt;CEILING ISNULL SIN&lt;br /&gt;COALESCE ISNUMERIC SQUARE&lt;br /&gt;COS LOG SQRT&lt;br /&gt;COT LOG10 TAN&lt;br /&gt;DATALENGTH MONTH YEAR&lt;br /&gt;DATEADD NULLIF &lt;br /&gt;&lt;br /&gt;These functions are not always deterministic but can be used in indexed views or indexes on computed columns when they are specified in a deterministic manner.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Function Comments&lt;/span&gt;&lt;br /&gt;CAST Deterministic unless used with datetime, smalldatetime, or sql_variant.&lt;br /&gt;CONVERT Deterministic unless used with datetime, smalldatetime, or sql_variant. The datetime and smalldatetime data types are deterministic if the style parameter is also specified.&lt;br /&gt;&lt;br /&gt;CHECKSUM Deterministic, with the exception of CHECKSUM(*).&lt;br /&gt;ISDATE Deterministic only if used with the CONVERT function, the CONVERT style parameter is specified and style is not equal to 0, 100, 9, or 109.&lt;br /&gt;RAND RAND is deterministic only when a seed parameter is specified.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is non deterministic function?&lt;/span&gt;&lt;br /&gt;All of the configuration, cursor, meta data, security, and system statistical functions are nondeterministic. For a list of these functions, see Configuration Functions, Cursor Functions, Meta Data Functions, Security Functions, and System Statistical Functions.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;These built-in functions from other categories are always nondeterministic:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;@@ERROR FORMATMESSAGE NEWID&lt;br /&gt;@@IDENTITY GETANSINULL PATINDEX&lt;br /&gt;@@ROWCOUNT GETDATE PERMISSIONS&lt;br /&gt;@@TRANCOUNT GetUTCDate SESSION_USER&lt;br /&gt;APP_NAME HOST_ID STATS_DATE&lt;br /&gt;CHARINDEX HOST_NAME SYSTEM_USER&lt;br /&gt;CURRENT_TIMESTAMP IDENT_INCR TEXTPTR&lt;br /&gt;CURRENT_USER IDENT_SEED TEXTVALID&lt;br /&gt;DATENAME IDENTITY USER_NAME&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are the types of Functions ?&lt;/span&gt;&lt;br /&gt;The Transact-SQL programming language provides three types of functions:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Rowset functions&lt;/span&gt;&lt;br /&gt;Can be used like table references in an SQL statement. For more information about a list of these functions, see Rowset Functions.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Aggregate functions&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Operate on a collection of values but return a single, summarizing value. For more information about a list of these functions, see Aggregate Functions.&lt;br /&gt;Scalar functions&lt;br /&gt;&lt;br /&gt;Operate on a single value and then return a single value. Scalar functions can be used wherever an expression is valid. This table categorizes the scalar functions.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Function category Explanation&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Configuration Functions&lt;/span&gt;&lt;br /&gt;Returns information about the current configuration.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Cursor Functions&lt;/span&gt;&lt;br /&gt;Returns information about cursors.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Date and Time Functions&lt;/span&gt;&lt;br /&gt;Performs an operation on a date and time input value and returns either a string, numeric, or date and time value.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Mathematical Functions&lt;/span&gt;&lt;br /&gt;Performs a calculation based on input values provided as parameters to the function, and returns a numeric value.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Metadata Functions&lt;/span&gt;&lt;br /&gt;Returns information about the database and database objects.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Security Functions&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Returns information about users and roles.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;String Functions&lt;/span&gt;&lt;br /&gt;Performs an operation on a string (char or varchar) input value and returns a string or numeric value.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;System Functions&lt;/span&gt;&lt;br /&gt;Performs operations and returns information about values, objects, and settings in Microsoft® SQL Server™.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;System Statistical Functions&lt;/span&gt;&lt;br /&gt;Returns statistical information about the system.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Text and Image Functions&lt;/span&gt;&lt;br /&gt;Performs an operation on a text or image input values or column, and returns information about the value.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are the Configuration Functions?&lt;/span&gt;&lt;br /&gt;These scalar functions return information about current configuration option settings.&lt;br /&gt;&lt;br /&gt;@@DATEFIRST&lt;br /&gt;@@OPTIONS&lt;br /&gt;&lt;br /&gt;@@DBTS&lt;br /&gt;@@REMSERVER&lt;br /&gt;&lt;br /&gt;@@LANGID&lt;br /&gt;@@SERVERNAME&lt;br /&gt;&lt;br /&gt;@@LANGUAGE&lt;br /&gt;@@SERVICENAME&lt;br /&gt;&lt;br /&gt;@@LOCK_TIMEOUT&lt;br /&gt;@@SPID&lt;br /&gt;&lt;br /&gt;@@MAX_CONNECTIONS&lt;br /&gt;@@TEXTSIZE&lt;br /&gt;&lt;br /&gt;@@MAX_PRECISION&lt;br /&gt;@@VERSION&lt;br /&gt;&lt;br /&gt;@@NESTLEVEL&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;All configuration functions are nondeterministic; they do not always return the same results every time they are called with a specific set of input values.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are the Cursor Functions?&lt;/span&gt;&lt;br /&gt;These scalar functions return information about cursors.&lt;br /&gt;@@CURSOR_ROWS&lt;br /&gt;CURSOR_STATUS&lt;br /&gt;@@FETCH_STATUS&lt;br /&gt;All cursor functions are nondeterministic; they do not always return the same results every time they are called with a specific set of input values.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are the Date and Time Functions?&lt;/span&gt;&lt;br /&gt;These scalar functions perform an operation on a date and time input value and return a string, numeric, or date and time value.&lt;br /&gt;This table lists the date and time functions and their determinism property. For more information about function determinism, see Deterministic and Nondeterministic Functions.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Function Determinism&lt;/span&gt;&lt;br /&gt;DATEADD&lt;br /&gt;Deterministic&lt;br /&gt;DATEDIFF&lt;br /&gt;Deterministic&lt;br /&gt;DATENAME&lt;br /&gt;Nondeterministic&lt;br /&gt;DATEPART&lt;br /&gt;Deterministic except when used as DATEPART (dw, date). dw, the weekday datepart, depends on the value set by SET DATEFIRST, which sets the first day of the week.&lt;br /&gt;DAY&lt;br /&gt;Deterministic&lt;br /&gt;GETDATE&lt;br /&gt;Nondeterministic&lt;br /&gt;GETUTCDATE&lt;br /&gt;Nondeterministic&lt;br /&gt;MONTH&lt;br /&gt;Deterministic&lt;br /&gt;YEAR&lt;br /&gt;Deterministic&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are the Mathematical Functions?&lt;/span&gt;&lt;br /&gt;These scalar functions perform a calculation, usually based on input values provided as arguments, and return a numeric value.&lt;br /&gt;ABS&lt;br /&gt;DEGREES&lt;br /&gt;RAND&lt;br /&gt;&lt;br /&gt;ACOS&lt;br /&gt;EXP&lt;br /&gt;ROUND&lt;br /&gt;&lt;br /&gt;ASIN&lt;br /&gt;FLOOR&lt;br /&gt;SIGN&lt;br /&gt;&lt;br /&gt;ATAN&lt;br /&gt;LOG&lt;br /&gt;SIN&lt;br /&gt;&lt;br /&gt;ATN2&lt;br /&gt;LOG10&lt;br /&gt;SQUARE&lt;br /&gt;&lt;br /&gt;CEILING&lt;br /&gt;PI&lt;br /&gt;SQRT&lt;br /&gt;&lt;br /&gt;COS&lt;br /&gt;POWER&lt;br /&gt;TAN&lt;br /&gt;&lt;br /&gt;COT&lt;br /&gt;RADIANS&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are the Meta Data Functions?&lt;/span&gt;&lt;br /&gt;These scalar functions return information about the database and database objects.&lt;br /&gt;COL_LENGTH&lt;br /&gt;fn_listextendedproperty&lt;br /&gt;&lt;br /&gt;COL_NAME&lt;br /&gt;FULLTEXTCATALOGPROPERTY&lt;br /&gt;&lt;br /&gt;COLUMNPROPERTY&lt;br /&gt;FULLTEXTSERVICEPROPERTY&lt;br /&gt;&lt;br /&gt;DATABASEPROPERTY&lt;br /&gt;INDEX_COL&lt;br /&gt;&lt;br /&gt;DATABASEPROPERTYEX&lt;br /&gt;INDEXKEY_PROPERTY&lt;br /&gt;&lt;br /&gt;DB_ID&lt;br /&gt;INDEXPROPERTY&lt;br /&gt;&lt;br /&gt;DB_NAME&lt;br /&gt;OBJECT_ID&lt;br /&gt;&lt;br /&gt;FILE_ID&lt;br /&gt;OBJECT_NAME&lt;br /&gt;&lt;br /&gt;FILE_NAME&lt;br /&gt;OBJECTPROPERTY&lt;br /&gt;&lt;br /&gt;FILEGROUP_ID&lt;br /&gt;@@PROCID&lt;br /&gt;&lt;br /&gt;FILEGROUP_NAME&lt;br /&gt;SQL_VARIANT_PROPERTY&lt;br /&gt;&lt;br /&gt;FILEGROUPPROPERTY&lt;br /&gt;TYPEPROPERTY&lt;br /&gt;&lt;br /&gt;FILEPROPERTY&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;All meta data functions are nondeterministic.  They do not always return the same results every time they are called with a specific set of input values.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are the Security Functions?&lt;/span&gt;&lt;br /&gt;These scalar functions return information about users and roles.&lt;br /&gt;fn_trace_geteventinfo&lt;br /&gt;IS_SRVROLEMEMBER&lt;br /&gt;&lt;br /&gt;fn_trace_getfilterinfo&lt;br /&gt;SUSER_SID&lt;br /&gt;&lt;br /&gt;fn_trace_getinfo&lt;br /&gt;SUSER_SNAME&lt;br /&gt;&lt;br /&gt;fn_trace_gettable&lt;br /&gt;USER_ID&lt;br /&gt;&lt;br /&gt;HAS_DBACCESS&lt;br /&gt;USER&lt;br /&gt;&lt;br /&gt;IS_MEMBER&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;All security functions are nondeterministic. They do not always return the same results every time they are called with a specific set of input values.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are the String Functions&lt;/span&gt;&lt;br /&gt;These scalar functions perform an operation on a string input value and return a string or numeric value.&lt;br /&gt;ASCII&lt;br /&gt;NCHAR&lt;br /&gt;SOUNDEX&lt;br /&gt;&lt;br /&gt;CHAR&lt;br /&gt;PATINDEX&lt;br /&gt;SPACE&lt;br /&gt;&lt;br /&gt;CHARINDEX&lt;br /&gt;REPLACE&lt;br /&gt;STR&lt;br /&gt;&lt;br /&gt;DIFFERENCE&lt;br /&gt;QUOTENAME&lt;br /&gt;STUFF&lt;br /&gt;&lt;br /&gt;LEFT&lt;br /&gt;REPLICATE&lt;br /&gt;SUBSTRING&lt;br /&gt;&lt;br /&gt;LEN&lt;br /&gt;REVERSE&lt;br /&gt;UNICODE&lt;br /&gt;&lt;br /&gt;LOWER&lt;br /&gt;RIGHT&lt;br /&gt;UPPER&lt;br /&gt;&lt;br /&gt;LTRIM&lt;br /&gt;RTRIM&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are the System Functions?&lt;/span&gt;&lt;br /&gt;These scalar functions perform operations on and return information about values, objects, and settings in Microsoft® SQL Server™.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Function Determinism&lt;/span&gt;&lt;br /&gt;APP_NAME&lt;br /&gt;Nondeterministic&lt;br /&gt;CASE expression&lt;br /&gt;Deterministic&lt;br /&gt;CAST and CONVERT&lt;br /&gt;Deterministic unless used with datetime, smalldatetime, or sql_variant.&lt;br /&gt;COALESCE&lt;br /&gt;Deterministic&lt;br /&gt;COLLATIONPROPERTY&lt;br /&gt;Nondeterministic&lt;br /&gt;CURRENT_TIMESTAMP&lt;br /&gt;Nondeterministic&lt;br /&gt;CURRENT_USER&lt;br /&gt;Nondeterministic&lt;br /&gt;DATALENGTH&lt;br /&gt;Deterministic&lt;br /&gt;@@ERROR&lt;br /&gt;Nondeterministic&lt;br /&gt;fn_helpcollations&lt;br /&gt;Deterministic&lt;br /&gt;fn_servershareddrives&lt;br /&gt;Nondeterministic&lt;br /&gt;fn_virtualfilestats&lt;br /&gt;Nondeterministic&lt;br /&gt;FORMATMESSAGE&lt;br /&gt;Nondeterministic&lt;br /&gt;GETANSINULL&lt;br /&gt;Nondeterministic&lt;br /&gt;HOST_ID&lt;br /&gt;Nondeterministic&lt;br /&gt;HOST_NAME&lt;br /&gt;Nondeterministic&lt;br /&gt;IDENT_CURRENT&lt;br /&gt;Nondeterministic&lt;br /&gt;IDENT_INCR&lt;br /&gt;Nondeterministic&lt;br /&gt;IDENT_SEED&lt;br /&gt;Nondeterministic&lt;br /&gt;@@IDENTITY&lt;br /&gt;Nondeterministic&lt;br /&gt;IDENTITY (Function)&lt;br /&gt;Nondeterministic&lt;br /&gt;ISDATE&lt;br /&gt;&lt;br /&gt;Deterministic only if used with the CONVERT function, the CONVERT style parameter is specified and the style parameter is not equal to 0, 100, 9, or 109. Styles 0 and 100 use the default format mon dd yyyy hh:miAM (or PM). Styles 9 and 109 use the default format plus milliseconds mon dd yyyy hh:mi:ss:mmmAM (or PM).&lt;br /&gt;&lt;br /&gt;ISNULL&lt;br /&gt;Deterministic&lt;br /&gt;ISNUMERIC&lt;br /&gt;Deterministic&lt;br /&gt;NEWID&lt;br /&gt;Nondeterministic&lt;br /&gt;NULLIF&lt;br /&gt;Deterministic&lt;br /&gt;PARSENAME&lt;br /&gt;Deterministic&lt;br /&gt;PERMISSIONS&lt;br /&gt;Nondeterministic&lt;br /&gt;@@ROWCOUNT&lt;br /&gt;Nondeterministic&lt;br /&gt;ROWCOUNT_BIG&lt;br /&gt;Nondeterministic&lt;br /&gt;SCOPE_IDENTITY&lt;br /&gt;Nondeterministic&lt;br /&gt;SERVERPROPERTY&lt;br /&gt;Nondeterministic&lt;br /&gt;SESSIONPROPERTY&lt;br /&gt;Nondeterministic&lt;br /&gt;SESSION_USER&lt;br /&gt;Nondeterministic&lt;br /&gt;STATS_DATE&lt;br /&gt;Nondeterministic&lt;br /&gt;SYSTEM_USER&lt;br /&gt;Nondeterministic&lt;br /&gt;@@TRANCOUNT&lt;br /&gt;Nondeterministic&lt;br /&gt;USER_NAME&lt;br /&gt;Nondeterministic&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are the System Statistical Functions?&lt;/span&gt;&lt;br /&gt;These scalar functions return statistical information about the system.&lt;br /&gt;@@CONNECTIONS&lt;br /&gt;@@PACK_RECEIVED&lt;br /&gt;&lt;br /&gt;@@CPU_BUSY&lt;br /&gt;@@PACK_SENT&lt;br /&gt;&lt;br /&gt;fn_virtualfilestats&lt;br /&gt;@@TIMETICKS&lt;br /&gt;&lt;br /&gt;@@IDLE&lt;br /&gt;@@TOTAL_ERRORS&lt;br /&gt;&lt;br /&gt;@@IO_BUSY&lt;br /&gt;@@TOTAL_READ&lt;br /&gt;&lt;br /&gt;@@PACKET_ERRORS&lt;br /&gt;@@TOTAL_WRITE&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;All system statistical functions are nondeterministic;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are the Text and Image Functions?&lt;/span&gt;&lt;br /&gt;These scalar functions perform an operation on a text or image input value or column and return information about the value.&lt;br /&gt;PATINDEX&lt;br /&gt;TEXTPTR&lt;br /&gt;TEXTVALID&lt;br /&gt;These text and image functions are nondeterministic functions and they may not return the same results each time they are called, even with the same set of input values&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4905884173788197974-6816935137527160959?l=sqldemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqldemo.blogspot.com/feeds/6816935137527160959/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-question-functions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/6816935137527160959'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/6816935137527160959'/><link rel='alternate' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-question-functions.html' title='Sql Server Interview Question: Functions'/><author><name>thangadurai</name><uri>http://www.blogger.com/profile/16066274107687970274</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4905884173788197974.post-8122026447174223833</id><published>2009-06-27T05:43:00.000-07:00</published><updated>2009-06-27T05:56:29.408-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Procedure'/><title type='text'>Sql Server Interview Question:Procedure</title><content type='html'>&lt;span style="font-weight:bold;"&gt;What is stored PROCEDURE?&lt;/span&gt;&lt;br /&gt;Creates a stored procedure, which is a saved collection of Transact-SQL statements that can take and return user-supplied parameters.&lt;br /&gt;&lt;br /&gt;Procedures can be created for permanent use or for temporary use within a session (local temporary procedure) or for temporary use within all sessions (global temporary procedure).&lt;br /&gt;&lt;br /&gt;Local or global temporary procedures can be created by preceding the procedure_name with a single number sign (#procedure_name) for local temporary procedures and a double number sign (##procedure_name) for global temporary procedures. The complete name, including # or ##, cannot exceed 128 characters.&lt;br /&gt;Stored procedures can also be created to run automatically when Microsoft® SQL Server™ starts.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is group procedure?&lt;/span&gt;&lt;br /&gt;;number&lt;br /&gt;Is an optional integer used to group procedures of the same name so they can be dropped together with a single DROP PROCEDURE statement.&lt;br /&gt;&lt;br /&gt;For example, the procedures used with an application called orders may be named orderproc;1, orderproc;2, and so on. The statement DROP PROCEDURE orderproc drops the entire group. If the name contains delimited identifiers, the number should not be included as part of the identifier; use the appropriate delimiter around procedure_name only.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is parameter procedure?&lt;/span&gt;&lt;br /&gt;@parameter&lt;br /&gt;Is a parameter in the procedure. One or more parameters can be declared in a CREATE PROCEDURE statement. The value of each declared parameter must be supplied by the user when the procedure is executed (unless a default for the parameter is defined).&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;How many parameter a stored procedure can have?&lt;/span&gt;&lt;br /&gt;A stored procedure can have a maximum of 2,100 parameters.&lt;br /&gt;&lt;br /&gt;What are the datatype you can use for stored procedure parameter?&lt;br /&gt;data_type&lt;br /&gt;Is the parameter data type. All data types, including text, ntext and image, can be used as a parameter for a stored procedure.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Which procedure you can use cursor datatype?&lt;/span&gt;&lt;br /&gt;However, the cursor data type can be used only on OUTPUT parameters. When you specify a data type of cursor, the VARYING and OUTPUT keywords must also be specified&lt;br /&gt;&lt;br /&gt;What is the maximum number of output parameters a procedure can have?&lt;br /&gt;There is no limit on the maximum number of output parameters that can be of cursor data type.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is VARYING in procedure?&lt;/span&gt;&lt;br /&gt;Specifies the result set supported as an output parameter (constructed dynamically by the stored procedure and whose contents can vary). Applies only to cursor parameters.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Can we have default parameter procedure?&lt;/span&gt;&lt;br /&gt;Is a default value for the parameter. If a default is defined, the procedure can be executed without specifying a value for that parameter. The default must be a constant or it can be NULL. It can include wildcard characters (%, _, [], and [^]) if the procedure uses the parameter with the LIKE keyword.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What does the OUTPUT keyword in procedure?&lt;/span&gt;&lt;br /&gt;Indicates that the parameter is a return parameter. The value of this option can be returned to EXEC[UTE]. Use OUTPUT parameters to return information to the calling procedure. Text, ntext, and image parameters can be used as OUTPUT parameters. An output parameter using the OUTPUT keyword can be a cursor placeholder.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is RECOMPILE and ENCRYPTION in stored procedure?&lt;/span&gt;&lt;br /&gt;RECOMPILE indicates that SQL Server does not cache a plan for this procedure and the procedure is recompiled at run time. Use the RECOMPILE option when using atypical or temporary values without overriding the execution plan cached in memory.&lt;br /&gt;&lt;br /&gt;ENCRYPTION indicates that SQL Server encrypts the syscomments table entry containing the text of the CREATE PROCEDURE statement. Using ENCRYPTION prevents the procedure from being published as part of SQL Server replication&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is the maximum size of the stored procedure?&lt;/span&gt;&lt;br /&gt;The maximum size of a stored procedure is 128 MB.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you get  Information About Stored Procedures?&lt;/span&gt;&lt;br /&gt;To display the text used to create the procedure, execute sp_helptext in the database in which the procedure exists with the procedure name as the parameter.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Can we get the text of encrypted procedure?&lt;/span&gt;&lt;br /&gt;Stored procedures created with the ENCRYPTION option cannot be viewed with sp_helptext.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you know what are the objects referenced by procedure?&lt;/span&gt;&lt;br /&gt;For a report on the objects referenced by a procedure, use sp_depends.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Where are the procedure name and its text stored in sql server?&lt;/span&gt;&lt;br /&gt;When a CREATE PROCEDURE statement is executed successfully, the procedure name is stored in the sysobjects system table and the text of the CREATE PROCEDURE statement is stored in syscomments. When executed for the first time, the procedure is compiled to determine an optimal access plan to retrieve the data.&lt;br /&gt;&lt;br /&gt;Rules for Cursor Output Parameters:&lt;br /&gt;The following rules pertain to cursor output parameters when the procedure is executed:&lt;br /&gt;&lt;br /&gt;For a forward-only cursor, the rows returned in the cursor's result set are only those rows at and beyond the position of the cursor at the conclusion of the stored procedure executed, for example:&lt;br /&gt;&lt;br /&gt;A nonscrollable cursor is opened in a procedure on a result set named RS of 100 rows.&lt;br /&gt;&lt;br /&gt;The procedure fetches the first 5 rows of result set RS.&lt;br /&gt;&lt;br /&gt;The procedure returns to its caller.&lt;br /&gt;&lt;br /&gt;The result set RS returned to the caller consists of rows from 6 through 100 of RS, and the cursor in the caller is positioned before the first row of RS.&lt;br /&gt;&lt;br /&gt;For a forward-only cursor, if the cursor is positioned before the first row upon completion of the stored procedure, the entire result set is returned to the calling batch, stored procedure, or trigger. When returned, the cursor position is set before the first row.&lt;br /&gt;&lt;br /&gt;For a forward-only cursor, if the cursor is positioned beyond the end of the last row upon completion of the stored procedure, an empty result set is returned to the calling batch, stored procedure, or trigger.&lt;br /&gt; &lt;br /&gt;Note  An empty result set is not the same as a null value.&lt;br /&gt;&lt;br /&gt;For a scrollable cursor, all the rows in the result set are returned to the calling batch, stored procedure, or trigger at the conclusion of the execution of the stored procedure. When returned, the cursor position is left at the position of the last fetch executed in the procedure.&lt;br /&gt;&lt;br /&gt;For any type of cursor, if the cursor is closed, then a null value is passed back to the calling batch, stored procedure, or trigger. This will also be the case if a cursor is assigned to a parameter, but that cursor is never opened.&lt;br /&gt; &lt;br /&gt;Note  The closed state matters only at return time. For example, it is valid to close a cursor part way through the procedure, to open it again later in the procedure, and return that cursor's result set to the calling batch, stored procedure, or trigger.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Notes about procedure:&lt;/span&gt;&lt;br /&gt;A user-defined stored procedure can be created only in the current database (except for temporary procedures, which are always created in tempdb).&lt;br /&gt;&lt;br /&gt;The CREATE PROCEDURE statement cannot be combined with other Transact-SQL statements in a single batch.&lt;br /&gt;&lt;br /&gt;Parameters are nullable by default. If a NULL parameter value is passed and that parameter is used in a CREATE or ALTER TABLE statement in which the column referenced does not allow NULLs, SQL Server generates an error.&lt;br /&gt;&lt;br /&gt;To prevent passing a NULL parameter value to a column that does not allow NULLs, add programming logic to the procedure or use a default value (with the DEFAULT keyword of CREATE or ALTER TABLE) for the column.&lt;br /&gt;&lt;br /&gt;It is recommended that you explicitly specify NULL or NOT NULL for each column in any CREATE TABLE or ALTER TABLE statement in a stored procedure, such as when creating a temporary table.&lt;br /&gt;&lt;br /&gt;The ANSI_DFLT_ON and ANSI_DFLT_OFF options control the way SQL Server assigns the NULL or NOT NULL attributes to columns if not specified in a CREATE TABLE or ALTER TABLE statement.&lt;br /&gt;&lt;br /&gt;If a connection executes a stored procedure with different settings for these options than the connection that created the procedure, the columns of the table created for the second connection can have different nullability and exhibit different behaviors.&lt;br /&gt;&lt;br /&gt;If NULL or NOT NULL is explicitly stated for each column, the temporary tables are created with the same nullability for all connections that execute the stored procedure.&lt;br /&gt;SQL Server saves the settings of both SET QUOTED_IDENTIFIER and SET ANSI_NULLS when a stored procedure is created or altered. These original settings are used when the stored procedure is executed.&lt;br /&gt;&lt;br /&gt;Therefore, any client session settings for SET QUOTED_IDENTIFIER and SET ANSI_NULLS are ignored during stored procedure execution. SET QUOTED_IDENTIFIER and SET ANSI_NULLS statements that occur within the stored procedure do not affect the functionality of the stored procedure.&lt;br /&gt;&lt;br /&gt;Other SET options, such as SET ARITHABORT, SET ANSI_WARNINGS, or SET ANSI_PADDINGS are not saved when a stored procedure is created or altered.&lt;br /&gt;&lt;br /&gt;If the logic of the stored procedure is dependent on a particular setting, include a SET statement at the start of the procedure to ensure the proper setting. &lt;br /&gt;&lt;br /&gt;When a SET statement is executed from a stored procedure, the setting remains in effect only until the stored procedure completes.&lt;br /&gt; The setting is then restored to the value it had when the stored procedure was called. This allows individual clients to set the options wanted without affecting the logic of the stored procedure.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you ALTER PROCEDURE&lt;/span&gt;&lt;br /&gt;Alters a previously created procedure, created by executing the CREATE PROCEDURE statement, without changing permissions and without affecting any dependent stored procedures or triggers&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are System Stored Procedures&lt;/span&gt;&lt;br /&gt;Many administrative and informational activities in Microsoft® SQL Server™ can be performed through system stored procedures. The system stored procedures are grouped into these categories.&lt;br /&gt;&lt;br /&gt;Category Description&lt;br /&gt;Active Directory Procedures Used to register instances of SQL Server and SQL Server databases in Microsoft Windows® 2000 Active Directory™.&lt;br /&gt;&lt;br /&gt;Catalog Procedures Implements ODBC data dictionary functions and isolates ODBC applications from changes to underlying system tables.&lt;br /&gt;Cursor Procedures Implements cursor variable functionality.&lt;br /&gt;Database Maintenance Plan Procedures Used to set up core maintenance tasks necessary to ensure database performance.&lt;br /&gt;&lt;br /&gt;Distributed Queries Procedures Used to implement and manage Distributed Queries.&lt;br /&gt;Full-Text Search Procedures Used to implement and query full-text indexes.&lt;br /&gt;Log Shipping Procedures Used to configure and manage log shipping.&lt;br /&gt;&lt;br /&gt;OLE Automation Procedures Allows standard OLE automation objects to be used within a standard Transact-SQL batch.&lt;br /&gt;&lt;br /&gt;Replication Procedures Used to manage replication.&lt;br /&gt;Security Procedures Used to manage security.&lt;br /&gt;&lt;br /&gt;SQL Mail Procedures Used to perform e-mail operations from within SQL Server.&lt;br /&gt;SQL Profiler Procedures Used by SQL Profiler to monitor performance and activity.&lt;br /&gt;SQL Server Agent Procedures Used by SQL Server Agent to manage scheduled and event-driven activities.&lt;br /&gt;&lt;br /&gt;System Procedures Used for general maintenance of SQL Server.&lt;br /&gt;Web Assistant Procedures Used by the Web Assistant.&lt;br /&gt;XML Procedures Used for Extensible Markup Language (XML) text management.&lt;br /&gt;General Extended Procedures Provides an interface from SQL Server to external programs for various maintenance activities.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What are catalog procedures?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Catalog Procedures&lt;/span&gt;&lt;br /&gt;sp_column_privileges&lt;br /&gt;sp_special_columns&lt;br /&gt;&lt;br /&gt;sp_columns&lt;br /&gt;sp_sproc_columns&lt;br /&gt;&lt;br /&gt;sp_databases&lt;br /&gt;sp_statistics&lt;br /&gt;&lt;br /&gt;sp_fkeys&lt;br /&gt;sp_stored_procedures&lt;br /&gt;&lt;br /&gt;sp_pkeys&lt;br /&gt;sp_table_privileges&lt;br /&gt;&lt;br /&gt;sp_server_info&lt;br /&gt;sp_tables&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are the cursor procedure?&lt;/span&gt;&lt;br /&gt;Cursor Procedures&lt;br /&gt;sp_cursor_list&lt;br /&gt;sp_describe_cursor_columns&lt;br /&gt;&lt;br /&gt;sp_describe_cursor&lt;br /&gt;sp_describe_cursor_tables&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What are the database maintenance procedure?&lt;/span&gt;&lt;br /&gt;Database Maintenance Plan Procedures&lt;br /&gt;sp_add_maintenance_plan&lt;br /&gt;sp_delete_maintenance_plan_db&lt;br /&gt;&lt;br /&gt;sp_add_maintenance_plan_db&lt;br /&gt;sp_delete_maintenance_plan_job&lt;br /&gt;&lt;br /&gt;sp_add_maintenance_plan_job&lt;br /&gt;sp_help_maintenance_plan&lt;br /&gt;&lt;br /&gt;sp_delete_maintenance_plan&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are the distributed queries procedure?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Distributed Queries Procedures&lt;/span&gt;&lt;br /&gt;sp_addlinkedserver&lt;br /&gt;sp_indexes&lt;br /&gt;&lt;br /&gt;sp_addlinkedsrvlogin&lt;br /&gt;sp_linkedservers&lt;br /&gt;&lt;br /&gt;sp_catalogs&lt;br /&gt;sp_primarykeys&lt;br /&gt;&lt;br /&gt;sp_column_privileges_ex&lt;br /&gt;sp_serveroption&lt;br /&gt;&lt;br /&gt;sp_columns_ex&lt;br /&gt;sp_table_privileges_ex&lt;br /&gt;&lt;br /&gt;sp_droplinkedsrvlogin&lt;br /&gt;sp_tables_ex&lt;br /&gt;&lt;br /&gt;sp_foreignkeys&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are the full-text search procedure&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Full-Text Search Procedures&lt;/span&gt;&lt;br /&gt;sp_fulltext_catalog&lt;br /&gt;sp_help_fulltext_catalogs_cursor&lt;br /&gt;&lt;br /&gt;sp_fulltext_column&lt;br /&gt;sp_help_fulltext_columns&lt;br /&gt;&lt;br /&gt;sp_fulltext_database&lt;br /&gt;sp_help_fulltext_columns_cursor&lt;br /&gt;&lt;br /&gt;sp_fulltext_service&lt;br /&gt;sp_help_fulltext_tables&lt;br /&gt;&lt;br /&gt;sp_fulltext_table&lt;br /&gt;sp_help_fulltext_tables_cursor&lt;br /&gt;&lt;br /&gt;sp_help_fulltext_catalogs&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are the log-shipping procedures?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Log Shipping Procedures&lt;/span&gt;&lt;br /&gt;sp_add_log_shipping_database&lt;br /&gt;sp_delete_log_shipping_database&lt;br /&gt;&lt;br /&gt;sp_add_log_shipping_plan&lt;br /&gt;sp_delete_log_shipping_plan&lt;br /&gt;&lt;br /&gt;sp_add_log_shipping_plan_database&lt;br /&gt;sp_delete_log_shipping_plan_database&lt;br /&gt;&lt;br /&gt;sp_add_log_shipping_primary&lt;br /&gt;sp_delete_log_shipping_primary&lt;br /&gt;&lt;br /&gt;sp_add_log_shipping_secondary&lt;br /&gt;sp_delete_log_shipping_secondary&lt;br /&gt;&lt;br /&gt;sp_can_tlog_be_applied&lt;br /&gt;sp_get_log_shipping_monitor_info&lt;br /&gt;&lt;br /&gt;sp_change_monitor_role&lt;br /&gt;sp_remove_log_shipping_monitor&lt;br /&gt;&lt;br /&gt;sp_change_primary_role&lt;br /&gt;sp_resolve_logins&lt;br /&gt;&lt;br /&gt;sp_change_secondary_role&lt;br /&gt;sp_update_log_shipping_monitor_info&lt;br /&gt;&lt;br /&gt;sp_create_log_shipping_monitor_account&lt;br /&gt;sp_update_log_shipping_plan&lt;br /&gt;&lt;br /&gt;sp_define_log_shipping_monitor&lt;br /&gt;sp_update_log_shipping_plan_database&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;OLE Automation Extended Stored Procedures&lt;/span&gt;&lt;br /&gt;sp_OACreate&lt;br /&gt;sp_OAMethod&lt;br /&gt;&lt;br /&gt;sp_OADestroy&lt;br /&gt;sp_OASetProperty&lt;br /&gt;&lt;br /&gt;sp_OAGetErrorInfo&lt;br /&gt;sp_OAStop&lt;br /&gt;&lt;br /&gt;sp_OAGetProperty&lt;br /&gt;Object Hierarchy Syntax&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Replication Procedures&lt;/span&gt;&lt;br /&gt;sp_add_agent_parameter&lt;br /&gt;sp_enableagentoffload&lt;br /&gt;&lt;br /&gt;sp_add_agent_profile&lt;br /&gt;sp_enumcustomresolvers&lt;br /&gt;&lt;br /&gt;sp_addarticle&lt;br /&gt;sp_enumdsn&lt;br /&gt;&lt;br /&gt;sp_adddistpublisher&lt;br /&gt;sp_enumfullsubscribers&lt;br /&gt;&lt;br /&gt;sp_adddistributiondb&lt;br /&gt;sp_expired_subscription_cleanup&lt;br /&gt;&lt;br /&gt;sp_adddistributor&lt;br /&gt;sp_generatefilters&lt;br /&gt;&lt;br /&gt;sp_addmergealternatepublisher&lt;br /&gt;sp_getagentoffloadinfo&lt;br /&gt;&lt;br /&gt;sp_addmergearticle&lt;br /&gt;sp_getmergedeletetype&lt;br /&gt;&lt;br /&gt;sp_addmergefilter&lt;br /&gt;sp_get_distributor&lt;br /&gt;&lt;br /&gt;sp_addmergepublication&lt;br /&gt;sp_getqueuedrows&lt;br /&gt;&lt;br /&gt;sp_addmergepullsubscription&lt;br /&gt;sp_getsubscriptiondtspackagename&lt;br /&gt;&lt;br /&gt;sp_addmergepullsubscription_agent&lt;br /&gt;sp_grant_publication_access&lt;br /&gt;&lt;br /&gt;sp_addmergesubscription&lt;br /&gt;sp_help_agent_default&lt;br /&gt;&lt;br /&gt;sp_addpublication&lt;br /&gt;sp_help_agent_parameter&lt;br /&gt;&lt;br /&gt;sp_addpublication_snapshot&lt;br /&gt;sp_help_agent_profile&lt;br /&gt;&lt;br /&gt;sp_addpublisher70&lt;br /&gt;sp_helparticle&lt;br /&gt;&lt;br /&gt;sp_addpullsubscription&lt;br /&gt;sp_helparticlecolumns&lt;br /&gt;&lt;br /&gt;sp_addpullsubscription_agent&lt;br /&gt;sp_helparticledts&lt;br /&gt;&lt;br /&gt;sp_addscriptexec&lt;br /&gt;sp_helpdistpublisher&lt;br /&gt;&lt;br /&gt;sp_addsubscriber&lt;br /&gt;sp_helpdistributiondb&lt;br /&gt;&lt;br /&gt;sp_addsubscriber_schedule&lt;br /&gt;sp_helpdistributor&lt;br /&gt;&lt;br /&gt;sp_addsubscription&lt;br /&gt;sp_helpmergealternatepublisher&lt;br /&gt;&lt;br /&gt;sp_addsynctriggers&lt;br /&gt;sp_helpmergearticle&lt;br /&gt;&lt;br /&gt;sp_addtabletocontents&lt;br /&gt;sp_helpmergearticlecolumn&lt;br /&gt;&lt;br /&gt;sp_adjustpublisheridentityrange&lt;br /&gt;sp_helpmergearticleconflicts&lt;br /&gt;&lt;br /&gt;sp_article_validation&lt;br /&gt;sp_helpmergeconflictrows&lt;br /&gt;&lt;br /&gt;sp_articlecolumn&lt;br /&gt;sp_helpmergedeleteconflictrows&lt;br /&gt;&lt;br /&gt;sp_articlefilter&lt;br /&gt;sp_helpmergefilter&lt;br /&gt;&lt;br /&gt;sp_articlesynctranprocs&lt;br /&gt;sp_helpmergepublication&lt;br /&gt;&lt;br /&gt;sp_articleview&lt;br /&gt;sp_helpmergepullsubscription&lt;br /&gt;&lt;br /&gt;sp_attachsubscription&lt;br /&gt;sp_helpmergesubscription&lt;br /&gt;&lt;br /&gt;sp_browsesnapshotfolder&lt;br /&gt;sp_helppublication&lt;br /&gt;&lt;br /&gt;sp_browsemergesnapshotfolder&lt;br /&gt;sp_help_publication_access&lt;br /&gt;&lt;br /&gt;sp_browsereplcmds&lt;br /&gt;sp_helppullsubscription&lt;br /&gt;&lt;br /&gt;sp_change_agent_parameter&lt;br /&gt;sp_helpreplfailovermode&lt;br /&gt;&lt;br /&gt;sp_change_agent_profile&lt;br /&gt;sp_helpreplicationdboption&lt;br /&gt;&lt;br /&gt;sp_changearticle&lt;br /&gt;sp_helpreplicationoption&lt;br /&gt;&lt;br /&gt;sp_changedistpublisher&lt;br /&gt;sp_helpsubscriberinfo&lt;br /&gt;&lt;br /&gt;sp_changedistributiondb&lt;br /&gt;sp_helpsubscription&lt;br /&gt;&lt;br /&gt;sp_changedistributor_password&lt;br /&gt;sp_ivindexhasnullcols&lt;br /&gt;&lt;br /&gt;sp_changedistributor_property&lt;br /&gt;sp_helpsubscription_properties&lt;br /&gt;&lt;br /&gt;sp_changemergearticle&lt;br /&gt;sp_link_publication&lt;br /&gt;&lt;br /&gt;sp_changemergefilter&lt;br /&gt;sp_marksubscriptionvalidation&lt;br /&gt;&lt;br /&gt;sp_changemergepublication&lt;br /&gt;sp_mergearticlecolumn&lt;br /&gt;&lt;br /&gt;sp_changemergepullsubscription&lt;br /&gt;sp_mergecleanupmetadata&lt;br /&gt;&lt;br /&gt;sp_changemergesubscription&lt;br /&gt;sp_mergedummyupdate&lt;br /&gt;&lt;br /&gt;sp_changepublication&lt;br /&gt;sp_mergesubscription_cleanup&lt;br /&gt;&lt;br /&gt;sp_changesubscriber&lt;br /&gt;sp_publication_validation&lt;br /&gt;&lt;br /&gt;sp_changesubscriber_schedule&lt;br /&gt;sp_refreshsubscriptions&lt;br /&gt;&lt;br /&gt;sp_changesubscriptiondtsinfo&lt;br /&gt;sp_reinitmergepullsubscription&lt;br /&gt;&lt;br /&gt;sp_changesubstatus&lt;br /&gt;sp_reinitmergesubscription&lt;br /&gt;&lt;br /&gt;sp_change_subscription_properties&lt;br /&gt;sp_reinitpullsubscription&lt;br /&gt;&lt;br /&gt;sp_check_for_sync_trigger&lt;br /&gt;sp_reinitsubscription&lt;br /&gt;&lt;br /&gt;sp_copymergesnapshot&lt;br /&gt;sp_removedbreplication&lt;br /&gt;&lt;br /&gt;sp_copysnapshot&lt;br /&gt;sp_repladdcolumn&lt;br /&gt;&lt;br /&gt;sp_copysubscription&lt;br /&gt;sp_replcmds&lt;br /&gt;&lt;br /&gt;sp_deletemergeconflictrow&lt;br /&gt;sp_replcounters&lt;br /&gt;&lt;br /&gt;sp_disableagentoffload&lt;br /&gt;sp_repldone&lt;br /&gt;&lt;br /&gt;sp_drop_agent_parameter&lt;br /&gt;sp_repldropcolumn&lt;br /&gt;&lt;br /&gt;sp_drop_agent_profile&lt;br /&gt;sp_replflush&lt;br /&gt;&lt;br /&gt;sp_droparticle&lt;br /&gt;sp_replicationdboption&lt;br /&gt;&lt;br /&gt;sp_dropanonymouseagent&lt;br /&gt;sp_replication_agent_checkup&lt;br /&gt;&lt;br /&gt;sp_dropdistpublisher&lt;br /&gt;sp_replqueuemonitor&lt;br /&gt;&lt;br /&gt;sp_dropdistributiondb&lt;br /&gt;sp_replsetoriginator&lt;br /&gt;&lt;br /&gt;sp_dropmergealternatepublisher&lt;br /&gt;sp_replshowcmds&lt;br /&gt;&lt;br /&gt;sp_dropdistributor&lt;br /&gt;sp_repltrans&lt;br /&gt;&lt;br /&gt;sp_dropmergearticle&lt;br /&gt;sp_restoredbreplication&lt;br /&gt;&lt;br /&gt;sp_dropmergefilter&lt;br /&gt;sp_revoke_publication_access&lt;br /&gt;&lt;br /&gt; sp_scriptsubconflicttable&lt;br /&gt;&lt;br /&gt;sp_dropmergepublication&lt;br /&gt;sp_script_synctran_commands&lt;br /&gt;&lt;br /&gt;sp_dropmergepullsubscription&lt;br /&gt;sp_setreplfailovermode&lt;br /&gt;&lt;br /&gt; sp_showrowreplicainfo&lt;br /&gt;&lt;br /&gt;sp_dropmergesubscription&lt;br /&gt;sp_subscription_cleanup&lt;br /&gt;&lt;br /&gt;sp_droppublication&lt;br /&gt;sp_table_validation&lt;br /&gt;&lt;br /&gt;sp_droppullsubscription&lt;br /&gt;sp_update_agent_profile&lt;br /&gt;&lt;br /&gt;sp_dropsubscriber&lt;br /&gt;sp_validatemergepublication&lt;br /&gt;&lt;br /&gt;sp_dropsubscription&lt;br /&gt;sp_validatemergesubscription&lt;br /&gt;&lt;br /&gt;sp_dsninfo&lt;br /&gt;sp_vupgrade_replication&lt;br /&gt;&lt;br /&gt;sp_dumpparamcmd&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Security Procedures&lt;/span&gt;&lt;br /&gt;sp_addalias&lt;br /&gt;sp_droprolemember&lt;br /&gt;&lt;br /&gt;sp_addapprole&lt;br /&gt;sp_dropserver&lt;br /&gt;&lt;br /&gt;sp_addgroup&lt;br /&gt;sp_dropsrvrolemember&lt;br /&gt;&lt;br /&gt;sp_addlinkedsrvlogin&lt;br /&gt;sp_dropuser&lt;br /&gt;&lt;br /&gt;sp_addlogin&lt;br /&gt;sp_grantdbaccess&lt;br /&gt;&lt;br /&gt;sp_addremotelogin&lt;br /&gt;sp_grantlogin&lt;br /&gt;&lt;br /&gt;sp_addrole&lt;br /&gt;sp_helpdbfixedrole&lt;br /&gt;&lt;br /&gt;sp_addrolemember&lt;br /&gt;sp_helpgroup&lt;br /&gt;&lt;br /&gt;sp_addserver&lt;br /&gt;sp_helplinkedsrvlogin&lt;br /&gt;&lt;br /&gt;sp_addsrvrolemember&lt;br /&gt;sp_helplogins&lt;br /&gt;&lt;br /&gt;sp_adduser&lt;br /&gt;sp_helpntgroup&lt;br /&gt;&lt;br /&gt;sp_approlepassword&lt;br /&gt;sp_helpremotelogin&lt;br /&gt;&lt;br /&gt;sp_changedbowner&lt;br /&gt;sp_helprole&lt;br /&gt;&lt;br /&gt;sp_changegroup&lt;br /&gt;sp_helprolemember&lt;br /&gt;&lt;br /&gt;sp_changeobjectowner&lt;br /&gt;sp_helprotect&lt;br /&gt;&lt;br /&gt;sp_change_users_login&lt;br /&gt;sp_helpsrvrole&lt;br /&gt;&lt;br /&gt;sp_dbfixedrolepermission&lt;br /&gt;sp_helpsrvrolemember&lt;br /&gt;&lt;br /&gt;sp_defaultdb&lt;br /&gt;sp_helpuser&lt;br /&gt;&lt;br /&gt;sp_defaultlanguage&lt;br /&gt;sp_MShasdbaccess&lt;br /&gt;&lt;br /&gt;sp_denylogin&lt;br /&gt;sp_password&lt;br /&gt;&lt;br /&gt;sp_dropalias&lt;br /&gt;sp_remoteoption&lt;br /&gt;&lt;br /&gt;sp_dropapprole&lt;br /&gt;sp_revokedbaccess&lt;br /&gt;&lt;br /&gt;sp_dropgroup&lt;br /&gt;sp_revokelogin&lt;br /&gt;&lt;br /&gt;sp_droplinkedsrvlogin&lt;br /&gt;sp_setapprole&lt;br /&gt;&lt;br /&gt;sp_droplogin&lt;br /&gt;sp_srvrolepermission&lt;br /&gt;&lt;br /&gt;sp_dropremotelogin&lt;br /&gt;sp_validatelogins&lt;br /&gt;&lt;br /&gt;sp_droprole&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SQL Mail Procedures&lt;br /&gt;sp_processmail&lt;br /&gt;xp_sendmail&lt;br /&gt;&lt;br /&gt;xp_deletemail&lt;br /&gt;xp_startmail&lt;br /&gt;&lt;br /&gt;xp_findnextmsg&lt;br /&gt;xp_stopmail&lt;br /&gt;&lt;br /&gt;xp_readmail&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;SQL Profiler Procedures&lt;/span&gt;&lt;br /&gt;sp_trace_create&lt;br /&gt;sp_trace_setfilter&lt;br /&gt;&lt;br /&gt;sp_trace_generateevent&lt;br /&gt;sp_trace_setstatus&lt;br /&gt;&lt;br /&gt;sp_trace_setevent&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;SQL Server Agent Procedures&lt;/span&gt;&lt;br /&gt;sp_add_alert&lt;br /&gt;sp_help_jobhistory&lt;br /&gt;&lt;br /&gt;sp_add_category&lt;br /&gt;sp_help_jobschedule&lt;br /&gt;&lt;br /&gt;sp_add_job&lt;br /&gt;sp_help_jobserver&lt;br /&gt;&lt;br /&gt;sp_add_jobschedule&lt;br /&gt;sp_help_jobstep&lt;br /&gt;&lt;br /&gt;sp_add_jobserver&lt;br /&gt;sp_help_notification&lt;br /&gt;&lt;br /&gt;sp_add_jobstep&lt;br /&gt;sp_help_operator&lt;br /&gt;&lt;br /&gt;sp_add_notification&lt;br /&gt;sp_help_targetserver&lt;br /&gt;&lt;br /&gt;sp_add_operator&lt;br /&gt;sp_help_targetservergroup&lt;br /&gt;&lt;br /&gt;sp_add_targetservergroup&lt;br /&gt;sp_helptask&lt;br /&gt;&lt;br /&gt;sp_add_targetsvrgrp_member&lt;br /&gt;sp_manage_jobs_by_login&lt;br /&gt;&lt;br /&gt;sp_addtask&lt;br /&gt;sp_msx_defect&lt;br /&gt;&lt;br /&gt;sp_apply_job_to_targets&lt;br /&gt;sp_msx_enlist&lt;br /&gt;&lt;br /&gt;sp_delete_alert&lt;br /&gt;sp_post_msx_operation&lt;br /&gt;&lt;br /&gt;sp_delete_category&lt;br /&gt;sp_purgehistory&lt;br /&gt;&lt;br /&gt;sp_delete_job&lt;br /&gt;sp_purge_jobhistory&lt;br /&gt;&lt;br /&gt;sp_delete_jobschedule&lt;br /&gt;sp_reassigntask&lt;br /&gt;&lt;br /&gt;sp_delete_jobserver&lt;br /&gt;sp_remove_job_from_targets&lt;br /&gt;&lt;br /&gt;sp_delete_jobstep&lt;br /&gt;sp_resync_targetserver&lt;br /&gt;&lt;br /&gt;sp_delete_notification&lt;br /&gt;sp_start_job&lt;br /&gt;&lt;br /&gt;sp_delete_operator&lt;br /&gt;sp_stop_job&lt;br /&gt;&lt;br /&gt;sp_delete_targetserver&lt;br /&gt;sp_update_alert&lt;br /&gt;&lt;br /&gt;sp_delete_targetservergroup&lt;br /&gt;sp_update_category&lt;br /&gt;&lt;br /&gt;sp_delete_targetsvrgrp_member&lt;br /&gt;sp_update_job&lt;br /&gt;&lt;br /&gt;sp_droptask&lt;br /&gt;sp_update_jobschedule&lt;br /&gt;&lt;br /&gt;sp_help_alert&lt;br /&gt;sp_update_jobstep&lt;br /&gt;&lt;br /&gt;sp_help_category&lt;br /&gt;sp_update_notification&lt;br /&gt;&lt;br /&gt;sp_help_downloadlist&lt;br /&gt;sp_update_operator&lt;br /&gt;&lt;br /&gt;sp_helphistory&lt;br /&gt;sp_update_targetservergroup&lt;br /&gt;&lt;br /&gt;sp_help_job&lt;br /&gt;sp_updatetask&lt;br /&gt;&lt;br /&gt; xp_sqlagent_proxy_account&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;System Procedures&lt;/span&gt;&lt;br /&gt;sp_add_data_file_recover_suspect_db&lt;br /&gt;sp_helpconstraint&lt;br /&gt;&lt;br /&gt;sp_addextendedproc&lt;br /&gt;sp_helpdb&lt;br /&gt;&lt;br /&gt;sp_addextendedproperty&lt;br /&gt;sp_helpdevice&lt;br /&gt;&lt;br /&gt;sp_add_log_file_recover_suspect_db&lt;br /&gt;sp_helpextendedproc&lt;br /&gt;&lt;br /&gt;sp_addmessage&lt;br /&gt;sp_helpfile&lt;br /&gt;&lt;br /&gt;sp_addtype&lt;br /&gt;sp_helpfilegroup&lt;br /&gt;&lt;br /&gt;sp_addumpdevice&lt;br /&gt;sp_helpindex&lt;br /&gt;&lt;br /&gt;sp_altermessage&lt;br /&gt;sp_helplanguage&lt;br /&gt;&lt;br /&gt;sp_autostats&lt;br /&gt;sp_helpserver&lt;br /&gt;&lt;br /&gt;sp_attach_db&lt;br /&gt;sp_helpsort&lt;br /&gt;&lt;br /&gt;sp_attach_single_file_db&lt;br /&gt;sp_helpstats&lt;br /&gt;&lt;br /&gt;sp_bindefault&lt;br /&gt;sp_helptext&lt;br /&gt;&lt;br /&gt;sp_bindrule&lt;br /&gt;sp_helptrigger&lt;br /&gt;&lt;br /&gt;sp_bindsession&lt;br /&gt;sp_indexoption&lt;br /&gt;&lt;br /&gt;sp_certify_removable&lt;br /&gt;sp_invalidate_textptr&lt;br /&gt;&lt;br /&gt;sp_configure&lt;br /&gt;sp_lock&lt;br /&gt;&lt;br /&gt;sp_create_removable&lt;br /&gt;sp_monitor&lt;br /&gt;&lt;br /&gt;sp_createstats&lt;br /&gt;sp_procoption&lt;br /&gt;&lt;br /&gt;sp_cycle_errorlog&lt;br /&gt;sp_recompile&lt;br /&gt;&lt;br /&gt;sp_datatype_info&lt;br /&gt;sp_refreshview&lt;br /&gt;&lt;br /&gt;sp_dbcmptlevel&lt;br /&gt;sp_releaseapplock&lt;br /&gt;&lt;br /&gt;sp_dboption&lt;br /&gt;sp_rename&lt;br /&gt;&lt;br /&gt;sp_dbremove&lt;br /&gt;sp_renamedb&lt;br /&gt;&lt;br /&gt;sp_delete_backuphistory&lt;br /&gt;sp_resetstatus&lt;br /&gt;&lt;br /&gt;sp_depends&lt;br /&gt;sp_serveroption&lt;br /&gt;&lt;br /&gt;sp_detach_db&lt;br /&gt;sp_setnetname&lt;br /&gt;&lt;br /&gt;sp_dropdevice&lt;br /&gt;sp_settriggerorder&lt;br /&gt;&lt;br /&gt;sp_dropextendedproc&lt;br /&gt;sp_spaceused&lt;br /&gt;&lt;br /&gt;sp_dropextendedproperty&lt;br /&gt;sp_tableoption&lt;br /&gt;&lt;br /&gt;sp_dropmessage&lt;br /&gt;sp_unbindefault&lt;br /&gt;&lt;br /&gt;sp_droptype&lt;br /&gt;sp_unbindrule&lt;br /&gt;&lt;br /&gt;sp_executesql&lt;br /&gt;sp_updateextendedproperty&lt;br /&gt;&lt;br /&gt;sp_getapplock&lt;br /&gt;sp_updatestats&lt;br /&gt;&lt;br /&gt;sp_getbindtoken&lt;br /&gt;sp_validname&lt;br /&gt;&lt;br /&gt;sp_help&lt;br /&gt;sp_who&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Web Assistant Procedures&lt;br /&gt;sp_dropwebtask&lt;br /&gt;sp_makewebtask&lt;br /&gt;&lt;br /&gt;sp_enumcodepages&lt;br /&gt;sp_runwebtask&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;XML Procedures&lt;/span&gt;&lt;br /&gt;sp_xml_preparedocument&lt;br /&gt;sp_xml_removedocument&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;General Extended Procedures&lt;/span&gt;&lt;br /&gt;xp_cmdshell&lt;br /&gt;xp_logininfo&lt;br /&gt;&lt;br /&gt;xp_enumgroups&lt;br /&gt;xp_msver&lt;br /&gt;&lt;br /&gt;xp_findnextmsg&lt;br /&gt;xp_revokelogin&lt;br /&gt;&lt;br /&gt;xp_grantlogin&lt;br /&gt;xp_sprintf&lt;br /&gt;&lt;br /&gt;xp_logevent&lt;br /&gt;xp_sqlmaint&lt;br /&gt;&lt;br /&gt;xp_loginconfig&lt;br /&gt;xp_sscanf&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you DROP a PROCEDURE?&lt;/span&gt;&lt;br /&gt;Removes one or more stored procedures or procedure groups from the current database.&lt;br /&gt;Syntax&lt;br /&gt;DROP PROCEDURE { procedure } [ ,...n ]&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you recompile a procedure?&lt;/span&gt;&lt;br /&gt;sp_recompile&lt;br /&gt;Causes stored procedures and triggers to be recompiled the next time they are run.&lt;br /&gt;Syntax&lt;br /&gt;sp_recompile [ @objname = ] 'object'&lt;br /&gt;sp_recompile looks for an object in the current database only.&lt;br /&gt;The queries used by stored procedures and triggers are optimized only when they are compiled. As indexes or other changes that affect statistics are made to the database, compiled stored procedures and triggers may lose efficiency. By recompiling stored procedures and triggers that act on a table, you can reoptimize the queries.&lt;br /&gt; &lt;br /&gt;Note  Microsoft® SQL Server™ automatically recompiles stored procedures and triggers when it is advantageous to do so.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are the Rules for Programming Stored Procedures ?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Rules for programming stored procedures include:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The CREATE PROCEDURE definition itself can include any number and type of SQL statements except for the following CREATE statements, which cannot be used anywhere within a stored procedure:&lt;br /&gt;&lt;br /&gt;CREATE DEFAULT CREATE TRIGGER&lt;br /&gt;CREATE PROCEDURE CREATE VIEW&lt;br /&gt;CREATE RULE &lt;br /&gt;&lt;br /&gt;Other database objects can be created within a stored procedure. You can reference an object created in the same stored procedure as long as it is created before it is referenced.&lt;br /&gt;&lt;br /&gt;You can reference temporary tables within a stored procedure.&lt;br /&gt;If you create a local temporary table inside a stored procedure, the temporary table exists only for the purposes of the stored procedure; it disappears when you exit the stored procedure.&lt;br /&gt;&lt;br /&gt;If you execute a stored procedure that calls another stored procedure, the called stored procedure can access all objects created by the first stored procedure, including temporary tables.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you execute a remote stored procedure that makes changes on a remote instance of Microsoft® SQL Server™ 2000, those changes cannot be rolled back. Remote stored procedures do not take part in transactions.&lt;br /&gt;&lt;br /&gt;The maximum number of parameters in a stored procedure is 2100.&lt;br /&gt;The maximum number of local variables in a stored procedure is limited only by available memory.&lt;br /&gt;&lt;br /&gt;Depending on available memory, the maximum size of a stored procedure is 128 megabytes (MB).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you Encrypt Procedure?&lt;/span&gt;&lt;br /&gt;If you are creating a stored procedure and you want to make sure that the procedure definition cannot be viewed by other users, you can use the WITH ENCRYPTION clause. &lt;br /&gt;The procedure definition is then stored in an unreadable form.&lt;br /&gt;After a stored procedure is encrypted, its definition cannot be decrypted and cannot be viewed by anyone, including the owner of the stored procedure or the system administrator.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is EXECUTE in procedure?&lt;/span&gt;&lt;br /&gt;Executes a scalar-valued, user-defined function, a system procedure, a user-defined stored procedure, or an extended stored procedure. Also supports the execution of a character string within a Transact-SQL batch.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4905884173788197974-8122026447174223833?l=sqldemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqldemo.blogspot.com/feeds/8122026447174223833/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-questionprocedure.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/8122026447174223833'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/8122026447174223833'/><link rel='alternate' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-questionprocedure.html' title='Sql Server Interview Question:Procedure'/><author><name>thangadurai</name><uri>http://www.blogger.com/profile/16066274107687970274</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4905884173788197974.post-6265386614042763753</id><published>2009-06-27T05:39:00.000-07:00</published><updated>2009-06-27T05:42:58.202-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Create view'/><title type='text'>Sql Server Interview Question:Create View</title><content type='html'>&lt;span style="font-weight:bold;"&gt;What is view?&lt;/span&gt;&lt;br /&gt;CREATE VIEW&lt;br /&gt;Creates a virtual table that represents the data in one or more tables in an alternative way. CREATE VIEW must be the first statement in a query batch.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What are the restrictions when creating view?&lt;/span&gt;&lt;br /&gt;There are a few restrictions on the SELECT clauses in a view definition. A CREATE VIEW statement cannot:&lt;br /&gt;&lt;br /&gt;Include COMPUTE or COMPUTE BY clauses.&lt;br /&gt;Include ORDER BY clause, unless there is also a TOP clause in the select list of the SELECT statement.&lt;br /&gt;Include the INTO keyword.&lt;br /&gt;Reference a temporary table or a table variable.&lt;br /&gt;&lt;br /&gt;Because select_statement uses the SELECT statement, it is valid to use &lt;join_hint&gt; and &lt;table_hint&gt; hints as specified in the FROM clause. For more information, see FROM and SELECT.&lt;br /&gt;Functions can be used in the select_statement.&lt;br /&gt;select_statement can use multiple SELECT statements separated by UNION or UNION ALL.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is WITH CHECK OPTION on views?&lt;/span&gt;&lt;br /&gt;Forces all data modification statements executed against the view to adhere to the criteria set within select_statement. When a row is modified through a view, the WITH CHECK OPTION ensures the data remains visible through the view after the modification is committed.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is WITH ENCRYPTION on views?&lt;/span&gt;&lt;br /&gt;Indicates that SQL Server encrypts the system table columns containing the text of the CREATE VIEW statement. Using WITH ENCRYPTION prevents the view from being published as part of SQL Server replication.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What do you know SCHEMABINDING?&lt;/span&gt;&lt;br /&gt;Binds the view to the schema. When SCHEMABINDING is specified, the select_statement must include the two-part names (owner.object) of tables, views, or user-defined functions referenced.&lt;br /&gt;&lt;br /&gt;Views or tables participating in a view created with the schema binding clause cannot be dropped unless that view is dropped or changed so that it no longer has schema binding. Otherwise, SQL Server raises an error. In addition, ALTER TABLE statements on tables that participate in views having schema binding will fail if these statements affect the view definition.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is VIEW_METADATA?&lt;/span&gt;&lt;br /&gt;Specifies that SQL Server will return to the DBLIB, ODBC, and OLE DB APIs the metadata information about the view, instead of the base table or tables, when browse-mode metadata is being requested for a query that references the view. Browse-mode metadata is additional metadata returned by SQL Server to the client-side DB-LIB, ODBC, and OLE DB APIs, which allow the client-side APIs to implement updatable client-side cursors. Browse-mode meta data includes information about the base table that the columns in the result set belong to.&lt;br /&gt;&lt;br /&gt;For views created with VIEW_METADATA option, the browse-mode meta data returns the view name as opposed to the base table names when describing columns from the view in the result set.&lt;br /&gt;&lt;br /&gt;When a view is created WITH VIEW_METADATA, all its columns (except for timestamp) are updatable if the view has INSERT or UPDATE INSTEAD OF triggers&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How many columns a view can reference?&lt;/span&gt;&lt;br /&gt;A view can reference a maximum of 1,024 columns.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Notes about views:&lt;/span&gt;&lt;br /&gt;When querying through a view, Microsoft® SQL Server™ checks to make sure that all the database objects referenced anywhere in the statement exist, that they are valid in the context of the statement, and that data modification statements do not violate any data integrity rules.&lt;br /&gt;&lt;br /&gt;A check that fails returns an error message. A successful check translates the action into an action against the underlying table(s).&lt;br /&gt;&lt;br /&gt;If a view depends on a table (or view) that was dropped, SQL Server produces an error message if anyone tries to use the view. If a new table (or view) is created, and the table structure does not change from the previous base table, to replace the one dropped, the view again becomes usable. If the new table (or view) structure changes, then the view must be dropped and recreated.&lt;br /&gt;&lt;br /&gt;When a view is created, the name of the view is stored in the sysobjects table. Information about the columns defined in a view is added to the syscolumns table, and information about the view dependencies is added to the sysdepends table.&lt;br /&gt;&lt;br /&gt;In addition, the text of the CREATE VIEW statement is added to the syscomments table. This is similar to a stored procedure; when a view is executed for the first time, only its query tree is stored in the procedure cache. Each time a view is accessed, its execution plan is recompiled.&lt;br /&gt;&lt;br /&gt;The result of a query using an index on a view defined with numeric or float expressions may be different from a similar query that does not use the index on the view. This difference may be the result of rounding errors during INSERT, DELETE, or UPDATE actions on underlying tables.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is Updatable Views&lt;/span&gt;&lt;br /&gt;Microsoft SQL Server 2000 enhances the class of updatable views in two ways:&lt;br /&gt;&lt;br /&gt;INSTEAD OF Triggers: INSTEAD OF triggers can be created on a view in order to make a view updatable. The INSTEAD OF trigger is executed instead of the data modification statement on which the trigger is defined. This trigger allows the user to specify the set of actions that need to take place in order to process the data modification statement. Thus, if an INSTEAD OF trigger exists for a view on a given data modification statement (INSERT, UPDATE, or DELETE), the corresponding view is updatable through that statement. For more information about INSTEAD OF triggers, see Designing INSTEAD OF triggers.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Partitioned Views:&lt;/span&gt; If the view is of a specified form called 'partitioned view,' the view is updatable, subject to certain restrictions. Partitioned views and their updatability are discussed later in this topic.&lt;br /&gt;&lt;br /&gt;When needed, SQL Server will distinguish Local Partitioned Views as the views in which all participating tables and the view are on the same SQL Server, and Distributed Partitioned Views as the views in which at least one of the tables in the view resides on a different (remote) server.&lt;br /&gt;&lt;br /&gt;If a view does not have INSTEAD OF triggers, or if it is not a partitioned view, then it is updatable only if the following conditions are satisfied:&lt;br /&gt;&lt;br /&gt;The select_statement has no aggregate functions in the select list and does not contain the TOP, GROUP BY, UNION (unless the view is a partitioned view as described later in this topic), or DISTINCT clauses. Aggregate functions can be used in a subquery in the FROM clause as long as the values returned by the functions are not modified. For more information, see Aggregate Functions.&lt;br /&gt;&lt;br /&gt;select_statement has no derived columns in the select list. Derived columns are result set columns formed by anything other than a simple column expression, such as using functions or addition or subtraction operators.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is Partitioned Views?&lt;/span&gt;&lt;br /&gt;A partitioned view is a view defined by a UNION ALL of member tables structured in the same way, but stored separately as multiple tables in either the same SQL Server or in a group of autonomous SQL Server 2000 servers, called Federated SQL Server 2000 Servers.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are then Conditions for Creating Partitioned Views?&lt;/span&gt;&lt;br /&gt;1. SELECT list&lt;br /&gt;All columns in the member tables should be selected in the column list of the view definition.&lt;br /&gt;&lt;br /&gt;The columns in the same ordinal position of each select_list should be of the same type, including collations. It is not sufficient for the columns to be implicitly convertible types, as is generally the case for UNION.&lt;br /&gt;&lt;br /&gt;The same column cannot be used multiple times in the SELECT list.&lt;br /&gt;1. Partitioning column&lt;br /&gt;The partitioning column is a part of the PRIMARY KEY of the table.&lt;br /&gt;It cannot be a computed column.&lt;br /&gt;&lt;br /&gt;If there is more than one constraint on the same column in a member table, SQL Server ignores all the constraints and will not consider them when determining whether or not the view is a partitioned view. To meet the conditions of the partitioned view, there should be only one partitioning constraint on the partitioning column.&lt;br /&gt;&lt;br /&gt;2. Member tables (or underlying tables T1, ..., Tn)&lt;br /&gt;The tables can be either local tables or tables from other SQL Servers referenced either through a four-part name or an OPENDATASOURCE- or OPENROWSET-based name. (The OPENDATASOURCE and OPENROWSET syntax can specify a table name, but not a pass-through query.) For more information, see OPENDATASOURCE and OPENROWSET .&lt;br /&gt;If one or more of the member tables are remote, the view is called distributed partitioned view, and additional conditions apply. They are discussed later in this section.&lt;br /&gt;&lt;br /&gt;The same table cannot appear twice in the set of tables that are being combined with the UNION ALL statement.&lt;br /&gt;&lt;br /&gt;The member tables cannot have indexes created on computed columns in the table.&lt;br /&gt;The member tables should have all PRIMARY KEY constraints on an identical number of columns.&lt;br /&gt;&lt;br /&gt;All member tables in the view should have the same ANSI padding setting (which is set using the user options option in sp_configure or the SET option).&lt;br /&gt;&lt;br /&gt;What are the Conditions for Modifying Partitioned Views?&lt;br /&gt;Only the Developer and Enterprise Editions of SQL Server 2000 allow INSERT, UPDATE, and DELETE operations on partitioned views. To modify partitioned views, the statements must meet these conditions:&lt;br /&gt;&lt;br /&gt;The INSERT statement must supply values for all the columns in the view, even if the underlying member tables have a DEFAULT constraint for those columns or if they allow NULLs. For those member table columns that have DEFAULT definitions, the statements cannot use the keyword DEFAULT explicitly.&lt;br /&gt;&lt;br /&gt;The value being inserted into the partitioning column should satisfy at least one of the underlying constraints; otherwise, the INSERT action will fail with a constraint violation.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;UPDATE statements cannot specify the DEFAULT keyword as a value in the SET clause even if the column has a DEFAULT value defined in the corresponding member table.&lt;br /&gt;&lt;br /&gt;PRIMARY KEY columns cannot be modified through an UPDATE statement if the member tables have text, ntext, or image columns.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Columns in the view that are an IDENTITY column in one or more of the member tables cannot be modified through an INSERT or UPDATE statement.&lt;br /&gt;&lt;br /&gt;If one of the member tables contains a timestamp column, the view cannot be modified through an INSERT or UPDATE statement.&lt;br /&gt;&lt;br /&gt;INSERT, UPDATE, and DELETE actions against a partitioned view are not allowed if there is a self-join with the same view or with any of the member tables in the statement.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you alter a view?&lt;/span&gt;&lt;br /&gt;ALTER VIEW&lt;br /&gt;Alters a previously created view (created by executing CREATE VIEW), including indexed views, without affecting dependent stored procedures or triggers and without changing permissions&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you DROP a VIEW?&lt;/span&gt;&lt;br /&gt;Removes one or more views from the current database. DROP VIEW can be executed against indexed views.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4905884173788197974-6265386614042763753?l=sqldemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqldemo.blogspot.com/feeds/6265386614042763753/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-questioncreate_4020.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/6265386614042763753'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/6265386614042763753'/><link rel='alternate' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-questioncreate_4020.html' title='Sql Server Interview Question:Create View'/><author><name>thangadurai</name><uri>http://www.blogger.com/profile/16066274107687970274</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4905884173788197974.post-3405938529792181829</id><published>2009-06-27T05:35:00.000-07:00</published><updated>2009-06-27T05:39:23.818-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Create Database'/><title type='text'>Sql Server Interview Question:Create Database</title><content type='html'>&lt;span style="font-weight:bold;"&gt;What does the Create Database statement do?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Creates a new database and the files used to store the database, or attaches a database from the files of a previously created database.&lt;br /&gt;&lt;br /&gt;Database names must be unique within a server and conform to the rules for identifiers. database_name can be a maximum of 128 characters, unless no logical name is specified for the log.&lt;br /&gt;&lt;br /&gt;If no logical log file name is specified, Microsoft® SQL Server™ generates a logical name by appending a suffix to database_name. This limits database_name to 123 characters so that the generated logical log file name is less than 128 characters.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is LOG ON on create database definition?&lt;/span&gt;&lt;br /&gt;Specifies that the disk files used to store the database log (log files) are explicitly defined. The keyword is followed by a comma-separated list of &lt;filespec&gt; items defining the log files. &lt;br /&gt;If LOG ON is not specified, a single log file is automatically created with a system-generated name and a size that is 25 percent of the sum of the sizes of all the data files for the database.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is FOR ATTACH?&lt;/span&gt;&lt;br /&gt;Specifies that a database is attached from an existing set of operating system files. There must be a &lt;filespec&gt; entry specifying the first primary file.&lt;br /&gt;&lt;br /&gt;The only other &lt;filespec&gt; entries needed are those for any files that have a different path from when the database was first created or last attached. A &lt;filespec&gt; entry must be specified for these files.&lt;br /&gt;&lt;br /&gt;The database attached must have been created using the same code page and sort order as SQL Server. Use the sp_attach_db system stored procedure instead of using CREATE DATABASE FOR ATTACH directly. Use CREATE DATABASE FOR ATTACH only when you must specify more than 16 &lt;filespec&gt; items.&lt;br /&gt;&lt;br /&gt;If you attach a database to a server other than the server from which the database was detached, and the detached database was enabled for replication, you should run sp_removedbreplication to remove replication from the database.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is primary when creating create database definition?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;PRIMARY&lt;br /&gt;Specifies that the associated &lt;filespec&gt; list defines the primary file. The primary filegroup contains all of the database system tables. It also contains all objects not assigned to user filegroups.&lt;br /&gt;&lt;br /&gt;The first &lt;filespec&gt; entry in the primary filegroup becomes the primary file, which is the file containing the logical start of the database and its system tables. A database can have only one primary file. If PRIMARY is not specified, the first file listed in the CREATE DATABASE statement becomes the primary file.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is the default size when we create database?&lt;/span&gt;&lt;br /&gt;SIZE&lt;br /&gt;Specifies the size of the file defined in the &lt;filespec&gt;. When a SIZE parameter is not supplied in the &lt;filespec&gt; for a primary file, SQL Server uses the size of the primary file in the model database. When a SIZE parameter is not specified in the &lt;filespec&gt; for a secondary or log file, SQL Server makes the file 1 MB.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you define maxsize on create database?&lt;/span&gt;&lt;br /&gt;MAXSIZE&lt;br /&gt;Specifies the maximum size to which the file defined in the &lt;filespec&gt; can grow.&lt;br /&gt;max_size&lt;br /&gt;&lt;br /&gt;Is the maximum size to which the file defined in the &lt;filespec&gt; can grow. The kilobyte (KB), megabyte (MB), gigabyte (GB), or terabyte (TB) suffixes can be used. The default is MB. Specify a whole number; do not include a decimal. If max_size is not specified, the file grows until the disk is full.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is UNLIMITED?&lt;/span&gt;&lt;br /&gt;Specifies that the file defined in the &lt;filespec&gt; grows until the disk is full.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is FILEGROWTH&lt;/span&gt;&lt;br /&gt;Specifies the growth increment of the file defined in the &lt;filespec&gt;. The FILEGROWTH setting for a file cannot exceed the MAXSIZE setting.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is growth_increment&lt;/span&gt;&lt;br /&gt;Is the amount of space added to the file each time new space is needed. Specify a whole number; do not include a decimal. A value of 0 indicates no growth. The value can be specified in MB, KB, GB, TB, or percent (%).&lt;br /&gt;If a number is specified without an MB, KB, or % suffix, the default is MB. When % is specified, the growth increment size is the specified percentage of the size of the file at the time the increment occurs. If FILEGROWTH is not specified, the default value is 10 percent and the minimum value is 64 KB. The size specified is rounded to the nearest 64 KB.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How SQL Server implements the CREATE DATABASE statement?&lt;/span&gt;&lt;br /&gt;SQL Server implements the CREATE DATABASE statement in two steps:&lt;br /&gt;1. SQL Server uses a copy of the model database to initialize the database and its meta data.&lt;br /&gt;2. SQL Server then fills the rest of the database with empty pages, except for pages that have internal data recording how the space is used in the database.&lt;br /&gt;Any user-defined objects in the model database are therefore copied to all newly created databases. You can add to the model database any objects, such as tables, views, stored procedures, data types, and so on, to be included in all databases&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How many number of database can be specified per sql server?&lt;/span&gt;&lt;br /&gt;A maximum of 32,767 databases can be specified on a server.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;How many of files used to store database?&lt;/span&gt;&lt;br /&gt;There are three types of files used to store a database:&lt;br /&gt;&lt;br /&gt;The primary file contains the startup information for the database. The primary file is also used to store data. Every database has one primary file.&lt;br /&gt;&lt;br /&gt;Secondary files hold all of the data that does not fit in the primary data file. Databases need not have any secondary data files if the primary file is large enough to hold all of the data in the database. Other databases may be large enough to need multiple secondary data files, or they may use secondary files on separate disk drives to spread the data across multiple disks.&lt;br /&gt;&lt;br /&gt;Transaction log files hold the log information used to recover the database. There must be at least one transaction log file for each database, although there may be more than one. The minimum size for a transaction log file is 512 KB.&lt;br /&gt;&lt;br /&gt;Every database has at least two files, a primary file and a transaction log file.&lt;br /&gt;Although 'os_file_name' can be any valid operating system file name, the name more clearly reflects the purpose of the file if you use the following recommended extensions.&lt;br /&gt;&lt;br /&gt;File type File name extension&lt;br /&gt;Primary data file .mdf&lt;br /&gt;Secondary data file .ndf&lt;br /&gt;Transaction log file .ldf&lt;br /&gt;Note  The master database should be backed up when a user database is created.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is filegroup on create database definition?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;All databases have at least a primary filegroup. All system tables are allocated in the primary filegroup. &lt;br /&gt;&lt;br /&gt;A database can also have user-defined filegroups. If an object is created with an ON filegroup clause specifying a user-defined filegroup, then all the pages for the object are allocated from the specified filegroup. &lt;br /&gt;&lt;br /&gt;The pages for all user objects created without an ON filegroup clause, or with an ON DEFAULT clause, are allocated from the default filegroup.&lt;br /&gt;&lt;br /&gt; When a database is first created the primary filegroup is the default filegroup. You can specify a user-defined filegroup as the default filegroup using ALTER DATABASE:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you report a database?&lt;/span&gt;&lt;br /&gt;To display a report on a database, or on all the databases for an instance of SQL Server, execute sp_helpdb.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you report database space used?&lt;/span&gt;&lt;br /&gt;For a report on the space used in a database, use sp_spaceused.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you report filegroup, files on database?&lt;/span&gt;&lt;br /&gt;For a report on the filegroups in a database use sp_helpfilegroup, and use sp_helpfile for a report of the files in a database.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you rename a database?&lt;/span&gt;&lt;br /&gt;sp_renamedb  Changes the name of a database.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you alter the database?&lt;/span&gt;&lt;br /&gt;ALTER DATABASE&lt;br /&gt;Adds or removes files and filegroups from a database. Can also be used to modify the attributes of files and filegroups, such as changing the name or size of a file. ALTER DATABASE provides the ability to change the database name, filegroup names, and the logical names of data files and log files.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you drop a database?&lt;/span&gt;&lt;br /&gt;DROP DATABASE&lt;br /&gt;Removes one or more databases from Microsoft® SQL Server™. Removing a database deletes the database and the disk files used by the database.&lt;br /&gt;Syntax&lt;br /&gt;DROP DATABASE database_name [ ,...n ]&lt;br /&gt;To use DROP DATABASE, the database context of the connection must be in the master database.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Notes about drop database:&lt;/span&gt;&lt;br /&gt;DROP DATABASE removes damaged databases marked as suspect and removes the specified database. Before dropping a database used in replication, first remove replication.&lt;br /&gt;&lt;br /&gt;Any database published for transactional replication, or published or subscribed to merge replication cannot be dropped. If a database is damaged and replication cannot first be removed, in most cases you still can drop the database by marking it as an offline database.&lt;br /&gt;&lt;br /&gt;A dropped database can be re-created only by restoring a backup. You cannot drop a database currently in use (open for reading or writing by any user).&lt;br /&gt;&lt;br /&gt;When database is created the master database should be backed up&lt;br /&gt;When a database is dropped, the master database should be backed up.&lt;br /&gt;System databases (msdb, master, model, tempdb) cannot be dropped.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4905884173788197974-3405938529792181829?l=sqldemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqldemo.blogspot.com/feeds/3405938529792181829/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-questioncreate_27.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/3405938529792181829'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/3405938529792181829'/><link rel='alternate' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-questioncreate_27.html' title='Sql Server Interview Question:Create Database'/><author><name>thangadurai</name><uri>http://www.blogger.com/profile/16066274107687970274</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4905884173788197974.post-4970359419085780519</id><published>2009-06-27T05:31:00.000-07:00</published><updated>2009-06-27T05:35:17.238-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Table and Index'/><title type='text'>Sql Server Interview Question:Table and Index Architecture</title><content type='html'>&lt;span style="font-weight:bold;"&gt;Table and Index Architecture&lt;/span&gt;&lt;br /&gt;Objects in a Microsoft® SQL Server™ 2000 database are stored as a collection of 8-KB pages&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Notes about Table and Index:&lt;/span&gt;&lt;br /&gt;SQL Server 2000 supports indexes on views. The first index allowed on a view is a clustered index. &lt;br /&gt;At the time a CREATE INDEX statement is executed on a view, the result set for the view is materialized and stored in the database with the same structure as a table that has a clustered index&lt;br /&gt;&lt;br /&gt;The data rows for each table or indexed view are stored in a collection of 8-KB data pages. Each data page has a 96-byte header containing system information such as the identifier (ID) of the table that owns the page.&lt;br /&gt;&lt;br /&gt;The page header also includes pointers to the next and previous pages that are used if the pages are linked in a list. A row offset table is at the end of the page. Data rows fill the rest of the page.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Organization of Data Pages&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL Server 2000 tables use one of two methods to organize their data pages:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Clustered tables are tables that have a clustered index&lt;/span&gt;.&lt;br /&gt;The data rows are stored in order based on the clustered index key. &lt;br /&gt;The index is implemented as a B-tree index structure that supports fast retrieval of the rows based on their clustered index key values. &lt;br /&gt;The pages in each level of the index, including the data pages in the leaf level, are linked in a doubly-linked list, but navigation from one level to another is done using key values.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Heaps are tables that have no clustered index.&lt;/span&gt;&lt;br /&gt;The data rows are not stored in any particular order, and there is no particular order to the sequence of the data pages. The data pages are not linked in a linked list.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Indexed views have the same storage structure as clustered tables.&lt;/span&gt;&lt;br /&gt;SQL Server also supports up to 249 nonclustered indexes on each table or indexed view. The nonclustered indexes have a B-tree index structure similar to the one in clustered indexes.&lt;br /&gt;&lt;br /&gt;The difference is that nonclustered indexes have no effect on the order of the data rows. Clustered tables and indexed views keep their data rows in order based on the clustered index key.&lt;br /&gt;&lt;br /&gt;The collection of data pages for a heap is not affected if nonclustered indexes are defined for the table. &lt;br /&gt;&lt;br /&gt;The data pages remain in a heap unless a clustered index is defined.&lt;br /&gt;The pages holding text, ntext, and image data are managed as a single unit for each table. All of the text, ntext, and image data for a table is stored in one collection of pages.&lt;br /&gt;&lt;br /&gt;All of the page collections for tables, indexes and indexed views are anchored by page pointers in the sysindexes table.&lt;br /&gt;&lt;br /&gt; Every table and indexed view has one collection of data pages, plus additional collections of pages to implement each index defined for the table or view.&lt;br /&gt;Each table, index and indexed view has a row in sysindexes uniquely identified by the combination of the object identifier (id) column and the index identifier (indid) column.&lt;br /&gt;&lt;br /&gt;The allocation of pages to tables, indexes, and indexed views is managed by a chain of IAM pages.&lt;br /&gt;&lt;br /&gt;The column sysindexes.FirstIAM points to first IAM page in the chain of IAM pages managing the space allocated to the table, index or indexed view.&lt;br /&gt;Each table has a set of rows in sysindexes:&lt;br /&gt;&lt;br /&gt;A heap has a row in sysindexes with indid = 0.&lt;br /&gt;The FirstIAM column points to the IAM chain for the collection of data pages for the table. The server uses the IAM pages to find the pages in the data page collection because they are not linked together.&lt;br /&gt;&lt;br /&gt;A clustered index on a table or view has a row in sysindexes with indid = 1.&lt;br /&gt;The root column points to the top of the clustered index B-tree. The server uses the index B-tree to find the data pages.&lt;br /&gt;&lt;br /&gt;Each nonclustered index created for a table or view has a row in sysindexes.&lt;br /&gt;The values for indid in the rows for each nonclustered index range from 2 through 250. The root column points to the top of the nonclustered index B-tree.&lt;br /&gt;Each table that has at least one text, ntext, or image column also has a row in sysindexes with indid = 255.&lt;br /&gt;&lt;br /&gt;The column FirstIAM points to the chain of IAM pages that manage the text, ntext, and image pages.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4905884173788197974-4970359419085780519?l=sqldemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqldemo.blogspot.com/feeds/4970359419085780519/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-questiontable-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/4970359419085780519'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/4970359419085780519'/><link rel='alternate' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-questiontable-and.html' title='Sql Server Interview Question:Table and Index Architecture'/><author><name>thangadurai</name><uri>http://www.blogger.com/profile/16066274107687970274</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4905884173788197974.post-6110852281210833829</id><published>2009-06-27T05:26:00.000-07:00</published><updated>2009-06-27T05:31:29.848-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Index'/><title type='text'>Sql Server Interview Question:Create Index</title><content type='html'>&lt;span style="font-weight:bold;"&gt;How do you create a index?&lt;/span&gt;&lt;br /&gt;Creates an index on a given table or view.&lt;br /&gt;Only the table or view owner can create indexes on that table. The owner of a table or view can create an index at any time, whether or not there is data in the table. Indexes can be created on tables or views in another database by specifying a qualified database name.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is unique index?&lt;/span&gt;&lt;br /&gt;Creates a unique index (one in which no two rows are permitted to have the same index value) on a table or view. A clustered index on a view must be UNIQUE.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Can we create index on table with existing data?&lt;/span&gt;&lt;br /&gt;Microsoft® SQL Server™ checks for duplicate values when the index is created (if data already exists) and checks each time data is added with an INSERT or UPDATE statement. If duplicate key values exist, the CREATE INDEX statement is canceled and an error message giving the first duplicate is returned. Multiple NULL values are considered duplicates when UNIQUE index is created.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Which situation create unique index fail?&lt;/span&gt;&lt;br /&gt;SQL Server does not allow the creation of a unique index on columns that already include duplicate values, whether or not IGNORE_DUP_KEY is set. If attempted, SQL Server displays an error message; duplicates must be eliminated before a unique index can be created on the column(s).&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is clustered index?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;How many clustered index can we have per table?&lt;/span&gt;&lt;br /&gt;CLUSTERED&lt;br /&gt;Creates an object where the physical order of rows is the same as the indexed order of the rows, and the bottom (leaf) level of the clustered index contains the actual data rows. A table or view is allowed one clustered index at a time.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Why do we need to create clustered index first before creating nonclustered index?&lt;/span&gt;&lt;br /&gt;Create the clustered index before creating any nonclustered indexes. Existing nonclustered indexes on tables are rebuilt when a clustered index is created.&lt;br /&gt;If CLUSTERED is not specified, a nonclustered index is created.&lt;br /&gt; &lt;br /&gt;Note  Because the leaf level of a clustered index and its data pages are the same by definition, creating a clustered index and using the ON filegroup clause effectively moves a table from the file on which the table was created to the new filegroup. Before creating tables or indexes on specific filegroups, verify which filegroups are available and that they have enough empty space for the index. It is important that the filegroup have at least 1.2 times the space required for the entire table.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is NONCLUSTERED index?&lt;/span&gt;&lt;br /&gt;Creates an object that specifies the logical ordering of a table. With a nonclustered index, the physical order of the rows is independent of their indexed order. The leaf level of a nonclustered index contains index rows. Each index row contains the nonclustered key value and one or more row locators that point to the row that contains the value. If the table does not have a clustered index, the row locator is the row's disk address. If the table does have a clustered index, the row locator is the clustered index key for the row.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How many nonclustered index we can have per table?&lt;/span&gt;&lt;br /&gt;Each table can have as many as 249 nonclustered indexes (regardless of how they are created: implicitly with PRIMARY KEY and UNIQUE constraints, or explicitly with CREATE INDEX). Each index can provide access to the data in a different sort order.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Is it possible to create nonclustered index on views?&lt;/span&gt;&lt;br /&gt;For indexed views, nonclustered indexes can be created only on a view with a clustered index already defined. Thus, the row locator of a nonclustered index on an indexed view is always the clustered key of the row.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Can we create nonclustered indexes on views?&lt;/span&gt;&lt;br /&gt;A unique clustered index must be created on a view before any nonclustered index is created.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Why do we need to create indexes on view?&lt;/span&gt;&lt;br /&gt;Indexed views may be used by the query optimizer in SQL Server Enterprise or Developer edition to speed up the query execution. The view does not need to be referenced in the query for the optimizer to consider that view for a substitution.&lt;br /&gt;When creating indexed views or manipulating rows in tables participating in an indexed view, seven SET options must be assigned specific values.&lt;br /&gt;&lt;br /&gt;The SET options ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER, ANSI_NULLS, ANSI_PADDING, and ANSI_WARNING must be ON. The SET option NUMERIC_ROUNDABORT must be OFF.&lt;br /&gt;If any of these settings is different, data modification statements (INSERT, UPDATE, DELETE) on any table referenced by an indexed view fail and SQL Server raises an error listing all SET options that violate setting requirements.&lt;br /&gt;&lt;br /&gt;In addition, for a SELECT statement that involves an indexed view, if the values of any of the SET options are not the required values, SQL Server processes the SELECT without considering the indexed view substitution. This ensures correctness of query result in cases where it can be affected by the above SET options.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Which are the datatypes not supported by index?&lt;/span&gt;&lt;br /&gt;Columns consisting of the ntext, text, or image data types cannot be specified as columns for an index. In addition, a view cannot include any text, ntext, or image columns, even if they are not referenced in the CREATE INDEX statement.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is a composite index?&lt;/span&gt;&lt;br /&gt;Composite indexes are used when two or more columns are best searched as a unit or if many queries reference only the columns specified in the index&lt;br /&gt;What is constraint when defining composite indexes?&lt;br /&gt;As many as 16 columns can be combined into a single composite index. All the columns in a composite index must be in the same table.&lt;br /&gt;The maximum allowable size of the combined index values is 900 bytes. That is, the sum of the lengths of the fixed-size columns that make up the composite index cannot exceed 900 bytes&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is fillfactor?&lt;/span&gt;&lt;br /&gt;Specifies a percentage that indicates how full SQL Server should make the leaf level of each index page during index creation.&lt;br /&gt;When an index page fills up, SQL Server must take time to split the index page to make room for new rows, which is quite expensive. For update-intensive tables, a properly chosen FILLFACTOR value yields better update performance than an improper FILLFACTOR value. The value of the original FILLFACTOR is stored with the index in sysindexes.&lt;br /&gt;&lt;br /&gt;When FILLFACTOR is specified, SQL Server rounds up the number of rows to be placed on each page.&lt;br /&gt;For example, issuing CREATE CLUSTERED INDEX ... FILLFACTOR = 33 creates a clustered index with a FILLFACTOR of 33 percent. Assume that SQL Server calculates that 5.2 rows is 33 percent of the space on a page. SQL Server rounds so that six rows are placed on each page.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Notes about fillfactor&lt;/span&gt;&lt;br /&gt;An explicit FILLFACTOR setting applies only when the index is first created. SQL Server does not dynamically keep the specified percentage of empty space in the pages.&lt;br /&gt;User-specified FILLFACTOR values can be from 1 through 100. If no value is specified, the default is 0. When FILLFACTOR is set to 0, only the leaf pages are filled. You can change the default FILLFACTOR setting by executing sp_configure.&lt;br /&gt;Use a FILLFACTOR of 100 only if no INSERT or UPDATE statements will occur, such as with a read-only table. If FILLFACTOR is 100, SQL Server creates indexes with leaf pages 100 percent full. An INSERT or UPDATE made after the creation of an index with a 100 percent FILLFACTOR causes page splits for each INSERT and possibly each UPDATE.&lt;br /&gt;Smaller FILLFACTOR values, except 0, cause SQL Server to create new indexes with leaf pages that are not completely full. For example, a FILLFACTOR of 10 can be a reasonable choice when creating an index on a table known to contain a small portion of the data that it will eventually hold. Smaller FILLFACTOR values also cause each index to take more storage space.&lt;br /&gt;The following table illustrates how the pages of an index are filled up if FILLFACTOR is specified.&lt;br /&gt;FILLFACTOR Intermediate page Leaf page&lt;br /&gt;0 percent One free entry 100 percent full&lt;br /&gt;1 - 99 percent One free entry &lt;= FILLFACTOR percent full&lt;br /&gt;100 percent One free entry 100 percent full&lt;br /&gt;&lt;br /&gt;One free entry is the space on the page that can accommodate another index entry.&lt;br /&gt; &lt;br /&gt;Important  Creating a clustered index with a FILLFACTOR affects the amount of storage space the data occupies because SQL Server redistributes the data when it creates the clustered index&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is IGNORE_DUP_KEY?&lt;/span&gt;&lt;br /&gt;Controls what happens when an attempt is made to insert a duplicate key value into a column that is part of a unique clustered index. If IGNORE_DUP_KEY was specified for the index and an INSERT statement that creates a duplicate key is executed, SQL Server issues a warning and ignores the duplicate row.&lt;br /&gt;If IGNORE_DUP_KEY was not specified for the index, SQL Server issues an error message and rolls back the entire INSERT statement.&lt;br /&gt;The table shows when IGNORE_DUP_KEY can be used.&lt;br /&gt;Index type Options&lt;br /&gt;Clustered Not allowed&lt;br /&gt;Unique clustered IGNORE_DUP_KEY allowed&lt;br /&gt;Nonclustered Not allowed&lt;br /&gt;Unique nonclustered IGNORE_DUP_KEY allowed&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;When dropping clustered indexes what happen to the &lt;span style="font-weight:bold;"&gt;clustering keys?&lt;/span&gt;&lt;br /&gt;What is DROP_EXISTING?&lt;/span&gt;&lt;br /&gt;Specifies that the named, preexisting clustered or nonclustered index should be dropped and rebuilt. The index name specified must be the same as a currently existing index. Because nonclustered indexes contain the clustering keys, the nonclustered indexes must be rebuilt when a clustered index is dropped. If a clustered index is recreated, the nonclustered indexes must be rebuilt to take the new set of keys into account.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is the advantange of drop_existing?&lt;/span&gt;&lt;br /&gt;The DROP_EXISTING clause enhances performance when re-creating a clustered index (with either the same or a different set of keys) on a table that also has nonclustered indexes.&lt;br /&gt;The DROP_EXISTING clause replaces the execution of a DROP INDEX statement on the old clustered index followed by the execution of a CREATE INDEX statement for the new clustered index. The nonclustered indexes are rebuilt once, and only if the keys are different.&lt;br /&gt;If the keys do not change (the same index name and columns as the original index are provided), the DROP_EXISTING clause does not sort the data again. This can be useful if the index must be compacted.&lt;br /&gt;A clustered index cannot be converted to a nonclustered index using the DROP_EXISTING clause;&lt;br /&gt;however, a unique clustered index can be changed to a non-unique index, and vice versa.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Notes about index space:&lt;/span&gt;&lt;br /&gt;Space is allocated to tables and indexes in increments of one extent (eight 8-kilobyte pages) at a time. Each time an extent is filled, another is allocated. &lt;br /&gt;&lt;br /&gt;Indexes on very small or empty tables will use single page allocations until eight pages have been added to the index and then will switch to extent allocations. For a report on the amount of space allocated and used by an index, use sp_spaceused.&lt;br /&gt;Creating a clustered index requires space available in your database equal to approximately 1.2 times the size of the data.&lt;br /&gt;&lt;br /&gt;This is space in addition to the space used by the existing table; the data is duplicated in order to create the clustered index, and the old, nonindexed data is deleted when the index is complete.&lt;br /&gt;When using the DROP_EXISTING clause, the space needed for the clustered index is the amount of space equal to the space requirements of the existing index. &lt;br /&gt;The amount of additional space required also may be affected by the FILLFACTOR specified.&lt;br /&gt;The CREATE INDEX statement is optimized like any other query. The SQL Server query processor may choose to scan another index instead of performing a table scan to save on I/O operations&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;How do you report index?&lt;/span&gt;&lt;br /&gt;To display a report on an object's indexes, execute sp_helpindex.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Can we create indexes and triggers on temporary table?&lt;/span&gt;&lt;br /&gt;Indexes can be created on a temporary table. When the table is dropped or the session ends, all indexes and triggers are dropped.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is Variable type columns in indexes?&lt;/span&gt;&lt;br /&gt;The maximum size allowed for an index key is 900 bytes, but SQL Server 2000 allows indexes to be created on columns that may have large variable type columns with a maximum size greater than 900 bytes.&lt;br /&gt;During index creation, SQL Server checks the following conditions:&lt;br /&gt;The sum of all fixed data columns that participate in the index definition must be less or equal to 900 bytes.&lt;br /&gt;&lt;br /&gt; When the index to be created is composed of fixed data columns only, the total size of the fixed data columns must be less or equal to 900 bytes. Otherwise, the index will not be created and SQL Server will return an error.&lt;br /&gt;&lt;br /&gt;If the index definition is composed of fixed- and variable-type columns, and the fixed-data columns meet the previous condition (less or equal to 900 bytes), SQL Server still checks the total size of the variable type columns.&lt;br /&gt;&lt;br /&gt;If the maximum size of the variable-type columns plus the size of the fixed-data columns is greater than 900 bytes, SQL Server creates the index, but returns a warning to the user. &lt;br /&gt;&lt;br /&gt;The warning alerts the user that if subsequent insert or update actions on the variable-type columns result in a total size greater than 900 bytes, the action will fail and the user will get a run-time error.&lt;br /&gt;&lt;br /&gt;Likewise, if the index definition is composed of variable-type columns only, and the maximum total size of these columns is greater than 900 bytes, SQL Server will create the index, but return a warning.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What needs to be Considerations when indexing computed columns and views?&lt;/span&gt;&lt;br /&gt;In SQL Server 2000, indexes also can be created on computed columns and views. Creating a unique clustered index on a view improves query performance because the view is stored in the database in the same way a table with a clustered index is stored.&lt;br /&gt;Creation of an index on a computed column or view may cause the failure of an INSERT or UPDATE operation that previously worked. Such a failure may take place when the computed column results in arithmetic error&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What are the Restrictions on indexed views?&lt;/span&gt;&lt;br /&gt;The SELECT statement defining an indexed view must not have the TOP, DISTINCT, COMPUTE, HAVING, and UNION keywords. It cannot have a subquery.&lt;br /&gt;The SELECT list may not include asterisks (*), 'table.*' wildcard lists, DISTINCT, COUNT(*), COUNT(&lt;expression&gt;), computed columns from the base tables, and scalar aggregates.&lt;br /&gt;&lt;br /&gt;Nonaggregate SELECT lists cannot have expressions. Aggregate SELECT list (queries that contain GROUP BY) may include SUM and COUNT_BIG(&lt;expression&gt;); it must contain COUNT_BIG(*). Other aggregate functions (MIN, MAX, STDEV,...) are not allowed.&lt;br /&gt;&lt;br /&gt;Complex aggregation using AVG cannot participate in the SELECT list of the indexed view. &lt;br /&gt;However, if a query uses such aggregation, the optimizer is capable of using this indexed view to substitute AVG with a combination of simple aggregates SUM and COUNT_BIG.&lt;br /&gt;&lt;br /&gt;A column resulting from an expression that either evaluates to a float data type or uses float expressions for its evaluation cannot be a key of an index in an indexed view or on a computed column in a table. Such columns are called nonprecise. Use the COLUMNPROPERTY function to determine if a particular computed column or a column in a view is precise.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Indexed views are subject to these additional restrictions:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The creator of the index must own the tables. All tables, the view, and the index, must be created in the same database.&lt;br /&gt;&lt;br /&gt;The SELECT statement defining the indexed view may not contain views, rowset functions, inline functions, or derived tables. The same physical table may occur only once in the statement.&lt;br /&gt;&lt;br /&gt;In any joined tables, no OUTER JOIN operations are allowed.&lt;br /&gt;&lt;br /&gt;No subqueries or CONTAINS or FREETEXT predicates are allowed in the search condition.&lt;br /&gt;&lt;br /&gt;If the view definition contains a GROUP BY clause, all grouping columns as well as the COUNT_BIG(*) expression must appear in the view's SELECT list. Also, these columns must be the only columns in the CREATE UNIQUE CLUSTERED INDEX clause.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Is DROP INDEX statement drop indexes created by primary key or unique key?&lt;/span&gt;&lt;br /&gt;Removes one or more indexes from the current database.&lt;br /&gt;The DROP INDEX statement does not apply to indexes created by defining PRIMARY KEY or UNIQUE constraints (created by using the PRIMARY KEY or UNIQUE options of either the CREATE TABLE or ALTER TABLE statements, respectively).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Notes about Drop index statement:&lt;/span&gt;&lt;br /&gt;After DROP INDEX is executed, all the space previously occupied by the index is regained. This space can then be used for any database object.&lt;br /&gt;DROP INDEX cannot be specified on an index on a system table.&lt;br /&gt;&lt;br /&gt;To drop the indexes created to implement PRIMARY KEY or UNIQUE constraints, the constraint must be dropped. For more information about dropping constraints, see "ALTER TABLE" in this volume.&lt;br /&gt;&lt;br /&gt;Nonclustered indexes have different pointers to data rows depending on whether or not a clustered index is defined for the table.&lt;br /&gt;&lt;br /&gt;If there is a clustered index the leaf rows of the nonclustered indexes use the clustered index keys to point to the data rows.&lt;br /&gt;&lt;br /&gt;If the table is a heap, the leaf rows of nonclustered indexes use row pointers. If you drop a clustered index on a table with nonclustered indexes, all the nonclustered indexes are rebuilt to replace the clustered index keys with row pointers&lt;br /&gt;.&lt;br /&gt;Similarly, when the clustered index of an indexed view is dropped, all nonclustered indexes on the same view are dropped automatically.&lt;br /&gt;&lt;br /&gt;Sometimes indexes are dropped and re-created to reorganize the index, for example to apply a new fillfactor or to reorganize data after a bulk load. It is more efficient to use CREATE INDEX and the WITH DROP_EXISTING clause for this, especially for clustered indexes. Dropping a clustered index causes all the nonclustered indexes to be rebuilt.&lt;br /&gt;&lt;br /&gt;If the clustered index is then re-created, the nonclustered indexes are rebuilt once again to replace the row pointers with clustered index keys.&lt;br /&gt;&lt;br /&gt;The WITH DROP_EXISTING clause of CREATE INDEX has optimizations to prevent this overhead of rebuilding the nonclustered indexes twice. DBCC DBREINDEX can also be used and has the advantage that it does not require that the structure of the index be known.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is DBCC DBREINDEX&lt;/span&gt;&lt;br /&gt;Rebuilds one or more indexes for a table in the specified database.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Notes about DBCC DBREINDEX:&lt;/span&gt;&lt;br /&gt;DBCC DBREINDEX rebuilds an index for a table or all indexes defined for a table. By allowing an index to be rebuilt dynamically, indexes enforcing either PRIMARY KEY or UNIQUE constraints can be rebuilt without having to drop and re-create those constraints.&lt;br /&gt;&lt;br /&gt;This means an index can be rebuilt without knowing the table's structure or constraints, which could occur after a bulk copy of data into the table.&lt;br /&gt;&lt;br /&gt;If either index_name or fillfactor is specified, all preceding parameters must also be specified.&lt;br /&gt;&lt;br /&gt;DBCC DBREINDEX can rebuild all of the indexes for a table in one statement, which is easier than coding multiple DROP INDEX and CREATE INDEX statements.&lt;br /&gt;Because the work is done by one statement, DBCC DBREINDEX is automatically atomic, while individual DROP INDEX and CREATE INDEX statements would have to be put in a transaction to be atomic.&lt;br /&gt;&lt;br /&gt;Also, DBCC DBREINDEX can take advantage of more optimizations with DBCC DBREINDEX than it can with individual DROP INDEX and CREATE INDEX statements.&lt;br /&gt;DBCC DBREINDEX is not supported for use on system tables.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4905884173788197974-6110852281210833829?l=sqldemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqldemo.blogspot.com/feeds/6110852281210833829/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-questioncreate.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/6110852281210833829'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/6110852281210833829'/><link rel='alternate' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-questioncreate.html' title='Sql Server Interview Question:Create Index'/><author><name>thangadurai</name><uri>http://www.blogger.com/profile/16066274107687970274</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4905884173788197974.post-874029229931914908</id><published>2009-06-27T05:23:00.000-07:00</published><updated>2009-06-27T05:25:50.994-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Default'/><title type='text'>Sql Server Interview Question: Default</title><content type='html'>&lt;span style="font-weight:bold;"&gt;What is the CREATE DEFAULT definition?&lt;/span&gt;&lt;br /&gt;Creates an object called a default. When bound to a column or a user-defined data type, a default specifies a value to be inserted into the column to which the object is bound (or into all columns, in the case of a user-defined data type) when no value is explicitly supplied during an insert.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you attach a default definition to column?&lt;/span&gt;&lt;br /&gt;When a default is created, use sp_bindefault to bind it to a column or to a user-defined data type.&lt;br /&gt;&lt;br /&gt;Notes about binding the rule?&lt;br /&gt;If the default is not compatible with the column to which it is bound, Microsoft® SQL Server™ generates an error message when trying to insert the default value. For example, N/A cannot be used as a default for a numeric column.&lt;br /&gt;If the default value is too long for the column to which it is bound, the value is truncated.&lt;br /&gt;CREATE DEFAULT statements cannot be combined with other Transact-SQL statements in a single batch.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What you need to do before dropping the default?&lt;/span&gt;&lt;br /&gt;A default must be dropped before creating a new one of the same name, and the default must be unbound by executing sp_unbindefault before it is dropped.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What will happen when you have both rule and default in a column?&lt;/span&gt;&lt;br /&gt;If a column has both a default and a rule associated with it, the default value must not violate the rule. A default that conflicts with a rule is never inserted, and SQL Server generates an error message each time it attempts to insert the default.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;When are  the time default inserted to the table?&lt;/span&gt;&lt;br /&gt;A value is not explicitly inserted.&lt;br /&gt;Either the DEFAULT VALUES or DEFAULT keywords are used with INSERT to insert default values.&lt;br /&gt;If NOT NULL is specified when creating a column and a default is not created for it, an error message is generated when a user fails to make an entry in that column. This table illustrates the relationship between the existence of a default and the definition of a column as NULL or NOT NULL. The entries in the table show the result.&lt;br /&gt;Column definition No entry, no default No entry, default Enter NULL, no default Enter NULL, default&lt;br /&gt;NULL NULL default NULL NULL&lt;br /&gt;NOT NULL Error default error error&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you rename a default?&lt;/span&gt;&lt;br /&gt;To rename a default, use sp_rename&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do get report on default?&lt;/span&gt;&lt;br /&gt;For a report on a default, use sp_help.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you drop default?&lt;/span&gt;&lt;br /&gt;DROP DEFAULT&lt;br /&gt;Removes one or more user-defined defaults from the current database.&lt;br /&gt;The DROP DEFAULT statement does not apply to DEFAULT constraints. For more information about dropping DEFAULT constraints (created by using the DEFAULT option of either the CREATE TABLE or ALTER TABLE statements), see "ALTER TABLE" in this volume.&lt;br /&gt;Syntax&lt;br /&gt;DROP DEFAULT { default } [ ,...n ]&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4905884173788197974-874029229931914908?l=sqldemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqldemo.blogspot.com/feeds/874029229931914908/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-question-default.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/874029229931914908'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/874029229931914908'/><link rel='alternate' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-question-default.html' title='Sql Server Interview Question: Default'/><author><name>thangadurai</name><uri>http://www.blogger.com/profile/16066274107687970274</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4905884173788197974.post-8080970870748829527</id><published>2009-06-27T04:23:00.000-07:00</published><updated>2009-06-27T04:26:20.738-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Rule'/><title type='text'>Sql Server Interview Qustion:Rule</title><content type='html'>&lt;span style="font-weight:bold;"&gt; What is the create rule statement?&lt;/span&gt;&lt;br /&gt;Creates an object called a rule. When bound to a column or a user-defined data type, a rule specifies the acceptable values that can be inserted into that column.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;How many constraint a single column can have?&lt;/span&gt;&lt;br /&gt;However, a column can have both a rule and one or more check constraints associated with it. When this is true, all restrictions are evaluated&lt;br /&gt;Check constraint, default constraint, rule&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What conditional expression you can use in rule?&lt;/span&gt;&lt;br /&gt;A rule can be any expression valid in a WHERE clause and can include such elements as arithmetic operators, relational operators, and predicates (for example, IN, LIKE, BETWEEN). A rule cannot reference columns or other database objects. Built-in functions that do not reference database objects can be included.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What variable you should use when you create Rule?&lt;/span&gt;&lt;br /&gt;condition_expression includes one variable. The at sign (@) precedes each local variable. The expression refers to the value entered with the UPDATE or INSERT statement. Any name or symbol can be used to represent the value when creating the rule, but the first character must be the at sign (@).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;When you create the rule, whether the rule may apply for existing data?&lt;/span&gt;&lt;br /&gt;Rules do not apply to data already existing in the database at the time the rules are created, and rules cannot be bound to system data types. A rule can be created only in the current database.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you bind the rule to the column?&lt;/span&gt;&lt;br /&gt;After creating a rule, execute sp_bindrule to bind the rule to a column or to a user-defined data type.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Which are the datatypes not supported for rule?&lt;/span&gt;&lt;br /&gt;The rule must be compatible with the column data type. A rule cannot be bound to a text, image, or timestamp column. Be sure to enclose character and date constants with single quotation marks (') and to precede binary constants with 0x. For example, "@value LIKE A%" cannot be used as a rule for a numeric column&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you get report on your Rule?&lt;/span&gt;&lt;br /&gt;To get a report on a rule, use sp_help.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;How do you display your rule text?&lt;/span&gt;&lt;br /&gt;To display the text of a rule, execute sp_helptext with the rule name as the parameter.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;How do you rename a rule?&lt;/span&gt;&lt;br /&gt;To rename a rule, use sp_rename.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do you drop a rule?&lt;/span&gt;&lt;br /&gt;A rule must be dropped (using DROP RULE)&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;When dropping rule what you must do?&lt;/span&gt;&lt;br /&gt;the rule must be unbound (using sp_unbindrule) before it is dropped. Use sp_unbindrule to unbind a rule from a column.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What will happen when binding new rule to the old rule?&lt;/span&gt;&lt;br /&gt;You can bind a new rule to a column or data type without unbinding the previous one; the new rule overrides the previous one. Rules bound to columns always take precedence over rules bound to user-defined data types. Binding a rule to a column replaces a rule already bound to the user-defined data type of that column. But binding a rule to a data type does not replace a rule bound to a column of that user-defined data type. The table shows the precedence in effect when binding rules to columns and to user-defined data types where rules already exist.&lt;br /&gt; Old rule bound to&lt;br /&gt;New rule bound to user-defined data type Column&lt;br /&gt;User-defined data type Old rule replaced No change&lt;br /&gt;Column Old rule replaced Old rule replaced&lt;br /&gt;&lt;br /&gt;If a column has both a default and a rule associated with it, the default must fall within the domain defined by the rule. A default that conflicts with a rule is never inserted. SQL Server generates an error message each time it attempts to insert such a default.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;How do drop rule?&lt;/span&gt;&lt;br /&gt;DROP RULE&lt;br /&gt;Removes one or more user-defined rules from the current database.&lt;br /&gt;Syntax&lt;br /&gt;DROP RULE { rule } [ ,...n ]&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4905884173788197974-8080970870748829527?l=sqldemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqldemo.blogspot.com/feeds/8080970870748829527/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-qustionrule.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/8080970870748829527'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/8080970870748829527'/><link rel='alternate' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-qustionrule.html' title='Sql Server Interview Qustion:Rule'/><author><name>thangadurai</name><uri>http://www.blogger.com/profile/16066274107687970274</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4905884173788197974.post-4531894917695629683</id><published>2009-06-27T04:03:00.000-07:00</published><updated>2009-06-27T04:06:04.910-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Alter Table'/><title type='text'>Sql Server Interview Question:Alter Table</title><content type='html'>&lt;span style="font-weight:bold;"&gt;What do you do with Alter table statement?&lt;/span&gt;&lt;br /&gt;Modifies a table definition by altering, adding, or dropping columns and constraints, or by disabling or enabling constraints and triggers.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Which are the data type column we cannot alter?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The altered column cannot be:&lt;br /&gt;A column with a text, image, ntext, or timestamp data type.&lt;br /&gt;The ROWGUIDCOL for the table.&lt;br /&gt;A computed column or used in a computed column.&lt;br /&gt;A replicated column.&lt;br /&gt;Used in an index, unless the column is a varchar, nvarchar, or varbinary data type, the data type is not changed, and the new size is equal to or larger than the old size.&lt;br /&gt;Used in statistics generated by the CREATE STATISTICS statement. First remove the statistics using the DROP STATISTICS statement. Statistics automatically generated by the query optimizer are automatically dropped by ALTER COLUMN.&lt;br /&gt;&lt;br /&gt;Used in a PRIMARY KEY or [FOREIGN KEY] REFERENCES constraint.&lt;br /&gt;Used in a CHECK or UNIQUE constraint, except that altering the length of a variable-length column used in a CHECK or UNIQUE constraint is allowed.&lt;br /&gt;Associated with a default, except that changing the length, precision, or scale of a column is allowed if the data type is not changed.&lt;br /&gt;&lt;br /&gt;Some data type changes may result in a change in the data. For example, changing an nchar or nvarchar column to char or varchar can result in the conversion of extended characters. For more information, see CAST and CONVERT. Reducing the precision and scale of a column may result in data truncation.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;When altering column what you have to taken care of?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The previous data type must be implicitly convertible to the new data type.&lt;br /&gt;new_data_type cannot be timestamp.&lt;br /&gt;ANSI null defaults are always on for ALTER COLUMN; if not specified, the column is nullable.&lt;br /&gt;ANSI padding is always on for ALTER COLUMN.&lt;br /&gt;If the altered column is an identity column, new_data_type must be a data type that supports the identity property.&lt;br /&gt;The current setting for SET ARITHABORT is ignored. ALTER TABLE operates as if the ARITHABORT option is ON.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is WITH CHECK, WITH NOCHECKin the alter table definition?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Specifies whether the data in the table is or is not validated against a newly added or re-enabled FOREIGN KEY or CHECK constraint. If not specified, WITH CHECK is assumed for new constraints, and WITH NOCHECK is assumed for re-enabled constraints.&lt;br /&gt;&lt;br /&gt;The WITH CHECK and WITH NOCHECK clauses cannot be used for PRIMARY KEY and UNIQUE constraints.&lt;br /&gt;&lt;br /&gt;If you do not want to verify new CHECK or FOREIGN KEY constraints against existing data, use WITH NOCHECK. This is not recommended except in rare cases. The new constraint will be evaluated in all future updates. Any constraint violations suppressed by WITH NOCHECK when the constraint is added may cause future updates to fail if they update rows with data that does not comply with the constraint.&lt;br /&gt;Constraints defined WITH NOCHECK are not considered by the query optimizer. These constraints are ignored until all such constraints are re-enabled using ALTER TABLE table CHECK CONSTRAINT ALL.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Which are the constraint use CHECK NOCHECK?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Specifies that constraint_name is enabled or disabled. When disabled, future inserts or updates to the column are not validated against the constraint conditions. This option can only be used with FOREIGN KEY and CHECK constraints.&lt;br /&gt;ALL&lt;br /&gt;Specifies that all constraints are disabled with the NOCHECK option, or enabled with the CHECK option.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How do your enable or disable a trigger?&lt;/span&gt;&lt;br /&gt;ENABLE | DISABLE} TRIGGER&lt;br /&gt;Specifies that trigger_name is enabled or disabled. When a trigger is disabled it is still defined for the table; however, when INSERT, UPDATE, or DELETE statements are executed against the table, the actions in the trigger are not performed until the trigger is re-enabled.&lt;br /&gt;ALL&lt;br /&gt;Specifies that all triggers in the table are enabled or disabled.&lt;br /&gt;trigger_name&lt;br /&gt;Specifies the name of the trigger to disable or enable.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is ON DELETE CASCADE  NO ACTION definition in the alter table statement?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Specifies what action occurs to a row in the table altered, if that row has a referential relationship and the referenced row is deleted from the parent table. The default is NO ACTION.&lt;br /&gt;If CASCADE is specified, a row is deleted from the referencing table if that row is deleted from the parent table. If NO ACTION is specified, SQL Server raises an error and the delete action on the row in the parent table is rolled back.&lt;br /&gt;The CASCADE action ON DELETE cannot be defined if an INSTEAD OF trigger ON DELETE already exists on the table in question.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is ON UPDATE CASCADE NO ACTION in the alter table definition?&lt;/span&gt;&lt;br /&gt;Specifies what action occurs to a row in the table altered, if that row has a referential relationship and the referenced row is updated in the parent table. The default is NO ACTION.&lt;br /&gt;If CASCADE is specified, the row is updated in the referencing table if that row is updated in the parent table. If NO ACTION is specified, SQL Server raises an error and the update action on the row in the parent table is rolled back.&lt;br /&gt;The CASCADE action ON UPDATE cannot be defined if an INSTEAD OF trigger ON UPDATE already exists on the table in question.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is WITH VALUES in the alter table definition?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Specifies that the value given in DEFAULT constant_expression is stored in a new column added to existing rows. WITH VALUES can be specified only when DEFAULT is specified in an ADD column clause. If the added column allows null values and WITH VALUES is specified, the default value is stored in the new column added to existing rows. If WITH VALUES is not specified for columns that allow nulls, the value NULL is stored in the new column in existing rows. If the new column does not allow nulls, the default value is stored in new rows regardless of whether WITH VALUES is specified.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Which schema used by the alter table statement?&lt;/span&gt;&lt;br /&gt;To add new rows of data, use the INSERT statement. To remove rows of data, use the DELETE or TRUNCATE TABLE statements. To change the values in existing rows, use UPDATE.&lt;br /&gt;The changes specified in ALTER TABLE are implemented immediately. If the changes require modifications of the rows in the table, ALTER TABLE updates the rows.&lt;br /&gt;&lt;br /&gt;ALTER TABLE acquires a schema modify lock on the table to ensure no other connections reference even the meta data for the table during the change.&lt;br /&gt;The modifications made to the table are logged and fully recoverable. Changes that affect all the rows in very large tables, such as dropping a column or adding a NOT NULL column with a default, can take a long time to complete and generate many log records. These ALTER TABLE statements should be executed with the same care as any INSERT, UPDATE, or DELETE statement that affects a large number of rows.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Notes on Alter table:&lt;/span&gt;&lt;br /&gt;Indexes created as part of a constraint are dropped when the constraint is dropped.&lt;br /&gt;Indexes that were created with CREATE INDEX must be dropped with the DROP INDEX statement.&lt;br /&gt;&lt;br /&gt;The DBCC DBREINDEX statement can be used to rebuild an index part of a constraint definition; the constraint does not need to be dropped and added again with ALTER TABLE.&lt;br /&gt;All indexes and constraints based on a column must be removed before the column can be removed.&lt;br /&gt;&lt;br /&gt;When constraints are added, all existing data is verified for constraint violations. If any violations occur, the ALTER TABLE statement fails and an error is returned.&lt;br /&gt;When a new PRIMARY KEY or UNIQUE constraint is added to an existing column, the data in the column(s) must be unique.&lt;br /&gt;&lt;br /&gt;If duplicate values are found, the ALTER TABLE statement fails. The WITH NOCHECK option has no effect when adding PRIMARY KEY or UNIQUE constraints.&lt;br /&gt;Each PRIMARY KEY and UNIQUE constraint generates an index. The number of UNIQUE and PRIMARY KEY constraints cannot cause the number of indexes on the table to exceed 249 no clustered indexes and 1 clustered index.&lt;br /&gt;&lt;br /&gt;If a column is added having a uniqueidentifier data type, it can be defined with a default that uses the NEWID() function to supply the unique identifier values in the new column for each existing row in the table.&lt;br /&gt;&lt;br /&gt;SQL Server does not enforce an order in which DEFAULT, IDENTITY, ROWGUIDCOL, or column constraints are specified in a column definition.&lt;br /&gt;The ALTER COLUMN clause of ALTER TABLE does not bind or unbind any rules on a column. Rules must be bound or unbound separately using sp_bindrule or sp_unbindrule.&lt;br /&gt;&lt;br /&gt;Rules can be bound to a user-defined data type.&lt;br /&gt;CREATE TABLE then automatically binds the rule to any column defined having the user-defined data type.&lt;br /&gt;ALTER COLUMN does not unbind the rule when changing the column data type. The rule from the original user-defined data type remains bound to the column.&lt;br /&gt;&lt;br /&gt;After ALTER COLUMN has changed the data type of the column, any subsequent sp_unbindrule execution that unbinds the rule from the user-defined data type does not unbind it from the column for which data type was changed.&lt;br /&gt;&lt;br /&gt;If ALTER COLUMN changes the data type of a column to a user-defined data type bound to a rule, the rule bound to the new data type is not bound to the column.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4905884173788197974-4531894917695629683?l=sqldemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqldemo.blogspot.com/feeds/4531894917695629683/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-questionalter.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/4531894917695629683'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/4531894917695629683'/><link rel='alternate' type='text/html' href='http://sqldemo.blogspot.com/2009/06/sql-server-interview-questionalter.html' title='Sql Server Interview Question:Alter Table'/><author><name>thangadurai</name><uri>http://www.blogger.com/profile/16066274107687970274</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4905884173788197974.post-2528114853594266045</id><published>2009-06-27T03:21:00.000-07:00</published><updated>2009-06-27T03:37:49.198-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Table'/><title type='text'>SQL Server Interview Question:Table</title><content type='html'>&lt;span style="font-weight:bold;"&gt;1.) How many character sql server table can have?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;table_name can contain a maximum of 128 characters, except for local temporary table names (names prefixed with a single number sign (#)) that cannot exceed 116 characters.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;2. What is the distinction between sql server tablename and column name?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The combination of owner.table_name must be unique within the database.&lt;br /&gt;&lt;br /&gt;Column names must conform to the rules for identifiers and must be unique in the table.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;3. Which occurrences you can omit column name in sql server table?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;column_name can be omitted for columns created with a timestamp data type. The name of a timestamp column defaults to timestamp if column_name is not specified.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;4. What is computed column in sqlserver?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Is an expression defining the value of a computed column. A computed column is a virtual column not physically stored in the table. It is computed from an expression using other columns in the same table&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;5. What is the restriction when defining computed column expression?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;a computed column can have the definition: cost AS price * qty. The expression can be a noncomputed column name, constant, function, variable, and any combination of these connected by one or more operators. The expression cannot be a subquery.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;6 Where can we use computed columns?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Computed columns can be used in select lists, WHERE clauses, ORDER BY clauses, or any other locations in which regular expressions can be used&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;7. Can we create a foreign key or default, not null constraint on computed column?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A computed column cannot be used as a DEFAULT or FOREIGN KEY constraint definition or with a NOT NULL constraint definition.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;8. Can we create an index on computed columns?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;a computed column can be used as a key column in an index or as part of any PRIMARY KEY or UNIQUE constraint, if the computed column value is defined by a deterministic expression and the data type of the result is allowed in index columns.&lt;br /&gt;&lt;br /&gt;For example, if the table has integer columns a and b, the computed column a+b may be indexed, but computed column a+DATEPART(dd, GETDATE()) cannot be indexed because the value may change in subsequent invocations.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;9. can computed column be the target of insert and update?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A computed column cannot be the target of an INSERT or UPDATE statement.&lt;br /&gt;&lt;br /&gt;Note Each row in a table can have different values for columns involved in a computed column; therefore the computed column may not have the same value for each row.&lt;br /&gt;&lt;br /&gt;The nullability of computed columns is determined automatically by SQL Server based on the expressions used. The result of most expressions is considered nullable even if only non-nullable columns are present because possible underflows or overflows will produce NULL results as well. Use the COLUMNPROPERTY function (AllowsNull property) to investigate the nullability of any computed column in a table. An expression expr that is nullable can be turned into a non-nullable one by specifying ISNULL(check_expression, constant) where the constant is a non-NULL value substituted for any NULL result.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;10.) Why do we specify filegroup when creating database?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Where is your table stored in sql server?&lt;br /&gt;&lt;br /&gt;Specifies the filegroup on which the table is stored. If filegroup is specified, the table is stored in the named filegroup. The filegroup must exist within the database. If DEFAULT is specified, or if ON is not specified at all, the table is stored on the default filegroup.&lt;br /&gt;&lt;br /&gt;ON {filegroup | DEFAULT} can also be specified in a PRIMARY KEY or UNIQUE constraint. These constraints create indexes. If filegroup is specified, the index is stored in the named filegroup. If DEFAULT is specified, the index is stored in the default filegroup. If no filegroup is specified in a constraint, the index is stored on the same filegroup as the table. If the PRIMARY KEY or UNIQUE constraint creates a clustered index, the data pages for the table are stored in the same filegroup as the index.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;11.) Can we specify length to a user-defined datatype when creating table?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You cannot specify a length for a user-defined data type in a CREATE TABLE statement.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;12. Which are the columns we cannot have default definition?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;DEFAULT&lt;br /&gt;&lt;br /&gt;Specifies the value provided for the column when a value is not explicitly supplied during an insert. DEFAULT definitions can be applied to any columns except those defined as timestamp, or those with the IDENTITY property&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;13.) If we drop the table default definition will remain?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;DEFAULT definitions are removed when the table is dropped&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;14.) What are the value we can use for default definition?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Only a constant value, such as a character string; a system function, such as SYSTEM_USER(); or NULL can be used as a default. To maintain compatibility with earlier versions of SQL Server, a constraint name can be assigned to a DEFAULT.&lt;br /&gt;&lt;br /&gt;constant_expression&lt;br /&gt;&lt;br /&gt;Is a constant, NULL, or a system function used as the default value for the column.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;What is identity column in sqlserver?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Indicates that the new column is an identity column. When a new row is added to the table, Microsoft® SQL Server™ provides a unique, incremental value for the column. Identity columns are commonly used in conjunction with PRIMARY KEY constraints to serve as the unique row identifier for the table.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;15) Which are the datatype suitable for identity column?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The IDENTITY property can be assigned to tinyint, smallint, int, bigint, decimal(p,0), or numeric(p,0) columns.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;16) How many identity column can we have per table in sqlserver?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Only one identity column can be created per table&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;17) Can we specify default definition on identity column?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Bound defaults and DEFAULT constraints cannot be used with an identity column&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;18) What is the seed and increment in identity column?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You must specify both the seed and increment or neither. If neither is specified, the default is (1,1).&lt;br /&gt;&lt;br /&gt;Seed:Is the value used for the very first row loaded into the table.&lt;br /&gt;&lt;br /&gt;Increment:Is the incremental value added to the identity value of the previous row loaded&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;19) What is ROWGUIDCOL?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Indicates that the new column is a row global unique identifier column. The ROWGUIDCOL property can be assigned only to a uniqueidentifier column&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;20) How many unique identifier can we have per table?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Only one uniqueidentifier column per table can be designated as the ROWGUIDCOL column.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;21) Why do we use NEWID function on unique identifier column?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;It also does not automatically generate values for new rows inserted into the table. To generate unique values for each column, either use the NEWID function on INSERT statements or use the NEWID function as the default for the column.&lt;br /&gt;&lt;br /&gt;22) Can u guarantee uniqueness of row value on unique identifier column?&lt;br /&gt;&lt;br /&gt;The ROWGUIDCOL property does not enforce uniqueness of the values stored in the column&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;23) What are constraints in sql server?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Is an optional keyword indicating the beginning of a PRIMARY KEY, NOT NULL, UNIQUE, FOREIGN KEY, or CHECK constraint definition. Constraints are special properties that enforce data integrity and they may create indexes for the table and its columns. Constraint names must be unique within a database.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;24) What is NULL | NOT NULL in sql server&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Are keywords that determine if null values are allowed in the column. NULL is not strictly a constraint but can be specified in the same manner as NOT NULL.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;25) What is PRIMARY KEY in sql server?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Is a constraint that enforces entity integrity for a given column or columns through a unique index. Only one PRIMARY KEY constraint can be created per table.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;26) What is UNIQUE constraint?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Is a constraint that provides entity integrity for a given column or columns through a unique index. A table can have multiple UNIQUE constraints.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;27) What is FOREIGN KEY constraint?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Is a constraint that provides referential integrity for the data in the column or columns. FOREIGN KEY constraints require that each value in the column exists in the corresponding referenced column(s) in the referenced table. FOREIGN KEY constraints can reference only columns that are PRIMARY KEY or UNIQUE constraints in the referenced table or columns referenced in a UNIQUE INDEX on the referenced table.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;28) What is CHECK constraint?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Is a constraint that enforces domain integrity by limiting the possible values that can be entered into a column or columns.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;29) What is CLUSTERED | NONCLUSTERED ?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Are keywords to indicate that a clustered or a nonclustered index is created for the PRIMARY KEY or UNIQUE constraint. PRIMARY KEY constraints default to CLUSTERED and UNIQUE constraints default to NONCLUSTERED.&lt;br /&gt;&lt;br /&gt;You can specify CLUSTERED for only one constraint in a CREATE TABLE statement. If you specify CLUSTERED for a UNIQUE constraint and also specify a PRIMARY KEY constraint, the PRIMARY KEY defaults to NONCLUSTERED&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;30) What is fillfactor in sqlserver?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Specifies how full SQL Server should make each index page used to store the index data. User-specified fillfactor values can be from 1 through 100, with a default of 0. A lower fill factor creates the index with more space available for new index entries without having to allocate new space.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;31) What is cascade?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If CASCADE is specified, a row is deleted from the referencing table if that row is deleted from the parent table&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;32) How many tables sql server can have?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL Server can have as many as two billion tables per database&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;33) How many columns per table sql server can have?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1,024 columns per table&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;34) What is size of the table in sqlserver?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The number of rows and total size of the table are limited only by the available storage. The maximum number of bytes per row is 8,060. If you create tables with varchar, nvarchar, or varbinary columns in which the total defined width exceeds 8,060 bytes, the table is created, but a warning message appears. Trying to insert more than 8,060 bytes into such a row or to update a row so that its total row size exceeds 8,060 produces an error message and the statement fails.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;35) Why sqlvariant column generate warning?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;CREATE TABLE statements that include a sql_variant column can generate the following warning:&lt;br /&gt;&lt;br /&gt;The total row size (xx) for table 'yy' exceeds the maximum number of bytes per row (8060). Rows that exceed the maximum number of bytes will not be added.&lt;br /&gt;&lt;br /&gt;This warning occurs because sql_variant can have a maximum length of 8016 bytes. When a sql_variant column contains values close to the maximum length, it can overshoot the row's maximum size limit.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;36) How many indexes can we have per table?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Each table can contain a maximum of 249 nonclustered indexes and 1 clustered index. These include the indexes generated to support any PRIMARY KEY and UNIQUE constraints defined for the table.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;37) What is the order when default, identity, rowguidcol are specified?&lt;/span&gt;&lt;br /&gt;SQL Server does not enforce an order in which DEFAULT, IDENTITY, ROWGUIDCOL, or column constraints are specified in a column definition.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is Temporary Tables&lt;/span&gt;&lt;br /&gt;You can create local and global temporary tables. Local temporary tables are visible only in the current session; global temporary tables are visible to all sessions.&lt;br /&gt;Prefix local temporary table names with single number sign (#table_name), and prefix global temporary table names with a double number sign (##table_name).&lt;br /&gt;Temporary tables are automatically dropped when they go out of scope, unless explicitly dropped using DROP TABLE:&lt;br /&gt;A local temporary table created in a stored procedure is dropped automatically when the stored procedure completes. The table can be referenced by any nested stored procedures executed by the stored procedure that created the table. The table cannot be referenced by the process which called the stored procedure that created the table.&lt;br /&gt;&lt;br /&gt;All other local temporary tables are dropped automatically at the end of the current session.&lt;br /&gt;&lt;br /&gt;Global temporary tables are automatically dropped when the session that created the table ends and all other tasks have stopped referencing them. The association between a task and a table is maintained only for the life of a single Transact-SQL statement. This means that a global temporary table is dropped at the completion of the last Transact-SQL statement that was actively referencing the table when the creating session ended.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When you create local or global temporary tables, the CREATE TABLE syntax supports constraint definitions with the exception of FOREIGN KEY constraints.&lt;br /&gt;&lt;br /&gt;If a FOREIGN KEY constraint is specified in a temporary table, the statement returns a warning message indicating that the constraint was skipped, and the table is still created without the FOREIGN KEY constraints.&lt;br /&gt;&lt;br /&gt;Temporary tables cannot be referenced in FOREIGN KEY constraints.&lt;br /&gt;Consider using table variables instead of temporary tables.&lt;br /&gt;Temporary tables are useful in cases when indexes need to be created explicitly on them, or when the table values need to be visible across multiple stored procedures or functions. In general,&lt;br /&gt;table variables contribute to more efficient query processing&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Notes PRIMARY KEY Constraints Features&lt;/span&gt;&lt;br /&gt;A table can contain only one PRIMARY KEY constraint.&lt;br /&gt;&lt;br /&gt;The index generated by a PRIMARY KEY constraint cannot cause the number of indexes on the table to exceed 249 nonclustered indexes and 1 clustered index.&lt;br /&gt;&lt;br /&gt;If CLUSTERED or NONCLUSTERED is not specified for a PRIMARY KEY constraint, CLUSTERED is used if there are no clustered indexes specified for UNIQUE constraints.&lt;br /&gt;&lt;br /&gt;All columns defined within a PRIMARY KEY constraint must be defined as NOT NULL. If nullability is not specified, all columns participating in a PRIMARY KEY constraint have their nullability set to NOT NULL.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Notes UNIQUE Constraints Features&lt;/span&gt;&lt;br /&gt;If CLUSTERED or NONCLUSTERED is not specified for a UNIQUE constraint, NONCLUSTERED is used by default.&lt;br /&gt;Each UNIQUE constraint generates an index. The number of UNIQUE constraints cannot cause the number of indexes on the table to exceed 249 nonclustered indexes and 1 clustered index.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Notes FOREIGN KEY Constraints Features&lt;/span&gt;&lt;br /&gt;When a value other than NULL is entered into the column of a FOREIGN KEY constraint, the value must exist in the referenced column; otherwise, a foreign key violation error message is returned.&lt;br /&gt;&lt;br /&gt;FOREIGN KEY constraints are applied to the preceding column unless source columns are specified.&lt;br /&gt;&lt;br /&gt;FOREIGN KEY constraints can reference only tables within the same database on the same server. Cross-database referential integrity must be implemented through triggers. &lt;br /&gt;&lt;br /&gt;FOREIGN KEY constraints can reference another column in the same table (a self-reference).&lt;br /&gt;The REFERENCES clause of a column-level FOREIGN KEY constraint can list only one reference column, which must have the same data type as the column on which the constraint is defined.&lt;br /&gt;&lt;br /&gt;The REFERENCES clause of a table-level FOREIGN KEY constraint must have the same number of reference columns as the number of columns in the constraint column list. The data type of each reference column must also be the same as the corresponding column in the column list.&lt;br /&gt;&lt;br /&gt;CASCADE may not be specified if a column of type timestamp is part of either the foreign key or the referenced key.&lt;br /&gt;&lt;br /&gt;It is possible to combine CASCADE and NO ACTION on tables that have referential relationships with each other. If SQL Server encounters NO ACTION, it terminates and rolls back related CASCADE actions. When a DELETE statement causes a combination of CASCADE and NO ACTION actions, all the CASCADE actions are applied before SQL Server checks for any NO ACTION.&lt;br /&gt;&lt;br /&gt;A table can contain a maximum of 253 FOREIGN KEY constraints.&lt;br /&gt;FOREIGN KEY constraints are not enforced on temporary tables.&lt;br /&gt;&lt;br /&gt;A table can reference a maximum of 253 different tables in its FOREIGN KEY constraints.&lt;br /&gt;&lt;br /&gt;FOREIGN KEY constraints can reference only columns in PRIMARY KEY or UNIQUE constraints in the referenced table or in a UNIQUE INDEX on the referenced table.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Notes DEFAULT Definitions Features&lt;/span&gt;&lt;br /&gt;A column can have only one DEFAULT definition.&lt;br /&gt;&lt;br /&gt;A DEFAULT definition can contain constant values, functions, SQL-92 niladic functions, or NULL. The table shows the niladic functions and the values they return for the default during an INSERT statement.&lt;br /&gt;&lt;br /&gt;constant_expression in a DEFAULT definition cannot refer to another column in the table, or to other tables, views, or stored procedures.&lt;br /&gt;&lt;br /&gt;DEFAULT definitions cannot be created on columns with a timestamp data type or columns with an IDENTITY property.&lt;br /&gt;&lt;br /&gt;DEFAULT definitions cannot be created for columns with user-defined data types if the user-defined data type is bound to a default object.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Notes CHECK Constraints Features&lt;/span&gt;&lt;br /&gt;A column can have any number of CHECK constraints, and the condition can include multiple logical expressions combined with AND and OR. Multiple CHECK constraints for a column are validated in the order created.&lt;br /&gt;&lt;br /&gt;The search condition must evaluate to a Boolean expression and cannot reference another table.&lt;br /&gt;&lt;br /&gt;A column-level CHECK constraint can reference only the constrained column, and a table-level CHECK constraint can reference only columns in the same table.&lt;br /&gt;&lt;br /&gt;     CHECK CONSTRAINTS and rules serve the same function of validating the data         during INSERT and DELETE statements.&lt;br /&gt;When a rule and one or more CHECK constraints exist for a column or columns, all restrictions are evaluated.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Notes on Additional Constraint Information&lt;/span&gt;&lt;br /&gt;An index created for a constraint cannot be dropped with the DROP INDEX statement; the constraint must be dropped with the ALTER TABLE statement. An index created for and used by a constraint can be rebuilt with the DBCC DBREINDEX statement.&lt;br /&gt;&lt;br /&gt;Constraint names must follow the rules for identifiers, except that the name cannot begin with a number sign (#). If constraint_name is not supplied, a system-generated name is assigned to the constraint. The constraint name appears in any error message about constraint violations.&lt;br /&gt;&lt;br /&gt;When a constraint is violated in an INSERT, UPDATE, or DELETE statement, the statement is terminated. However, the transaction (if the statement is part of an explicit transaction) continues to be processed. You can use the ROLLBACK TRANSACTION statement with the transaction definition by checking the @@ERROR system function.&lt;br /&gt;&lt;br /&gt;If a table has FOREIGN KEY or CHECK CONSTRAINTS and triggers, the constraint conditions are evaluated before the trigger is executed.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;38) To Report a table which command do you use?&lt;/span&gt;&lt;br /&gt;For a report on a table and its columns, use sp_help or sp_helpconstraint.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;39) To rename a table which command do you use?&lt;/span&gt;&lt;br /&gt;To rename a table, use sp_rename.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;40) What is the use of sp_depends&lt;/span&gt;&lt;br /&gt;For a report on the views and stored procedures that depend on a table, use sp_depends.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;41) What is the use of sp_spaceused?&lt;/span&gt;&lt;br /&gt;Space is generally allocated to tables and indexes in increments of one extent at a time. When the table or index is created, it is allocated pages from mixed extents until it has enough pages to fill a uniform extent. After it has enough pages to fill a uniform extent, another extent is allocated each time the currently allocated extents become full. For a report about the amount of space allocated and used by a table, execute sp_spaceused.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4905884173788197974-2528114853594266045?l=sqldemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqldemo.blogspot.com/feeds/2528114853594266045/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqldemo.blogspot.com/2009/06/tables_27.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/2528114853594266045'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/2528114853594266045'/><link rel='alternate' type='text/html' href='http://sqldemo.blogspot.com/2009/06/tables_27.html' title='SQL Server Interview Question:Table'/><author><name>thangadurai</name><uri>http://www.blogger.com/profile/16066274107687970274</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4905884173788197974.post-3925806501517258233</id><published>2009-06-20T04:22:00.000-07:00</published><updated>2009-06-20T04:25:18.526-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Create Table'/><title type='text'>How do create table in sql server</title><content type='html'>Create table emp&lt;br /&gt;(&lt;br /&gt;        empid int not null,&lt;br /&gt;        empname char(20) not null,&lt;br /&gt;        city char(20) not null&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;--Insert values&lt;br /&gt;&lt;br /&gt;insert into emp(empid,empname,city)values(1,thangadurai,chennai)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4905884173788197974-3925806501517258233?l=sqldemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqldemo.blogspot.com/feeds/3925806501517258233/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqldemo.blogspot.com/2009/06/create-table-emp-empid-int-not-null.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/3925806501517258233'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4905884173788197974/posts/default/3925806501517258233'/><link rel='alternate' type='text/html' href='http://sqldemo.blogspot.com/2009/06/create-table-emp-empid-int-not-null.html' title='How do create table in sql server'/><author><name>thangadurai</name><uri>http://www.blogger.com/profile/16066274107687970274</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
