Sie sind auf Seite 1von 14

Explain the difference between DBMS and RDBMS.

DBMS: A DBMS is a storage area that persist the data in files. To perform the database operations, the file should be in use. Relationship can be established between 2 files. There are limitations to store records in a single database file depending upon the database manager used. DBMS allows the relations to be established between 2 files. Data is stored in flat files with metadata. DBMS does not support client / server architecture. DBMS does not follow normalization. Only single user can access the data. DBMS does not impose integrity constraints. ACID properties of database must be implemented by the user or the developer RDBMS: RDBMS stores the data in tabular form. It has additional condition for supporting tabular structure or data that enforces relationships among tables. RDBMS supports client/server architecture. RDBMS follows normalization. RDBMS allows simultaneous access of users to data tables. RDBMS imposes integrity constraints. ACID properties of the database are defined in the integrity constraints. What is RDBMS? Explain its features. RDBMS is a database management system based on relational model defined by E.F.Codd. Data is stored in the form of rows and columns. The relations among tables are also stored in the form of the table. Features: - Provides data to be stored in tables - Persists data in the form of rows and columns - Provides facility primary key, to uniquely identify the rows - Creates indexes for quicker data retrieval - Provides a virtual table creation in which sensitive data can be stored and simplified query can be applied.(views) - Sharing a common column in two or more tables(primary key and foreign key) Define SQL. SQL stands for Structured Query Language. It allows access, insert/update/delete records and retrieve data from the database. Structured Query Language, SQL Structured Query Language is a relational database language, designed for managing data. The scope of SQL includes data query, including data, deleting and modifying data and controlling the access to the data. A specialized language for sending queries to database. Every specific

application will have its own version of implementing SQL features, but all SQL-capable database managers support a common subset of SQL What is an Entity-Relationship diagram? ER diagram is a conceptual and abstract representation of data and entities. ER is a data modeling process, which is to produce a conceptual schema of a system, often an RDBMS and the needs in top down fashion. ER diagrams are derived by using this model. Define Primary key and Foreign key. A column or combination of columns that identify a row of data in a table is Primary Key. A key in a table that identifies records in other table in called a foriegn key. Primary key and unique key Both are used to provide uniqueness of the column. Primary key creates clustered key on the column by default whereas unique key creates non-clustered index by default. Primary doesn't allow NULL values whereas unique key can allow one NULL value. Define Primary key and foreign key. Primary Key: Primary key is used for unique identification of each row in a table. Unique and not null values only are accepted to persist in primary key. Foreign Key: Foreign Key identifies a column with the primary key column of another table (parent table) for storing data. The values in the foreign key must be the values of primary key of other columns. Thus it ensures the data integrity correct data. Define alternate key. There can be a key apart from primary key in a table that can also be a key. This key may or may not be a unique key. For example, in an employee table, empno is a primary key, empname is a alternate key that may not be unique but still helps in identifying a row of the table. Define alternate key. An alternate key is similar to a primary key. It accepts null values; where as the primary key does not. The null values can be submitted to the attribute in a tuple. What are indexes? Index can be thought as index of the book that is used for fast retrieval of information. Index uses one or more column index keys and pointers to the record to locate record. Index is used to speed up query performance. Both exist as B-tree structure. Kind of the indexes are clustered and non-clustered.

Index is the way to order the records in a database according to the field values. It is the way to have fast access to the particular information. Indexes are created to the columns that are queried frequently. What are the disadvantages of the Indexes? Indexes improve query performance but it slows down data modification operations. Indexes consume disk space Explain Data Definition Language, Data Control Language and Data Manipulation Language. Data Definition Language (DDL):- are the SQL statements that define the database structure. Example:
a. b. c. d. e. f.

CREATE ALTER DROP TRUNCATE COMMENT RENAME

Data Manipulation Language (DML):- statements are used for manipulate or edit data. Example:
a. b. c. d. e. f. g. h.

SELECT - retrieve data from the a database INSERT - insert data into a table UPDATE - updates existing data within a table DELETE MERGE CALL EXPLAIN PLAN LOCK TABLE

Data Control Language (DCL):-statements to take care of the security and authorization. Examples:
a. GRANT b. REVOKE

What are the Authentication Modes in SQL Server?

1. Windows Authentication Mode (Windows Authentication): uses

users Windows account


a. Mixed Mode (Windows Authentication and SQL Server

Authentication): uses either windows or SQL server What is the purpose of SQL Profiler in SQL server? SQL profiler is a tool to monitor performance of various stored procedures. It is used to debug the queries and procedures. Based on performance, it identifies the slow executing queries. Capture any problems by capturing the events on production environment so that they can be solved. Explain GO Command. Go command is a signal to execute the entire batch of SQL statements after previous Go. What is the significance of NULL value and why should we avoid permitting null values? NULL value means that no entry has been made into the column. It states that the corresponding value is either unknown or undefined. It is different from zero or "". They should be avoided to avoid the complexity in select & update queries and also because columns which have constraints like primary or foreign key constraints cannot contain a NULL value. What are the differences among batches, stored procedures, and triggers? Batch Stored Procedure Triggers Collection or group of Its a collection or Its a type of Stored SQL statements. All group of SQL procedure that cannot statements of a batch statements thats be called directly. are compiled into one compiled once but Instead it fires when a executional unit called used many times. row is updated, execution plan. All deleted, or inserted. statements are then executed statement by statement. What are the advantages of using Stored Procedures? Advantages of using stored procedures are: They are easier to maintain and troubleshoot as they are modular. Stored procedures enable better tuning for performance. Using stored procedures is much easier from a GUI end than building/using complex queries.

They can be part of a separate layer which allows separating the concerns. Hence Database layer can be handled by separate developers proficient in database queries. Help in reducing network usage. Provides more scalability to an application. Reusable and hence reduce code.

What are the restrictions applicable while creating views? Views can be created referencing tables and views only in the current database. A view name must not be the same as any table owned by that user. You can build views on other views and on procedures that reference views. Rules or DEFAULT definitions can't be associated with views. Only INSTEAD OF triggers can be associated with views. The query that defines the view cannot include the ORDER BY, COMPUTE, or COMPUTE BY clauses or the INTO keyword. You cannot define full-text index definitions for views. You cannot create temporary views You cannot create views on temporary tables What is SQL service broker? Service Broker allows internal and external processes to send and receive guaranteed, asynchronous messaging. Messages can also be sent to remote servers hosting databases as well. The concept of queues is used by the broker to put a message in a queue and continue with other applications asynchronously. This enables client applications to process messages at their leisure without blocking the broker. Service Broker uses the concepts of message ordering, coordination, multithreading and receiver management to solve some major message queuing problems. It allows for loosely coupled services, for database applications What is cursor? A Cursor is a database object that represents a result set and is used to manipulate data row by row. When a cursor is opened, it is positioned on a row and that row is available for processing. A cursor is a temporary work area created in the system memory when a SQL statement is executed. A cursor contains information on a select statement and the rows of data accessed by it. This temporary work area is used to store the data retrieved from the database, and manipulate this data. A cursor can hold more than one row, but can process only one row at a time. The set of rows the cursor holds is called the active set. There are two types of cursors in PL/SQL: Implicit cursors:

These are created by default when DML statements like, INSERT, UPDATE, and DELETE statements are executed. They are also created when a SELECT statement that returns just one row is executed. The user will not be aware of this happening and will not be able to control or process the information in an implicit cursor. Explicit cursors: They must be created when you are executing a SELECT statement that returns more than one row. That means the programmer has declared the cursor within the PL/SQLcode block. This declaration allows for the application to sequentially process each row of data as it is returned by the cursor. Even though the cursor stores multiple records, only one record can be processed at a time, which is called as current row. When you fetch a row the current row position moves to next row. The only means of generating an explicit cursor is for the cursor to be named in the DECLARE section of the PL/SQL Block. The advantages of declaring an explicit cursor over the indirect implicit cursor are that the explicit cursor gives more programmatic control to the programmer. Implicit cursors are less efficient than explicit cursors and thus it is harder to trap data errors What is sub-query? A query within a query is defined as a sub-query. A sub query is executed by enclosing it within another query. Sub queries are used for returning single row as an atomic value. A sub query is nested in DML statements, and enclosed in parenthesis. What is "correlated sub queries"? A correlated sub query is a type of sub query. Unlike sub query, a correlated sub query is dependent upon the outer query, which returns a value. When a reference to the outer query is found in the sub query, then the outer query will execute first, and the result will be returned to the correlated sub query. The sub query is executed alter for every row that is selected in the outer query. What is Data Warehousing? Data Warehousing is a process of storing and accessing data from central location for some strategic decision. Data Warehouse is a collection of subject oriented databases that are design to support decision support functions. What is Data Warehousing? Enterprises data is electronic repository in data warehouse. Reporting and analysis facilitates are designated by data warehousing. The means for retrieving and analyzing data for extraction, transformation and loading is considered as mandatory components in data warehousing

system. It includes the management of data dictionary. It includes business intelligence tools. Explain Execution Plan.

SQL Server caches the plan of execution of query or stored procedure which it uses in subsequent call. This is a very important feature with regards to performance enhancement. You can view execution plan of data retrieval graphically or textually.

Explain the types of Data integrity. a. Entity Integrity: It means that the row is kept as a unique entity. It ensures that the integrity of the identifier is maintained through PRIMARY KEYS, IDENTITY property etc b. Domain Integrity: It validates the entries for a given column. Restricted data types can be given, FOREIGN KEY, CHECK and NOT NULL constraints can be specified. c. Referential Integrity: it helps in maintaining the relationships between tables when a new row is inserted or deleted. Usually Foreign leys are used to define relationships between tables. d. User-Defined Integrity : as the name suggests, user defined integrity is used to define business rules by the user. The rules are such that they dont fall under the category of any type of integrity type. Procedures and triggers are examples of such types of user defined integrity. Explain the classes of constraints. i.e. Primary key, Unique, Foreign Key and Check Constraints. Primary Key: This constraint when applied to a column ensures that the row is unique. This means that only ONE row with this ID can exist. For e.g. a table SALES has its primary key as sales_id. The column is specified as primary key by :sales_id PRIMARY KEY Unique: This constraint makes sure that the columns have unique values. This also means that no two rows can have the same value for the column specified as unique. They differ from primary keys by allowing NULL as one of the values. The keyword UNIQUE is used. Foreign Key: This constraint helps to establish relationships between tables. When one key is being referenced in another table, the key is called as a foreign key. For e.g. Sales_id from SALES table can be referenced in ORDER table. E.g in table ORDER sales_id is written as: FOREIGN KEY REFERENCES SALES (sales_id) Check constraints: This constraint restricts the value that can be inserted In a column. It specifies a BOOLEAN value. Values that can be accepted and meet the criteria are evaluated as TRUE while the ones that are rejected are evaluated as FALSE. e.g. CONSTRAINT amt CHECK (amt BETWEEN 10 and 1000)

Transaction Anomalies Anomaly Dirty Reads Example Transaction A begins.

A dirty read happens when a UPDATE employee SET salary = transaction reads data that is being 31650 modified by another transaction that WHERE empno = '000090' Transaction B begins. has not yet committed. SELECT * FROM employee (Transaction B sees data updated by transaction A. Those updates have not yet been committed.) Non-Repeatable Reads Non-repeatable reads happen when a query returns data that would be different if the query were repeated within the same transaction. Nonrepeatable reads can occur when other transactions are modifying data that a transaction is reading. Transaction A begins. SELECT * FROM employee WHERE empno = '000090' Transaction B begins. UPDATE employee SET salary = 30100 WHERE empno = '000090' (Transaction B updates rows viewed by transaction A before transaction A commits.) If Transaction A issues the same SELECT statement, the results will be different. Transaction A begins. SELECT * FROM employee WHERE salary > 30000 Transaction B begins. INSERT INTO employee (empno, firstnme, midinit, lastname, job, salary) VALUES ('000350', 'NICK', 'A','GREEN','LEGAL COUNSEL',35000) Transaction B inserts a row that would satisfy the query in Transaction A if it were issued again.

Phantom Reads Records that appear in a set being read by another transaction. Phantom reads can occur when other transactions insert rows that would satisfy the WHERE clause of another transaction's statement.

Explain the characteristics of a transaction. i.e. Atomicity, Consistency, Isolation, Durability.

Characteristics of a transaction:Atomicity This characteristic of a transaction means that a transaction is performed completely not performed at all. I.e. all the tasks in a transaction are completed or none are completed. E.g. transferring money from one account to another involves credit from one account and debit to another. Consistency This characteristic means that the database should be consistent before and after the transaction. For a successful transaction database can move from one state to another. Both the states should abide by the same rules. For an unsuccessful transaction, if the transaction fails to abide by the rule and leads to an inconsistent state, the transaction should be rolled back. Isolation A transaction should be isolated. This means that that no other operation should be allowed to access or see the intermediate state data. Durability A transaction on completion must persist. It should withstand system failures and should not be undone. Explain various types of SQL Server transactions. I.e. Explicit, Autocommit and Implicit Transactions. Explicit transaction A transaction which has START and END defined explicitly. The explicit transaction mode lasts until the transaction is over. When the transaction is over, the transaction is reverted back to the mode in which it started. This mode could either be implicit or autocommit. Autocommit transactions This is the default mode of transaction. In this mode, if the transaction is completed successfully, it is committed. If the transaction faces any error, it is rolled back. Implicit transactions In this mode, a new transaction is started when the current is committed or rolled back. Nothing is done to begin a transaction. One only needs to commit or roll back a transaction. Implicit transactions have a chain of continuous transactions. Explain the isolation level that SQL Server support. Isolation levels:

READ UNCOMMITTED: - Reads data that has been modified but not committed yet. READ UNCOMMITTED: - Cannot Read data that has been modified but not committed yet REPEATABLE READ: - cannot read data that has been modified but not yet committed by other transactions and that no other transactions can modify data that has been read by the current transaction until the current transaction completes

SNAPSHOT: - Data read by any statement in a transaction will be a consistent version of the data that existed at the start of the transaction. Here, the transaction can only identify the data modification that was committed before the start of the transaction. SERIALIZABLE:- Cannot Read data that has been modified but not committed yet, until the current transaction completes, no other transaction can modify the data and no other transactions will insert new rows whose keys falls in the range of current transaction

What is a dead lock? When two computer programs sharing the same resource prevent each other from accessing the resource results in a deadlock. This deadlock results in finishing the program. Example: P1 P2 P1 P2 requests requests requests requests R1 and receives it. R2 and receives it. resource R2 and is queued up, pending the release of R2. resource R1 and is queued up, pending the release of R1

Here, P and R is Program and Resource respectively. What are the different types of lock modes in SQL Server 2000? Different lock modes: Shared (S): Mostly used for Read only operations like SELECT statements. It allows concurrent transactions to read data. No other transaction can modify the data until the lock is present. The lock is released as soon as the read is over. Update locks (U): used to prevent dead locks. Used on resources that can be updated. Common forms of deadlocks occur when multiple sessions are reading, locking, and potentially updating resources later. Exclusive (X): used for data modifications statements like INSERT, UPDATE or DELETE. This lock ensures multiple updates cant be made simultaneously. Schema: Sch-M or Schema modification locks are used when an operation related to the table schema is being performed. Schema Stability or Sch-S locks are used when queries are being complied. Bulk update locks: Used when bulk copy is being performed. BU allows processes to bulk copy data concurrently into the same table while preventing other processes that are not bulk copying data from accessing the table. What is a dead lock? A dead lock occurs when 2 user processes have locks on 2 separate objects and each process is trying to acquire a lock on the object which is under the other process. SQL Server identifies dead locks and ends the dead lock by choosing one process and aborting the other process automatically. The aborted transaction is rolled back and an error

message is sent to the user application. Usually, the transaction which needs the least amount of overhead to rollback is aborted. What is a live lock? A live lock is similar to a deadlock that the states of the processes involved in the live lock constantly change with regard to one another, none progressing. This happens when where a request for an exclusive lock is repeatedly denied because a series of overlapping shared locks keeps interfering. What is the syntax for creating a new assembly in SQL Server 2005? Assemblies can be created using CREATE ASSEMBLY command. It takes the path of the DLL as the parameter. Example: CREATE DIRECTORY Sample FROM \\sampleserver\CodeLib\Mysample.dll When the CREATE ASSEMBLY is executed, the DLL is copied to master database. What is inner join? Explain with an example. A SQL server Join is helps to query data from two or more tables between columns of these tables. A simple JOIN returns data for at least one match between the tables. The columns need to be similar. Usually primary key one table and foreign key of another is used. Syntax: Table1_name JOIN table2_name ON table1_name.column1_name= table2_name.column2_name. What is inner join? Explain with an example Answer INNER JOIN: Inner join returns rows when there is at least one match in both tables. Syntax: SELECT column_name(s) FROM table_name1 INNER JOIN table_name2 ON table_name1.column_name=table_name2.column_name Example: To display records of an employee who got an appraisal. SELECT employee.firstname, appraisal.amount FROM employee INNER JOIN appraisal ON employee.id = appraisal.employee.id; What is outer join? Explain Left outer join, Right outer join and Full outer join. OUTER JOIN: In An outer join, rows are returned even when there are no matches through the JOIN criteria on the second table. LEFT OUTER JOIN: A left outer join or a left join returns results from the table mentioned on the left of the join irrespective of whether it finds

matches or not. If the ON clause matches 0 records from table on the right, it will still return a row in the resultbut with NULL in each column. Example: To display employees irrespective of whether they have got bonus. Select * From employee LEFT OUTER JOIN bonus ON employee.bonusID=bonus.bonusID RIGHT OUTER JOIN: A right outer join or a right join returns results from the table mentioned on the right of the join irrespective of whether it finds matches or not. If the ON clause matches 0 records from table on the left, it will still return a row in the resultbut with NULL in each column. Example: To display Bonus irrespective of whether they are an employee or not. Select * From employee RIGHT OUTER JOIN bonus ON employee.bonusID=bonus.bonusID FULL OUTER JOIN: A full outer join will combine results of both left and right outer join. Hence the records from both tables will be displayed with a NULL for missing matches from either of the tables. Example: To display employees who have a bonus and to display bonus even if he is not an employee. Select * From employee FULL OUTER JOIN bonus ON employee.bonusID=bonus.bonusID

CROSS JOIN This join is a Cartesian join that does not necessitate any condition to join. The resultset contains records that are multiplication of record number from both the tables.

What are XML indexes? XML indexes are created on XML data type columns. Having XML indexes will reduce cost with respect to maintenance and data modification. Use of XML indexes avoids the need to parse the complete data at runtime thereby increasing query processing efficiency. What are secondary XML indexes? XML indexes can either be primary or secondary. When the XML type column has its first index, it is called as a primary index. Using this primary index, secondary indexes like PATH, VALUE and PROPERTY are supported. Depending on the nature of queries, they help in query optimization. Path secondary index if used speeds up queries if the query specifies a path.

Path secondary index if used speeds up queries are value based. Path secondary index if used speeds up queries if the query retrieves one or more values from individual XML instances. What is FOR XML in SQL Server? FOR XML allows data to be retrieved in an XML format. The FOR XML clause needs to be mentioned at the end of SELECT statement. There are three modes of FOR XML:RAW mode: - An XML element is formed for each row in the query results. AUTO mode: - The query results are returned as nested XML elements. Explicit mode: - the format of the XML document returned by the query can be completely controlled by the query. What is the OPENXML statement in SQL Server? OPENXML is a row set provider, in which a row set view over an XML documented is provided. It is used to parse the complex XML function. Syntax: OPENXML(idoc int [in],rowpattern nvarchar[in],[flags byte[in]]) [WITH (SchemaDeclaration | TableName)] Idoc is the document handle of an XML document which is created by calling sp_xml_preparedocument Xpath is the pattern used to identify the nodes. Flag is for mapping between the XML data and the relational rowset WITH clause is used to provide a rowset format.

Describe in brief exporting and importing utility BCP Utility The Bulk Copy is a command utility that transfer SQL data to or from a data file. This utility mostly used to transfer huge data to SQL server from other database. With this, data is first exported from source file to a data file and then imported from the data file to SQL server table. It is also used to transfer data from SQL server table to a data file. You can use Bulk Insert statement to transfer data from data file to SQL server table. DTS Packages It is a set of tools that allows you extract, transform, and consolidate data from disparate sources into single or multiple destinations. You can create custom data movement solution using DTS object model. DTS packages can provide following services:

It can import or export data to or from text file or OLE DB data source. It supports data transformation using DTS transformation which means that data can be operated using one or more functions before hitting the destination. You can transfer database objects along with data using DTS package. DTS package also notifies if package steps succeed or failed by sending mails to source and destination Data Transformation Services is a set of tools available in SQL server that helps to extract, transform and consolidate data. This data can be from different sources into a single or multiple destinations depending on DTS connectivity. To perform such operations DTS offers a set of tools. Depending on the business needs, a DTS package is created. This package contains a list of tasks that define the work to be performed on, transformations to be done on the data objects. Import or Export data: DTS can import data from a text file or an OLE DB data source into a SQL server or vice versa. Transform data: DTS designer interface also allows to select data from a data source connection, map the columns of data to a set of transformations, and send the transformed data to a destination connection. For parameterized queries and mapping purposes, Data driven query task can be used from the DTS designer. Consolidate data: the DTS designer can also be used to transfer indexes, views, logins, triggers and user defined data. Scripts can also be generated for the sane For performing these tasks, a valid connection(s) to its source and destination data and to any additional data sources, such as lookup tables must be established. Describe in brief exporting and importing utility SQL Server has an export/import wizard that allows creation of a Integration services package enabling export import of data from one location to another. To start the wizard: Start menu-> SQL Server Management Studio-> Business Intelligence Development Studio. This wizard can import/export data from any data source that has a managed .Net Framework data provide or its own native OLEDB provider. E.g.: SQL Server, Flat files, MS Access, MS Excel etc. What is difference between a PROCEDURE & FUNCTION ? Ans. A FUNCTION always returns a value using the return statement. A PROCEDURE may return one or more values through parameters or may not return at all.

Das könnte Ihnen auch gefallen