Babu's Study Deck Flashcards

getting a developer job

1
Q

What is a RDBMS?

A

Database management systems that maintain data records and indices in tables. A program that allows you to Create, Read, Update, and Delete a relational database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the properties of the relational tables?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is normalization?

A

The process of organizing data to minimize redundancy. It 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is de-normalization?

A

The process of attempting to optimize the performance of a database by adding redundant data. It is a technique to move from higher to lower normal forms of database modeling in order to speed up database access. 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. It eliminates redundant data (storing the same data in more than one table) and it ensures data dependencies make sense.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How is ACID property related to database?

A

ACID properties help to maintain consistency in a database, before and after a transaction. The ACID properties, in totality, provide a mechanism to ensure correctness and consistency of a database in a way such that each transaction is a group of operations that acts as a single unit, produces consistent results, acts in isolation from other operations and updates that it makes are durably stored.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the “A” in ACID?

A

Atomicity the entire transaction takes place at once or doesn’t happen at all. It involves two operations (1) Abort: if a transaction aborts, changes made to database are not visible (2) Commit: if a transaction commits, changes made are visible. Atomicity is as known as the ‘All or nothing rule’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the “C” in ACID?

A

Consistency integrity constraints must be maintained so that the database is consistent before and after the transaction. It refers to correctness of a database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the “I” in ACID?

A

Isolation ensures that multiple transactions can occur concurrently without leading to inconsistency of database state. Transactions occur independently without interference. Transactions occur independently without interference. Changes occurring in a particular transaction will not be visible to any other transaction until that particular change in that transaction is written to memory or has been committed. This property ensures that the execution of transactions concurrently will result in a state that is equivalent to a state achieved if these were executed serially in some order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the “D” in ACID?

A

Durability ensures that once the transaction has completed execution, the updates and modifications to the database are stored in and written to disk and they persist even if system failure occurs. These updates now become permanent and are stored in a non-volatile memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the different normalization forms?

A
  • 1NF: Eliminate Repeating Groups
  • 2NF: Eliminate Redundant Data
  • 3NF: Eliminate Columns Not Dependent On Key
  • BCNF: Boyce-Codd Normal Form
  • 4NF: Isolate Independent Multiple Relationships
  • 5NF: Isolate Semantically Related Multiple Relationships
  • ONF: Optimal Normal Form
  • DKNF: Domain-Key Normal Form
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is 1NF?

A

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.

  1. It should only have single (atomic) valued attributes/columns
  2. Values stored in a column should be of the same domain
  3. All columns in a table should have unique names
  4. The order in which data is stored does not matter
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is 2NF?

A

Eliminate redundant data. If an attribute depends on only part of a multi-valued key, then remove it to a separate table. For a table to be in the Second Normal Form:

  1. It should be in the First Normal Form
  2. It should not have Partial Dependency
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is 3NF?

A

Eliminate columns not dependent on key. If attributes do not contribute to a description of the key, then remove them to a separate table. All attributes must be directly dependent on the primary key. For a database to be in 3NF, it must first fulfill all the criteria of a 2NF and 1NF database. A table is in Third Normal Form when:

  1. It is in Second Normal Form
  2. It does not have Transitive Dependency
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is BCNF?

A

Boyce-Codd Normal Form is a higher version of the Third Normal Form and deals with certain type of anomaly that is not handled by 3NF. If there are non-trivial dependencies between candidate key attributes, then separate them out into distinct tables. A 3NF table which does not have multiple overlapping candidate keys is said to be in BCNF.

  1. R must be in 3rd Normal Form
  2. Each functional dependency (X → Y), X should be a super key
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is 4NF?

A

Isolate independent multiple relationships. No table may contain two or more 1:n or n:m relationships that are not directly related.

  1. It is in the Boyce-Codd Normal Form
  2. It doesn’t have Multi-valued Dependency
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is 5NF?

A

Isolate semantically related multiple relationships. There may be practical constrains on information that justify separating logically related many-to-many relationships.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is ONF?

A

Optimal Normal Form. A model limited to only simple (elemental) facts, as expressed in Object Role Model notation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is DKNF?

A

Domain-key Normal Form. A model free from all modification anomalies is said to be in DKNF.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is a stored procedure?

A

A named group of SQL statements that have been previously created and stored in the server database. They reduce network traffic and improve performance and can be used to help ensure the integrity of the database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is a trigger?

A

A SQL procedure that initiates an action when an event (INSERT, DELETE, or UPDATE) occurs. They 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. It cannot be called or executed. You can have nested triggers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What are the different types of triggers?

A

1) DML Trigger
a) Instead of Triggers are fired in place of the triggering action such as an insert, update, or delete
b) After Triggers execute following the triggering action, such as an insert, update, or delete
2) DDL Trigger is fired against Drop Table, Create Table, Alter Table, or Login events and are always after triggers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is a view?

A

A virtual table. It’s like a subset of a table and 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. Views do not exist in the database unless you add an index.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is an index?

A

A physical structure containing pointers to the data. Indices are created in an existing table to locate rows more quickly and efficiently. Indexes are used to speed up queries.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is a linked server?

A

Is when you add other SQL Server to a Group and query both the SQL Server databases 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What is a cursor?

A
It is a loop that allows you to do row by row processing. You should avoid using a cursor because it kills performance. The following order must be followed:
•	Declare cursor
•	Fetch row from the cursor
•	Process fetched row
•	Close cursor
•	Deallocate cursor
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What is collation?

A

Specifies how data is sorted and compared in a database. It provides the sorting rules, case, and accent sensitivity properties for the data in the database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

What is the difference between a Function and a Stored Procedure?

A
  • Function must return a value but in Stored Procedures it is optional (Procedure can return zero or n values)
  • Functions can have only input parameters for it whereas Procedures can have input/output parameters
  • Functions can be called from Procedures whereas Procedures cannot be called from Function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What is a subquery?

A

It is a SELECT statement that is nested within another T-SQL statement. A subquery can be used anywhere an expression can be used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Explain the properties of a subquery.

A
  • Must be enclosed in the parenthesis
  • Must be put in the right hand of the comparison operator
  • Cannot contain an ORDER BY clause
  • Can contain more than one subquery
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What are the different types of JOINS?

A
  • Cross JOIN
  • Inner JOIN
  • Outer JOIN
  • Self-JOIN
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

What is a 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

What is an Inner JOIN?

A

Displays only the rows that have a match in both joined tables and is the default type of JOIN in the Query and View Designer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

What is an Outer JOIN?

A

It includes rows even if they do not have related rows in the joined table. There are three types of Outer JOINS:
• Left Outer JOIN all the rows in the first-named table which appears leftmost in the JOIN clause, are included. Unmatched rows in the right table do not appear.
• Right Outer JOIN all the rows in the second-named table which appears rightmost in the JOIN clause are included. Unmatched rows in the left table are not included.
• Full Outer JOIN all the rows in all joined tables are included, whether they are matched or not.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What is a Self-JOIN?

A

When one table joins to itself with one or two aliases to avoid confusion. Can be of any type, as long as the joined tables are the same. It is unique in that it involves a relationship with only one table. It can also be an Outer JOIN or an Inner JOIN.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

What are Primary Keys and Foreign Keys?

A

Primary keys are the unique identifiers for each row and must contain unique values which cannot be null. A table can have only one Primary key. Foreign keys are a method of ensuring data integrity and manifestation of the relationship between tables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

What is User-defined Functions?

A

Allow defining its own T-SQL functions that can accept zero or more parameters and return a single scalar data value or a table data type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

What are the types of User-defined Functions that can be created?

A
  • Scalar User-defined Function returns one of the scalar data types. Data types not supported are: text, ntext, image, and timestamp
  • Inline Table-value User-defined Function returns a table data type and is an exceptional alternative to a view as the user-defined function can pass parameters into a T-SQL SELECT command and in essence provide us with a parameterized, non-updateable view of the underlying tables.
  • Multi-statement Table-value User-defined Function returns a table, and it is also an exceptional alternative to a view as the function can support multiple T-SQL statements to build the final result where the view is limited to a single SELECT statement.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

What is an identity?

A

A special type of column that is used to automatically generate key values based on a provided seed (starting point) and increment.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

What is data-warehousing?

A
  • The data in the database is organized so that all the data elements relating to the same real-world event or object are linked together
  • Changes to the data in the database are tracked and recorded so that reports can be produced showing changes over time (time-variant)
  • Non-volatile – the database is never over-written or deleted, once committed, the data is static, read-only, but retained for future reporting
  • Integrated – the database contains data from most or all of an organization’s operational applications, and that this data is made consistent
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

What languages does BI use to achieve the goal?

A
  • MDX – Multidimensional Expressions retrieves data from SSAS cubes
  • DMX – Data Mining Extensions used for data mining structures.
  • XMLA – XML for Analysis commonly used in administration tasks such as backup or restore database, copy and move database, or for learning Meta data information.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

What is a Standby Server?

A

It is a computer that is located in close proximity to the production server(s) and can be used to temporarily replace a production server if it experiences a hardware failure. It can also be used to verify that you can recover databases from their full backups.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

Explain Hot Standby Server.

A

A redundant method in which one system runs simultaneously with an identical primary system. Upon failure of the primary system, the hot standby system immediately takes over, replacing the primary system. The data is mirrored in real time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

Explain Warm Standby Server.

A

A method of redundancy in which the secondary (i.e., backup) system runs in the background of the primary system. Data is mirrored to the secondary server at regular intervals, which means that there are times when both servers do not contain the exact same data.

44
Q

Explain Cold Standby Server.

A

A method of redundancy in which the secondary (i.e., backup) system is only called upon when the primary system fails. The system on cold standby receives scheduled data backups, but less frequently than a warm standby. Cold standby systems are used for non-critical applications or in cases where data is changed infrequently. Has to be turned on manually and physically replaces the previous server.

45
Q

What is a dirty read?

A

Is as known as uncommitted dependency, and it occurs when a transaction is allowed to read data from a row that has been modified by another running transaction and not yet committed.

46
Q

Why can’t I use Outer JOIN in an indexed view?

A

Rows can logically disappear from an indexed view based on Outer JOIN when you insert data into a base table. This makes incrementally updating Outer JOIN views relatively complex to implement, and the performance of the implementation would be slower than for views based on standard (INNER) JOIN.

47
Q

What is the correct order of the logical query processing phases?

A
  1. FROM
  2. ON
  3. OUTER
  4. WHERE
  5. GROUP BY
  6. CUBE | ROLLUP
  7. HAVING
  8. SELECT
  9. DISTINCT
  10. TOP
  11. ODER BY
48
Q

Which TCP/IP port does the SQL server run on?

A

port 1433

49
Q

How can the TCP/IP port be changed?

A

It can be changed from the Network Utility TCP/IP properties – Port number, both on client and the server.

50
Q

What is the difference between a clustered and a non-clustered index?

A

A clustered index describes the order in which records are physically stored on the disk, and a table can only have one clustered index. It is essentially a sorted copy of the data in the indexed columns. A non-clustered index defines a logical order that does not match the physical order on disk. The leaf node of a non-clustered index does not consist of the data pages. The leaf nodes contain index rows.

51
Q

What are the different index configurations a table can have?

A
  • No indexes
  • A clustered index
  • A clustered index and many non-clustered indexes
  • A non-clustered index
  • Many non-clustered indexes
52
Q

What are the different types of collation sensitivity?

A
  • Case Sensitivity: A and a, B and b, etc.
  • Accent Sensitivity: a and á, o and ó, etc.
  • Kana Sensitivity: When Japanese Kana characters. Hiragana and Katakana are treated differently, it is called Kana sensitive.
  • Width Sensitivity: A single-byte character (half-width) and the same character represented as a double-byte character (full-width) are treated differently, it is width sensitive.
53
Q

What is OLTP (Online Transaction Processing)?

A

A category of data processing that is focused on transaction-oriented tasks. It typically involves inserting, updating, and/or deleting small amounts of data in a database. It also mainly deals with large numbers of transactions by a large number of users. Ensures data integrity.

54
Q

What is the difference between a primary key and a unique key?

A

The primary key creates a clustered index on the column (used to identify a row (record) in a table. A unique key prevents duplicate values in a column and allows one Null and creates a non-clustered index by default.

55
Q

What is the difference between DELETE and TRUNCATE commands?

A

DELETE removes the rows from a table on the basis of 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 running the command.

56
Q

What are the different types of locks?

A
  • Shared Locks: Read-only operations such as a SELECT statement
  • Update Locks:
  • Exclusive Locks
  • Intent Locks
  • Schema Locks
  • Bulk Update Locks
57
Q

What are pessimistic lock and optimistic lock?

A

Optimistic Locking: A strategy where you read a record, take note of a version number and check that the version hasn’t changed before you write the record back. If the record is dirty, abort the transaction and the user can re-start it.
Pessimistic Locking: The record is locked for exclusive use until you have finished with it. It has much better integrity than optimistic locking but requires you to be careful with your application design to avoid Deadlocks.

58
Q

When is the use of UPDATE_STATISTICS command?

A

The command is used when a large amount of data is processed. If a large amount of deletions, modifications or Bulk Copy into the tables has occurred, it has to update the indexes to take these changes into account. UPDATE_STATISTICS updates the indexes on these tables accordingly.

59
Q

What is the difference between a HAVING clause and a WHERE clause?

A

The HAVING clause can be used only with SELECT statement and is typically used in a GROUP BY clause. It behaves like a WHERE clause when GROUP BY is not used. Basically, the HAVING clause is used only with the GROUP BY function in a query.

The WHERE clause is applied to each row before they are part of the GROUP BY function in a query.

60
Q

What is connection pooling and why is it used?

A

A cache of database connections maintained so that the connections can be reused when future requests to the database are required. They are used to enhance the performance of executing commands on a database.

61
Q

What are the properties of sub-queries?

A
  • Must be enclosed in the parenthesis
  • Must be put on the right hand of the comparison operator
  • Cannot contain an ORDER BY clause, however sub-query can use ORDER BY when used with TOP clause
  • Can contain more than one sub-query
62
Q

Name the different types of sub-queries.

A
  • Single-row: the sub-query returns only one row
  • Multiple-row sub-query: the sub-query returns multiple rows
  • Multiple column: the sub-query returns multiple columns
63
Q

What is a SQL Profiler?

A

A graphical tool that allows system administrators to monitor events. An interface to create and manage traces and analyze and replay trace results. Events are saved in a trace file that can later be analyzed or used to replay a specific series of steps when trying to diagnose a problem.

64
Q

What are the Authentication Modes in SQL Server?

A
  • Window Mode

* Mixed Mode – SQL and Windows

65
Q

Which command using Query Analyzer will give you the version of SQL Server and operating system?

A
  1. SELECT @@VERSION
  2. SELECT SERVERPROPERTY (‘Edition’) AS Edition,
    SERVERPROPERTY (ProductLevel’) AS ProductLevel,
    SERVERPROPERTY (‘ProductVersion’) AS ProductVersion
    GO
66
Q

What is a SQL Server Agent?

A

It allows you to schedule your own jobs and scripts, and it also helps to ease the implementation of tasks for the DBA, with its full-function scheduling engine.

67
Q

Can a stored procedure call itself or a recursive stored procedure?

A

Yes, because it supports recursion. You can write stored procedures that call themselves. Recursion can be defined as a method of problem solving wherein the solution is arrived at by repetitively applying it to subsets of the problem. A common application of recursive logic is to perform numeric computations that lend themselves to repetitive evaluation by the same processing steps. Stored procedures are nested when one stored procedure calls another or executes managed code by referencing a CLR routine, type, or aggregate.

68
Q

How many levels of stored procedure nesting is possible?

A

Stored procedures can be nested up to 32 levels.

69
Q

What is log shipping?

A

The process of automating the backup of database and transaction log files on a production SQL server and then restoring them onto a standby server. The Express edition does not support log shipping. The transactional log file from one server is automatically updated into the backup database on the other server. If one server fails, the other server can be used as the Disaster Recovery plan. The key feature is that it will automatically backup transaction logs throughout the day and automatically restore them on the standby server at defined intervals.

70
Q

Name three ways to get an accurate count of the number of records in a table.

A
  1. SELECT * FROM table1
  2. SELECT COUNT(*) FROM table1
  3. SELECT rows FROM sysindexes WHERE id = OBJECT(table1) AND indid < 2
  4. Select a column from a table and look at the count at the lower right for the count
71
Q

What does it mean to have QUOTED_INDENTIFIER on?

A

vIdentifiers can be delimited by double quotation marks, and literals must be delimited by single quotation marks.

72
Q

What are the implications of having the QUOTED_INDENTIFIER off?

A

Identifiers cannot be quoted and must follow all T-SQL rules for identifiers.

73
Q

What is the difference between a local and a global temporary table?

A

A local temporary table exists only for the duration of a connection, or if defined inside a compound statement, for the duration of the compound statement.
A global temporary table remains in the database accessible across the connections. Once the connection where original global table is declared dropped this becomes unavailable. Can be seen by all users connected to the server.

74
Q

What is the STUFF function?

A

It is used to overwrite existing characters using this syntax: STUFF (string_expression, start, length, replacement_characters), where string_expression is the string that will have characters substituted, start is the starting position, length is the number of characters in the string that are substituted, and replacement_characters are the new characters interjected into the string.

75
Q

How does the STUFF function differ from the REPLACE function?

A

The REPLACE function is used to replace existing characters of all occurrences. Using the syntax REPLACE (string_expression, search_string, replacement_string), every incidence of search_string found in the string_expression will be replaced with replacement_string.

76
Q

What is Primary Key?

A

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. It is used to enforce entity integrity. CANNOT HAVE A NULL.

77
Q

What is a Unique Key constraint?

A

It enforces the uniqueness of the values in a set of columns; so, no duplicate values are entered. They are used to enforce entity integrity as the primary key constraints. Can have one NULL.

78
Q

What is FOREIGN Key?

A

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. They 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.

79
Q

What is CHECK constraint?

A

Is used to limit the values that can be placed in a column, and they are used to enforce domain integrity. I

80
Q

What is NOT NULL constraint?

A

It enforces that the column will not accept null values and is used to enforce domain integrity, as the check constraints.

81
Q

What is the difference between UNION and UNION ALL?

A

The UNION command is used to select related information from two tables, much like the JOIN command. When using the UNION command, all selected columns need to be of the same data type and only distinct values are selected. Union does not return duplicates.
UNION ALL command selects all values. The UNION ALL command will not eliminate duplicate rows, instead it pulls all rows from all the tables fitting your query specifics and combines them into a table.

82
Q

What is B-Tree?

A

The database server uses a B-tree structure to organize index information and generally, has the following types of index pages or nodes:
• Root node: A root node contains node pointers to only one branch node.
• Branch node: A branch node contains pointers to leaf nodes or other branch nodes, which can be two or more.
• Leaf nodes: A leaf node contains index items and horizontal pointers to other leaf nodes, which can be many.

83
Q

How to get @@ERROR and @@ROWCOUNT at the same time?

A

Include both in the same statement and store them in a local variable. SELECT @RC = @@ROWCOUNT, @ER = @@ERROR

84
Q

What is B-Tree?

A

The database server uses a B-tree structure to organize index information and generally, has the following types of index pages or nodes:
• Root node: A root node contains node pointers to only one branch node.
• Branch node: A branch node contains pointers to leaf nodes or other branch nodes, which can be two or more.
• Leaf nodes: A leaf node contains index items and horizontal pointers to other leaf nodes, which can be many.

85
Q

What is a scheduled job or what is a scheduled task?

A

Scheduled tasks are automated processes that run on regular or predictable cycles. The user can determine the order in which tasks run by creating job steps within a SQL Server Agent job. Job steps give the user control over flow of execution. If one job fails, the user can configure SQL Server Agent to continue to run the remaining tasks or to stop execution.

86
Q

What are the advantages of using stored procedures?

A
  • Can reduce network traffic and latency, boosting application performance
  • Execution plans can be reused because they are cached in SQL Server’s memory, reducing server overhead
  • Help promote code reuse
  • Encapsulate logic. Can change stored procedure code without affecting clients
  • Provide better security to data
87
Q

What is a table called, if it has neither cluster nor non-clustered index?

A

An unindexed table or Heap. A Heap is a table that does not have a clustered index and therefore, the pages are not linked by pointers. The IAM pages are the only structures that link the pages in a table together.

88
Q

What is an unindexed table or Heap used for?

A

The fast storing of data. Many times, it is better to drop all the indexes from table and then do bulk of INSERTS and restore those indexes after that.

89
Q

Can SQL Servers link to other servers like Oracle?

A

SQL Server can be linked to any server provided it has OLE-DB provider from Microsoft to allow a link. Oracle has an OLE-DB provider that Microsoft provides to add it as a linked server to the SQL Server group.

90
Q

What is BCP?

A

BCP (BulkCopy) is a tool used to copy huge amount of data from tables and views. It does not copy the complete structure from source to destination.

91
Q

When is the BCP (BulkCopy) tool used?

A

It is used when you need to import and export large amounts of data in and out of SQL Server databases quickly and easily. The BULK INSERT command helps to import a data file into a database table or view in a user -specified format

92
Q

What is the command to rename a database, a table, and a column?

A
  • To rename a database use sp_renamedb ‘oldname’, ‘newname
  • To rename a table use sp_RENAME ‘Table_First’, ‘Table_Last’ GO
  • To rename column use sp_rename ‘TableName.[OldcolumnName]’, ‘NewColumnName’, ‘Column’
93
Q

What are sp_configure commands?

A

They are used to display or change server-level settings. To change the database-level settings, use ALTER DATABASE.

94
Q

What are Set commands?

A

Change the settings that affect only the current user session.

95
Q

How to implement One-to-One, One-to-Many and Many-to-Many relationships while designing tables?

A

Commit makes it permanent and rollback goes back to the original state before the transaction started

96
Q

What is an execution plan?

A

A road map that graphically or textually shows the data retrieval methods chosen by the SQL Server query optimizer for a stored procedure or ad-hoc query.

97
Q

When would you use an execution plan?

A

You would use it for performance tuning to make something faster.

98
Q

How would you view an execution plan?

A

Within the Query Analyzer, there is an option called “Show Execution Plan” (in the Query drop-down menu), if this option is turned on, it will display query execution plan in a separate window when the query is ran again.

99
Q

What is the difference between table aliases and column aliases and do they affect performance?

A

Table aliases are used to avoid any ambiguity with respect to columns selected in SELECT statement which might belong to two or more tables joined.
Column aliases is used to name a column in an understandable format.
Aliases do not affect performance.

100
Q

What is the difference between CHAR and VARCHAR datatypes?

A

CHAR is a fixed-length character data type and the storage size of the CHAR value is equal to the maximum size for this column. Can use when the data entries in a column are expected to be the same size.
VARCHAR is a variable-length character data type.

101
Q

What is the difference between VARCHAR and VARCHAR(MAX) datatypes?

A

VARCHAR stores variable-length character data whose range varies up to 8000 bytes; varchar(MAX) stores variable-length character data whose range may vary beyond 8000 bytes and till 2 GB. TEXT datatype is going to be deprecated in future versions, and the usage of VARCHAR(MAX) is strongly recommended instead of TEXT datatypes

102
Q

What is the difference between VARCHAR and NVARCHAR datatypes?

A

NVARCHAR supports Unicode characters, allowing you to use multiple languages in the database. It’s takes twice as much space when compared to VARCHAR. Use NVARCHAR only if you are using foreign languages.

103
Q

Which are important points to note when multilanguage data is stored in a table?

A
  1. The column must be of Unicode data type (NCHAR, NVARCHAR, NTEXT).
  2. The value must be prefixed with N while insertion. For example: INSERT INTO table (Hindi_col) values (N’hindi data’)
104
Q

How to optimize stored procedure optimization?

A
  • Include SET NOCOUNT ON statement
  • Use schema name with object name
  • Don’t use the prefix “sp_” in the stored procedure name
  • Use IF EXISTS (SELECT 1) instead of (SELECT *)
  • Use the sp_executesql stored procedure instead of the EXECUTE statement
  • Avoid using SQL Server cursors whenever possible
  • Keep the transactions as short as possible
  • Use TRY-Catch for error handling
105
Q

What does TOP operator do?

A

The TOP operator is used to specify the number of rows to be returned by a query. The TOP operator has new addition in SQL SERVER 2008 that it accepts variables as well as literal values and can be used with INSERT, UPDATE, and DELETE statements.