1. What is database? A database is a logically coherent collection of data with some inherent meaning, representing some aspect of real world and which is designed, built and populated with data for a specific purpose. 2. What is DBMS? It is a collection of programs that enables user to create and maintain a database. In other words it is general-purpose software that provides the users with the processes of defining, constructing and manipulating the database for various applications. 3. What is a Database system? The database and DBMS software together is called as Database system. 4. What are the advantages of DBMS? 1. 2. 3. 4. 5.
Redundancy is controlled. Unauthorised access is restricted. Providing multiple user interfaces. Enforcing integrity constraints. Providing backup and recovery.
5. What are the disadvantage in File Processing System? 1. 2. 3. 4. 5. 6.
Data redundancy and inconsistency. Difficult in accessing data. Data isolation. Data integrity. Concurrent access is not possible. Security Problems.
6. Describe the three levels of data abstraction? The are three levels of abstraction: 1. Physical level: The level: The lowest level of abstraction describes how data are stored. 2. Logical level: The level: The next higher level of abstraction, describes what data are stored in database and what relationship among those data. 3. View level: The level: The highest level of abstraction describes only part of entire database. Define the "integrity rules"? There are two Integrity rules. 1. Entity Integrity: States Integrity: States that "Primary key cannot have NULL value" 2. Referential Integrity: States Integrity: States that "Foreign Key can be either a NULL value or should be Primary Key value of other relation.
What is Data Independence? Data independence means that "the application is independent of the storage structure and access strategy of data". In other words, The ability to modify the schema definition in one level should not affect the schema definition in the next higher level. Two types of Data Independence: 1. Physical Data Independence: Modification in physical level should not affect the logical level. 2. Logical Data Independence: Modification in logical level should affect the view level. 3. What is a view? How it is related to data independence? A view may be thought of as a virtual table, that is, a table that does not really exist in its own right but is instead derived from one or more underlying base table. In other words, there is no stored file that direct represents the view instead a definition of view is stored in data dictionary.
4.
5.
6. 7.
Growth and restructuring of base tables is not reflected in views. Thus the view can insulate users from the effects of restructuring and growth in the database. Hence accounts for logical data independence. What is Data Model? A collection of conceptual tools for describing data, data relationships data semantics and constraints. What is Object Oriented model? This model is based on collection of objects. An object contains values stored in instance variables with in the object. An object also contains bodies of code that operate on the object. These bodies of code are called methods. Objects that contain same types of values and the same methods are grouped together into classes. What is Relationship? It is an association among two or more entities. What is DDL (Data Definition Language)? A data base schema is specifies by a set of definitions expressed by a special language called DDL.
What is DML (Data Manipulation Language)? This language that enable user to access or manipulate data as organised by appropriate data model. 1. Procedural DML or Low level: DML requires a user to specify what data are needed and how to get those data. 2. Non-Procedural DML or High level: DML requires a user to specify what data are needed without specifying how to get those data. 3. What is normalization? 4. It is a process of analysing the given relation schemas based on their Functional Dependencies (FDs) and primary key to achieve the properties (1).Minimizing redundancy, (2). Minimizing insertion, deletion and update anomalies. What are partial, alternate,, artificial, compound and natural key? 1. Partial Key: It is a set of attributes that can uniquely identify weak entities and that are related to same owner entity. It is sometime called as Discriminator.
2. Alternate Key: All Candidate Keys excluding the Primary Key are known as Alternate Keys. 3. Artificial Key: If no obvious key, either stand alone or compound is available, then the last resort is to simply create a key, by assigning a unique number to each record or occurrence. Then this is known as developing an artificial key. 4. Compound Key: If no single data element uniquely identifies occurrences within a construct, then combining multiple elements to create a unique identifier for the construct is known as creating a compound key. 5. Natural Key: When one of the data elements stored within a construct is utilized as the primary key, then it is called the natural key. What is indexing and what are the different kinds of indexing? Indexing is a technique for determining how quickly specific data can be found. Types: 1. 2. 3. 4. 5. 6.
Binary search style indexing B-Tree indexing Inverted list indexing Memory resident table Table indexing What is a query? A query with respect to DBMS relates to user commands that are used to interact with a data base. The query language can be classified into data definition language and data manipulation language. 7. What are the unary operations in Relational Algebra? PROJECTION and SELECTION. 8. How do you communicate with an RDBMS? You communicate with an RDBMS using Structured Query Language (SQL). 9. Name the three major set of files on disk that compose a database in Oracle. There are three major sets of files on disk that compose a database. All the files are binary. These are 1.) Database files 2.) Control files 3.) Redo logs The most important of these are the database files where the actual data resides. The control files and the redo logs support the functioning of the architecture itself. All three sets of files must be present, open, and available to Oracle for any data on the database to be useable. Without these files, you cannot access the database, and the database administrator might have to recover some or all of the database using a backup, if there is one. 10. What is database Trigger? A database trigger is a PL/SQL block that can defined to automatically execute for insert, update, and delete statements against a table. The trigger can e defined to execute once for the entire statement or once for every row that is inserted, updated, or deleted. For any one table, there are twelve events for which you can define database triggers. A database trigger can call database procedures that are also written in PL/SQL. 11. What are stored-procedures? And what are the advantages of using them? Stored procedures are database objects that perform a user defined operation. A stored procedure can have a set of compound SQL statements. A stored procedure executes the SQL commands and returns the result to the client. Stored procedures are used to reduce network traffic.
12. What are data and information, and how are they related in a database? Data is recorded facts and figures, and information is knowledge derived from data. A database stores data in such a way that information can be created. 13. Who is E.F. Codd, and why is he significant in the development of modern database systems? 14. While working at IBM, E.F. Codd created the relational database model. A paper he published in 1970 presented his ideas to the world at large. His work is the foundation for most of the DBMSs currently in use, and thus forms the basis for database systems as we know and use them today. 15. What is SQL, and why is it important? SQL stands for Structured Query Language, and is the most important data processing language in use today. It is not a complete programming language like Java or C#, but a data sublanguage used for creating and processing database data and metadata. All DBMS products today use SQL. 16. Write an SQL SELECT statement to display all the columns of the STUDENT table but only those rows where the Grade column is greater than or equal to 90. SELECT * FROM STUDENT WHERE Grade >= 90; 17. Name and briefly describe the five SQL built-in functions. COUNT: computes the number of rows in a table. SUM: totals numeric columns. AVG: computes the average value. MAX: obtains the maximum value of a column in a table. MIN: obtains the minimum value of a column in a table. 18. Write an SQL SELECT statement to count the number of rows in STUDENT table and display the result with the label NumStudents. SELECT COUNT(*) AS NumStudents FROM STUDENT; 19. What is an SQL subquery? An SQL subquery is a means of querying two or more tables at the same time. The subquery itself is an SQL SELECT statement contained within the WHERE clause of another SQL SELECT statement, and separated by being enclosed in parenthesis. Some subqueries have equivalent SQL join structures, but correlated subqueries cannot be duplicated by a join.. 20. Discuss the alternative terminology that is used in the relational model. Relations are also called tables, and sometimes by the older data processing term files. A row is known as a tuple in the relational model, but may also be referred to as a record. Finally, relational model attributes are known as table columns and sometimes as fields. 21. What is a foreign key, and what is it used for? A foreign key is used to establish relationships among relations in the relational model. Technically, a foreign key is a column (or columns) appearing in one relation that is (are) the primary key of another table. Although there may be exceptions, the values in the foreign key columns usually must correspond to values existing in the set of primary key values. This correspondence requirement is created in a database using a referential integrity constraint on the foreign key. 22. What does it mean when we say that a relation is in Boyce-Codd Normal Form (BCNF)? A relation is in BCNF when every determinant in the relation is a candidate key. This means that any possible primary key can determine all other attributes in the relation. Attributes may not be determined by non-candidate key attributes or part of a composite candidate key. Thus it is said "I swear to construct my tables so that all nonkey columns are dependent on the key, the whole key and nothing but the key, so help me Codd!" 23. You have been given a set of tables with data and asked to create a new database to store them. When you examine the data values in the tables, what are you looking for?
(1) Multivalued dependencies, (2) Functional dependencies, (3) Candidate keys, (4) Primary keys and (5) Foreign keys. 24. Define a surrogate key, describe the ideal primary key and explain how surrogate keys meet this ideal. The ideal primary key is short, numeric and fixed. A surrogate key is a unique, DBMS-supplied identifier intended to be used as the primary key of a table. Further, the DBMS will not allow the value of a surrogate key to be changed. The values of a surrogate key have no meaning to the users and are usually hidden on forms and reports. By design, they are short, numeric and fixed and thus meet the definition of the ideal primary key 25. Define and discuss data constraints. Data constraints on a column are the limits put on the values the data can have. There are four types of data constraints: (1) domain constraints, which define a limited set of values for the column, (2) range constraints, which specify that the values must fall within a certain range, (3) intrarelation constraints, which define what values the column can have based on values of other columns in the same table, and (4) interrelation constraints, which define values the column can have based on values of columns in other tables. 26. What is a cascading update? Referential integrity constraints require that foreign key values in one table correspond to primary key values in another. If the value of the primary key is changed -- that is, updated -the value of the foreign key must immediately be changed to match it. Cascading updates will set this change to be done automatically by the DBMS whenever necessary. 27. What is a SQL view? Briefly explain the use of views. A SQL view is a virtual table built from other tables or views. Views are used to (1) hide columns or rows, (2) show the results of computed columns, (3) hide complicated SQL syntax, (4) layer built-in functions, (5) provide a level of indirection between application programs and tables, (6) assign different sets of processing permissions to tables, and (7) to assign different sets of triggers to the same table. 28. Name four applications for triggers. (1) providing default values, (2) enforcing data constraints, (3) updating views and (4) enforcing referential integrity 29. What are stored procedures, and how do they differ from triggers? A stored procedure is a program that is stored within the database and is compiled when used. They can receive input parameters and they can return results. Unlike triggers, their scope is database-wide; they can be used by any process that has permission to use the database stored procedure. 30. What are the advantages of using stored procedures? The advantages of stored procedures are (1) greater security, (2) decreased network traffic, (3) the fact that SQL can be optimized and (4) code sharing which leads to less work, standardized processing, and specialization among developers. 31. Explain how to add a NOT NULL column to a table. First, add the column as NULL. Then use UPDATE to add data to every row. Finally use an ALTER TABLE . . . ALTER COLUMN statement to change the column constraint to NOT NULL. 32. Explain the difference between an exclusive lock and a shared lock. An exclusive lock prohibits other users from reading the locked resource; a shared lock allows other users to read the locked resource, but they cannot update it. 33. What is deadlock? How can it be avoided? How can it be resolved once it occurs? Deadlock occurs when two transactions are each waiting on a resource that the other transaction holds. Deadlock can be prevented by requiring transactions to acquire all locks at the same time; once it occurs, the only way to cure it is to abort one of the transactions and back out of partially completed work.
34. Explain what we mean by an ACID transaction. An ACID transaction is one that is atomic, consistent, isolated, and durable. Durable means that database changes are permanent. Consistency can mean either statement level or transaction level consistency. With transaction level consistency, a transaction may not see its own changes. There are four transaction isolation levels: read committed, read uncommitted, repeatable read and serialization. Atomic means it is performed as a unit. 35. What are the major functions of the database administrator? Managing database structure, controlling concurrent processing, managing processing rights and responsibilities, developing database security, providing for database recovery, managing the DBMS and maintaining the data repository 36. What are the three types of data sources used with ODBC? An ODBC file data source is a file that can be shared among database users. A ODBC system data source is one that is local to a single computer. A ODBC user data source is only available to the user who created it. 37. What disadvantage of ODBC does OLE DB overcome? By breaking the features and the functions of a DBMS into COM objects, OLE DB characteristic overcomes a major disadvantage of ODBC. With ODBC, a vendor must create an ODBC driver for almost all DBMS features and functions in order to participate in ODBC at all. This is a large task that requires a substantial initial investment. With OLE DB, however, a DBMS vendor can implement portions of their product. 38. What is ADO.NET? ADO.NET is a new, improved, and greatly expanded version of ADO that was developed for the Microsoft .NET initiative. ADO.NET incorporates all of the functionality of ADO, but adds much more. In particular, ADO.NET facilitates the transformation of XML documents to and from database data. Most importantly, ADO.NET introduces the concept of datasets, which are inmemory, full-function, independent databases. 39. What is a dataset? A dataset is an in-memory database that is disconnected from any regular database, but has all the important characteristics of a regular database. Datasets can have multiple tables, relationships, referential integrity rules, referential integrity actions, views and the equivalent of triggers. Datasets are needed to provide a standardized, non-proprietary means to process database views. They are especially important for the processing of views with multiple multivalued paths. 40. What is the coding pattern for using a JDBC driver? 1. Load the driver. 2. Establish a connection to the database. 3. Create a statement. 4. Do something with the statement 41. Explain the differences between structured data and unstructured data. Structured data are facts concerning objects and events. The most important structured data are numeric, character, and dates. Structured data are stored in tabular form. Unstructured data are multimedia data such as documents, photographs, maps, images, sound, and video clips. Unstructured data are most commonly found on Web servers and Web-enabled databases. 42. Explain the differences between an intranet and an extranet. An Internet database is accessible by everyone who has access to a Web site. An intranet database limits access to only people within a given organization. An extranet database limits access to only people within a company and a company's customers and suppliers. 43. Explain the systems development life cycle.
This is the traditional method to develop, maintain, and replace information systems that includes the project identification and selection, project initiation and planning, analysis, logical design, physical design, implementation, and maintenance steps. The process is a series of steps that are ideally completed in a linear fashion. In reality, the process is not linear and the process requires steps to be revisited and an overlap of steps 44. Briefly describe the six database activities that occur during the systems development life cycle. The enterprise modeling that analyzes the current data processing. Conceptual data modeling that identifies entities, relationships, and attributes. The logical database design that identifies data integrity and security requirements. The physical database design and definition that defines the database to a DBMS. The database implementation that installs and converts data from prior systems. Database maintenance that fixes errors in the database and database applications. 45. Explain some of the main goals of normalization. Normalization should minimize data redundancy. It should also simplify referential integrity constraints. Normalization will also make it easier to insert, update, and delete data. And finally, it provides better design. 46. List some of the properties of a relation. Relations in a database have a unique name and no multivalued attributes exist. Each row is unique and each attribute within a relation has a unique name. The sequence of both columns and rows is irrelevant. 47. What is denormalization and why would someone consider doing so? Denormalization is the process of taking normalized relations and changing them so that they are not longer normalized. This process may lead to anomalies and create data redundancy as negative consequences. However, the revised relations should improve database performance. 48. Briefly describe the three types of SQL commands. Data definition language commands are used to create, alter, and drop tables. Data manipulation commands are used to insert, modify, update, and query data in the database. Data control language commands help the DBA to control the database. 49. What are the steps to follow when preparing to create a table? 1. Identify the data type, length, and precision for each attribute. 2. Identify the columns that can accept a null value. 3. Identify the columns that need to be unique. 4. Identify primary and related foreign keys with the parent table being created before the child. 5. Determine default values. 6. Determine where the domain values are that need to be constrained. 7. Create the indexes. 50. Explain a join between tables A join allows tables to be linked to other tables when a relationship between the tables exists. The relationships are established by using a common column in the tables and often uses the primary/foreign key relationship. 51. Describe and contrast a trigger and a procedure. Triggers are stored and controlled in the DBMS. A trigger is executed automatically when a condition is met (INSERT, UPDATE, or DELETE). A procedure is also stored in a database. A procedure is not executed automatically. 52. Briefly describe an outer join. An outer join includes the records that match and those that do not have a matching value in another table. Outer joins can be a LEFT outer join (includes all records from the first table listed) or a RIGHT outer join (includes all records from the second table listed). Outer joins are not easily used with more than two tables. 53. Describe a subquery.
A subquery is a query that is composed of two queries. The first query (inner query) is within the WHERE clause of the other query (outer query). In some cases the inner query provides results for the outer query to process. In other cases, the outer query results provide results for the inner query (correlated subquery). 54. Compare a thin and a fat client. A fat client is a PC that is responsible where most processing occurs on the client rather than the server. Some of the fat client activities include processing, presentation logic, and business rules logic. A thin client is a PC where only limited processing occurs. In these cases, more processing should occur on the application server. 55. Describe some reasons that someone familiar with Microsoft Access will want to learn VBA. You can perform more complex functions and error handling can be accommodated by VBA. VBA code will execute faster since code runs faster than macros and maintenance is easier because VBA modules are stored with the forms and reports. Reading VBA is easier because you can see the entire code. Finally, you can pass parameters and use OLE automation better. 56. Describe JavaScript and VBScript. JavaScript shares many features with Java. Developers use it to achieve interactivity. JavaScript is an open language and does not require a license. It is supported by both Internet Explorer and Netscape. VBScript is similar to JavaScript. It is based on Visual Basic but is simpler. Microsoft developed this language. 57. Describe Web Services. Web Services are improving the ability of computers to communicate over the Internet. These services use XML programs and usually run in the background. Easier integration of applications may be possible because developers do not need to be familiar with the technical details with applications that are being integrated. UDDI is a technical specification for creating a distributed registry of Web services and businesses that are open to communicating through Web services. 58. Describe concurrency control. Concurrency control is the process managing simultaneous operations against a database so that database integrity is not compromised. There are two approaches to concurrency control. The pessimistic approach involves locking and the optimistic approach involves versioning. 59. What is RDBMS? Relational Data Base Management Systems (RDBMS) are database management systems that maintain data records and indices in tables. Relationships may be created and maintained across and among the data and tables. In a relational database, relationships between data items are expressed by means of tables. Interdependencies among these tables are expressed by data values rather than by pointers. This allows a high degree of data independence. An RDBMS has the capability to recombine the data items from different files, providing powerful tools for data usage. What are the properties of the Relational tables? Relational tables have six properties: 1. 2. 3. 4. 5. 6.
Values are atomic. Column values are of the same kind. Each row is unique. The sequence of columns is insignificant. The sequence of rows is insignificant. Each column must have a unique name.
7. What is Normalization? Database normalization is a data design and organization process applied to data structures based on rules that help building relational databases. In relational database design, the process of organizing data to minimize redundancy is called normalization. Normalization usually involves dividing a database into two or more tables and defining relationships between the tables. The objective is to isolate data so that additions, deletions, and modifications of a field can be made in just one table and then propagated through the rest of the database via the defined relationships. 8. 4. What is De-normalization? De-normalization is the process of attempting to optimize the performance of a database by adding redundant data. It is sometimes necessary because current DBMSs implement the relational model poorly. A true relational DBMS would allow for a fully normalized database at the logical level, while providing physical storage of data that is tuned for high performance. De-normalization is a technique to move from higher to lower normal forms of database modeling in order to speed up database access. What are different normalization forms? 1. 1NF: Eliminate Repeating Groups Make a separate table for each set of related attributes, and give each table a primary key. Each field contains at most one value from its attribute domain. 2. 2NF: Eliminate Redundant Data If an attribute depends on only part of a multi-valued key, remove it to a separate table. 3. 3NF: Eliminate Columns Not Dependent On Key If attributes do not contribute to a description of the key, remove them to a separate table. All attributes must be directly dependent on the primary key. 4. BCNF: Boyce-Codd Normal Form If there are non-trivial dependencies between candidate key attributes, separate them out into distinct tables. 5. 4NF: Isolate Independent Multiple Relationships No table may contain two or more 1:n or n:m relationships that are not directly related. 6. 5NF: Isolate Semantically Related Multiple Relationships There may be practical constrains on information that justify separating logically related many-to-many relationships. 7. ONF: Optimal Normal Form A model limited to only simple (elemental) facts, as expressed in Object Role Model notation. 8. DKNF: Domain-Key Normal Form A model free from all modification anomalies is said to be in DKNF. 9. What is Stored Procedure? A stored procedure is a named group of SQL statements that have been previously created and stored in the server database. Stored procedures accept input parameters so that a single procedure can be used over the network by several clients using different input data. And when the procedure is modified, all clients automatically get the new version. Stored procedures reduce network traffic and improve performance. Stored procedures can be used to help ensure the integrity of the database. e.g. sp_helpdb, sp_renamedb, sp_depends etc. 10. What is Trigger? A trigger is a SQL procedure that initiates an action when an event (INSERT, DELETE or UPDATE) occurs. Triggers are stored in and managed by the DBMS. Triggers are used to maintain the referential integrity of data by changing the data in a systematic fashion. A trigger cannot be called or executed; DBMS automatically fires the trigger as a result of a data
modification to the associated table. Triggers can be viewed as similar to stored procedures in that both consist of procedural logic that is stored at the database level. Stored procedures, however, are not event-drive and are not attached to a specific table as triggers are. Stored procedures are explicitly executed by invoking a CALL to the procedure while triggers are implicitly executed. In addition, triggers can also execute stored procedures. 11. What is View? A simple view can be thought of as a subset of a table. It can be used for retrieving data, as well as updating or deleting rows. Rows updated or deleted in the view are updated or deleted in the table the view was created with. It should also be noted that as data in the original table changes, so does data in the view, as views are the way to look at part of the original table. The results of using a view are not permanently stored in the database. The data accessed through a view is actually constructed using standard T-SQL select command and can come from one to many different base tables or even other views. What is Index? An index is a physical structure containing pointers to the data. Indices are created in an existing table to locate rows more quickly and efficiently. It is possible to create an index on one or more columns of a table, and each index is given a name. The users cannot see the indexes; they are just used to speed up queries. Effective indexes are one of the best ways to improve performance in a database application. A table scan happens when there is no index available to help a query. In a table scan SQL Server examines every row in the table to satisfy the query results. Table scans are sometimes unavoidable, but on large tables, scans have a terrific impact on performance. 11. What is a Linked Server? Linked Servers is a concept in SQL Server by which we can add other SQL Server to a Group and query both the SQL Server dbs using T-SQL Statements. With a linked server, you can create very clean, easy to follow, SQL statements that allow remote data to be retrieved, joined and combined with local data. Stored Procedure sp_addlinkedserver, sp_addlinkedsrvlogin will be used add new Linked Server. 12. What is Cursor? Cursor is a database object used by applications to manipulate data in a set on a row-by- row basis, instead of the typical SQL commands that operate on all the rows in the set at one time. In order to work with a cursor we need to perform some steps in the following order: 1. 2. 3. 4. 5. 6.
Declare cursor Open cursor Fetch row from the cursor Process fetched row Close cursor Deallocate cursor
What is Difference between Function and Stored Procedure? UDF can be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section where as
Stored procedures cannot be. UDFs that return tables can be treated as another rowset. This can be used in JOINs with other tables. Inline UDF's can be thought of as views that take parameters and can be used in JOINs and other Rowset operations.
What are different Types of Join? 1. Cross Join A cross join that does not have a WHERE clause produces the Cartesian product of the tables involved in the join. The size of a Cartesian product result set is the number of rows in the first table multiplied by the number of rows in the second table. The common example is when company wants to combine each product with a pricing table to analyze each product at each price. 2. Inner Join A join that displays only the rows that have a match in both joined tables is known as inner Join. This is the default type of join in the Query and View Designer. 3. Outer Join A join that includes rows even if they do not have related rows in the joined table is an Outer Join. You can create three different outer join to specify the unmatched rows to be included: 1. Left Outer Join: In Left Outer Join all rows in the first-named table i.e. "left" table, which appears leftmost in the JOIN clause are included. Unmatched rows in the right table do not appear. 2. Right Outer Join: In Right Outer Join all rows in the second-named table i.e. "right" table, which appears rightmost in the JOIN clause are included. Unmatched rows in the left table are not included. 3. Full Outer Join: In Full Outer Join all rows in all joined tables are included, whether they are matched or not. 4. Self Join This is a particular case when one table joins to itself, with one or two aliases to avoid confusion. A self join can be of any type, as long as the joined tables are the same. A self join is rather unique in that it involves a relationship with only one table. The common example is when company has a hierarchal reporting structure whereby one member of staff reports to another. Self Join can be Outer Join or Inner Join.
What are primary keys and foreign keys? Primary keys are the unique identifiers for each row. They must contain unique values and cannot be null. Due to their importance in relational databases, Primary keys are the most fundamental of all keys and constraints. A table can have only one Primary key. Foreign keys are both a method of ensuring data integrity and a manifestation of the relationship between tables.
What is Identity? Identity (or AutoNumber) is a column that automatically generates numeric values. A start and increment value can be set, but most DBA leave these at 1. A GUID column also generates numbers; the value of this cannot be controlled. Identity/GUID columns do not need to be indexed. Which TCP/IP port does SQL Server run on? How can it be changed? SQL Server runs on port 1433. It can be changed from the Network Utility TCP/IP properties What are the difference between clustered and a non-clustered index? 1. A clustered index is a special type of index that reorders the way records in the table are physically stored. Therefore table can have only one clustered index. The leaf nodes of a clustered index contain the data pages. 2. A non clustered index is a special type of index in which the logical order of the index does not match the physical stored order of the rows on disk. The leaf node of a non clustered index does not consist of the data pages. Instead, the leaf nodes contain index rows. What are the different index configurations a table can have? A table can have one of the following index configurations: 1. 2. 3. 4. 5.
No indexes A clustered index A clustered index and many nonclustered indexes A nonclustered index Many nonclustered indexes
What's the difference between a primary key and a unique key? 6. Both primary key and unique key enforces uniqueness of the column on which they are defined. But by default primary key creates a clustered index on the column, where are unique creates a nonclustered index by default. Another major difference is that, primary key doesn't allow NULLs, but unique key allows one NULL only. What is difference between DELETE and TRUNCATE commands? Delete command removes the rows from a table based on the condition that we provide with a WHERE clause. Truncate will actually remove all the rows from a table and there will be no data in the table after we run the truncate command. 1. TRUNCATE: 1. TRUNCATE is faster and uses fewer system and transaction log resources than DELETE. 2. TRUNCATE removes the data by deallocating the data pages used to store the table's data, and only the page deallocations are recorded in the transaction log.
3. TRUNCATE removes all rows from a table, but the table structure, its columns, constraints, indexes and so on, remains. The counter used by an identity for new rows is reset to the seed for the column. 4. You cannot use TRUNCATE TABLE on a table referenced by a FOREIGN KEY constraint. Because TRUNCATE TABLE is not logged, it cannot activate a trigger. 5. TRUNCATE cannot be rolled back. 6. TRUNCATE is DDL Command. 7. TRUNCATE Resets identity of the table 2. DELETE: 1. DELETE removes rows one at a time and records an entry in the transaction log for each deleted row. 2. If you want to retain the identity counter, use DELETE instead. If you want to remove table definition and its data, use the DROP TABLE statement. 3. DELETE Can be used with or without a WHERE clause 4. DELETE Activates Triggers. 5. DELETE can be rolled back. 6. DELETE is DML Command. 7. DELETE does not reset identity of the table. Note: DELETE and TRUNCATE both can be rolled back when surrounded by TRANSACTION if the current session is not closed. If TRUNCATE is written in Query Editor surrounded by TRANSACTION and if session is closed, it can not be rolled back but DELETE can be rolled back. What is the difference between a HAVING CLAUSE and a WHERE CLAUSE? They specify a search condition for a group or an aggregate. But the difference is that HAVING can be used only with the SELECT statement. HAVING is typically used in a GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE clause. Having Clause is basically used only with the GROUP BY function in a query whereas WHERE Clause is applied to each row before they are part of the GROUP BY function in a query. What are the properties and different Types of Sub-Queries? 1. Properties of Sub-Query 1. A sub-query must be enclosed in the parenthesis. 2. A sub-query must be put in the right hand of the comparison operator, and 3. A sub-query cannot contain an ORDER-BY clause. 4. A query can contain more than one sub-query. 2. Types of Sub-Query 1. Single-row sub-query, where the sub-query returns only one row. 2. Multiple-row sub-query, where the sub-query returns multiple rows,. and 3. Multiple column sub-query, where the sub-query returns multiple columns
3. What are the authentication modes in SQL Server? How can it be changed? 4. Windows mode and Mixed Mode - SQL and Windows. To change authentication mode in SQL Server click Start, Programs, Microsoft SQL Server and click SQL Enterprise Manager to run SQL Enterprise Manager from the Microsoft SQL Server program group. Select the server then
from the Tools menu select SQL Server Configuration Properties, and choose the Security page.
Name 3 ways to get an accurate count of the number of records in a table?
SELECT * FROM table1 SELECT COUNT(*) FROM table1 SELECT rows FROM sysindexes WHERE id = OBJECT_ID(table1) AND indid < 2
What is PRIMARY KEY? A PRIMARY KEY constraint is a unique identifier for a row within a database table. Every table should have a primary key constraint to uniquely identify each row and only one primary key constraint can be created for each table. The primary key constraints are used to enforce entity integrity. 22. What is UNIQUE KEY constraint? A UNIQUE constraint enforces the uniqueness of the values in a set of columns, so no duplicate values are entered. The unique key constraints are used to enforce entity integrity as the primary key constraints. 23. What is FOREIGN KEY? A FOREIGN KEY constraint prevents any actions that would destroy links between tables with the corresponding data values. A foreign key in one table points to a primary key in another table. Foreign keys prevent actions that would leave rows with foreign key values when there are no primary keys with that value. The foreign key constraints are used to enforce referential integrity. 24. What is CHECK Constraint? A CHECK constraint is used to limit the values that can be placed in a column. The check constraints are used to enforce domain integrity. What is NOT NULL Constraint? A NOT NULL constraint enforces that the column will not accept null values. The not null constraints are used to enforce domain integrity, as the check constraints. t are the advantages of using Stored Procedures? 1. Stored procedure can reduced network traffic and latency, boosting application performance.
2. Stored procedure execution plans can be reused, staying cached in SQL Server's memory, reducing server overhead. 3. Stored procedures help promote code reuse. 4. Stored procedures can encapsulate logic. You can change stored procedure code without affecting clients. 5. Stored procedures provide better security to your data.
How to implement one-to-one, one-to-many and many-to-many relationships while designing tables? One-to-One relationship can be implemented as a single table and rarely as two tables with primary and foreign key relationships. One-to-Many relationships are implemented by splitting the data into two tables with primary key and foreign key relationships. Many-to-Many relationships are implemented using a junction table with the keys from both the tables forming the composite primary key of the junction table.
1.
To
fetch
ALTERNATE
records
from
a
table.
(EVEN
NUMBERED)
select * from emp where rowid in (select decode(mod(rownum,2),0,rowid, null) from emp); 2.
To
select
ALTERNATE
records
from
a
table.
(ODD
NUMBERED)
select * from emp where rowid in (select decode(mod(rownum,2),0,null ,rowid) from emp); 3.
Find
the
3rd
MAX
salary
in
the
emp
table.
select distinct sal from emp e1 where 3 = (select count(distinct sal) from emp e2 where e1.sal <= e2.sal); 4.
Find
the
3rd
MIN
salary
in
the
emp
table.
select distinct sal from emp e1 where 3 = (select count(distinct sal) from emp e2where e1.sal >= e2.sal); 5.
Select
FIRST
n
records
from
a
table.
records
from
a
table
select * from emp where rownum <= &n; 6.
Select
LAST
n
select * from emp minus select * from emp where rownum <= (select count(*) - &n from emp); 7.
List dept no., Dept name for all the departments in which there are no employees in the department. select
*
from
dept
where
deptno
not
in
(select
deptno
from
emp);
alternate solution: select * from dept a where not exists (select * from emp b where a.deptno = b.deptno); altertnate solution: select empno,ename,b.deptno,dname from emp a, dept b where a.deptno(+) = b.deptno and empno is null; 8.
How
to
get
3
Max
salaries
?
select distinct sal from emp a where 3 >= (select count(distinct sal) from emp b where a.sal <= b.sal) order by a.sal desc; 9.
How
to
get
3
Min
salaries
?
select distinct sal from emp a where 3 >= (select count(distinct sal) from emp b where a.sal >= b.sal); 10. How
to
get
nth
max
salaries
?
select distinct hiredate from emp a where &n = (select count(distinct sal) from emp b where a.sal >= b.sal); 11. Select
DISTINCT
RECORDS
from
emp
table.
select * from emp a where rowid = (select max(rowid) from emp b where a.empno=b.empno); 12. How
to
delete
duplicate
rows
in
a
table?
delete from emp a where rowid != (select max(rowid) from emp b where a.empno=b.empno); 13. Count
of
number
of
employees
select count(EMPNO), b.deptno, dname from emp a, dept b
in
department
wise.
where a.deptno(+)=b.deptno group by
b.deptno,dname; 14. Suppose there is annual salary information provided by emp table. How to fetch monthly sal ary of each and every employee? select ename,sal/12 as monthlysal from emp; 15. Select all record from emp table where deptno =10 or 4 0. select * from emp where deptno=30 or deptno=10; 16. Select all record from emp table where deptno=30 and sal>1500. select * from emp where deptno=30 and sal>1500; 17. Select all record from emp where job not in SALESMAN or CLERK. select * from emp where job not in ('SALESMAN','CLERK'); 18. Select all record from emp where ename in 'BLAKE',' SCOTT','KING'and'FORD'. select * from emp where ename in('JONES','BLAKE','SCOTT','KING','FORD');
19.
Select all records where ename starts with ‘S’ and its lenth is 6 char.
select * from emp where ename like'S____'; character but it should end with ‘R’.
20. Select all records where ename may be any no of select * from emp where ename like'%R'; 21. Count MGR and their salary in emp table. select count(MGR),count(sal) from emp; 22. In emp table add comm+sal as total sal . select ename,(sal+nvl(comm,0)) as totalsal from emp; 23. Select any salary <3000 from emp table.
select * from emp where sal> any(select sal from emp where sal<3000); 24. Select all salary <3000 from emp table. select * from emp where sal> all(select sal from emp where sal<3000); 25. Select all the employee group by deptno and sal in descending order. select ename,deptno,sal from emp order by deptno,sal desc; 26. How can I create an empty table emp1 with same structure as emp? Create table emp1 as select * from emp where 1=2; 27. How
to
retrive
record
where
sal
between
1000
to
2000?
Select * from emp where sal>=1000 And sal<2000 28. Select
all
records
where
dept
no
of
both
emp
and
dept
table
matches.
select * from emp where exists(select * from dept where emp.deptno=dept.deptno) 29. If there are two tables emp1 and emp2, and both have common record. How can I fetch all the recods but
common
(Select * from emp) Union (Select * from emp1)
records
only
once?
30. How
to
fetch
only
common
records
from
two
tables
emp
and
emp1?
(Select * from emp) Intersect (Select * from emp1) 31. How
can
I
retrive
all
records
of
emp1
those
should
not
present
in
emp2?
employees
exist.
(Select * from emp) Minus (Select * from emp1) 32. Count SELECT
the
totalsa
deptno deptno,
wise
where sum(sal)
FROM GROUP HAVING COUNT(empno) > 2
more
than
2 As
totalsal emp
BY
deptno