Sunteți pe pagina 1din 15

1.

Configuring sql server


Enable remote connections for SQL Server 2005 Express or SQL Server 2005 Developer Edition
You must enable remote connections for each instance of SQL Server 2005 that you want to connect to from a remote computer. To do this, follow these steps:

1.
2. 3.

Click Start, point to Programs, point to Microsoft SQL Server 2005, point toConfiguration Tools, and then click SQL Server Surface Area Configuration. On the SQL Server 2005 Surface Area Configuration page, click Surface Area Configuration for Services and Connections. On the Surface Area Configuration for Services and Connections page, expandDatabase Engine, click Remote Connections, click Local and remote connections, click the appropriate protocol to enable for your environment, and then click Apply. Note Click OK when you receive the following message:

Changes to Connection Settings will not take effect until you restart the Database Engine service.

4.

On the Surface Area Configuration for Services and Connections page, expandDatabase Engine, click Service, click Stop, wait until the MSSQLSERVER service stops, and then click Start to restart the MSSQLSERVER service.

Back to the top

Enable the SQL Server Browser service


If you are running SQL Server 2005 by using an instance name and you are not using a specific TCP/IP port number in your connection string, you must enable the SQL Server Browser service to allow for remote connections. For example, SQL Server 2005 Express is installed with a default instance name of Computer Name\SQLEXPRESS. You are only required to enable the SQL Server Browser service one time, regardless of how many instances of SQL Server 2005 you are running. To enable the SQL Server Browser service, follow these steps. Important These steps may increase your security risk. These steps may also make your computer or your network more vulnerable to attack by malicious users or by malicious software such as viruses. We recommend the process that this article describes to enable programs to operate as they are designed to, or to implement specific program capabilities. Before you make these changes, we recommend that you evaluate the risks that are associated with implementing this process in your particular environment. If you choose to implement this process, take any appropriate additional steps to help protect your system. We recommend that you use this process only if you really require this process.

1.
2. 3.

Click Start, point to Programs, point to Microsoft SQL Server 2005, point toConfiguration Tools, and then click SQL Server Surface Area Configuration. On the SQL Server 2005 Surface Area Configuration page, click Surface Area Configuration for Services and Connections. On the Surface Area Configuration for Services and Connections page, click SQL Server Browser, click Automatic for Startup type, and then click Apply. Note When you click the Automatic option, the SQL Server Browser service starts automatically every time that you start Microsoft Windows. Click Start, and then click OK.

4.

Note When you run the SQL Server Browser service on a computer, the computer displays the instance names and the connection information for each instance of SQL Server that is running on the computer. This risk can be reduced by not enabling the SQL Server Browser service and by connecting to the instance of SQL Server directly through an assigned TCP port. Connecting directly to an instance of SQL Server through a TCP port is beyond the scope of this article. For more information about the SQL Server Browser server and connecting to an instance of SQL Server, see the following topics in SQL Server Books Online:

y y y

SQL Server Browser Service Connecting to the SQL Server Database Engine Client Network Configuration

Back to the top

Create exceptions in Windows Firewall


These steps apply to the version of Windows Firewall that is included in Windows XP Service Pack 2 (SP2) and in Windows Server 2003. If you are using a different firewall system, see your firewall documentation for more information. If you are running a firewall on the computer that is running SQL Server 2005, external connections to SQL Server 2005 will be blocked unless SQL Server 2005 and the SQL Server Browser service can communicate through the firewall. You must create an exception for each instance of SQL Server 2005 that you want to accept remote connections and an exception for the SQL Server Browser service. SQL Server 2005 uses an instance ID as part of the path when you install its program files. To create an exception for each instance of SQL Server, you must identify the correct instance ID. To obtain an instance ID, follow these steps:

1.
2. 3.

Click Start, point to Programs, point to Microsoft SQL Server 2005, point toConfiguration Tools, and then click SQL Server Configuration Manager. In SQL Server Configuration Manager, click the SQL Server Browser service in the right pane, right-click the instance name in the main window, and then click Properties. On the SQL Server Browser Properties page, click the Advanced tab, locate the instance ID in the property list, and then click OK.

To open Windows Firewall, click Start, click Run, type firewall.cpl, and then click OK.

Create an exception for SQL Server 2005 in Windows Firewall


To create an exception for SQL Server 2005 in Windows Firewall, follow these steps:

1.
2. 3.

In Windows Firewall, click the Exceptions tab, and then click Add Program. In the Add a Program window, click Browse. Click the C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn\sqlservr.exe executable program, click Open, and then click OK. Note The path may be different depending on where SQL Server 2005 is installed.MSSQL.1 is a placeholder for the instance ID that you obtained in step 3 of the previous procedure. Repeat steps 1 through 3 for each instance of SQL Server 2005 that needs an exception.

4.

Create an exception for the SQL Server Browser service in Windows Firewall
To create an exception for the SQL Server Browser service in Windows Firewall, follow these steps:

1.
2. 3.

In Windows Firewall, click the Exceptions tab, and then click Add Program. In the Add a Program window, click Browse. Click the C:\Program Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe executable program, click Open, and then click OK. Note The path may be different depending on where SQL Server 2005 is installed.

2.Trouble shooting sql server


To troubleshoot performance issues, you must complete a series of steps to isolate and determine the cause of the problem. Possible causes include:

y y y y

Blocking System resource contention Application design problems Queries or stored procedures that have long execution times

Identifying these causes is typically very time consuming, and you may spend several days evaluating the collected information. The complexity of the performance analysis is not specific to a particular database product or operating system. All applications are subject to performance constraints because of resource, design, or usage factors. For more information, click the following article number to view the article in the Microsoft Knowledge Base: 224587 How to troubleshoot application performance with SQL Server To help identify and troubleshoot the problem, collect the following information at the same time and have the output readily available before you contact Microsoft Product Support Services (PSS):

y y y

Blocker script output SQL Profiler trace log SQL Server Performance Monitor log

Note If you do not collect this information when the performance problem occurs, you may have to gather all the information again. This can delay the troubleshooting process. After the problem occurs, collect the following information and have it available:

y y

sqldiag report Microsoft Windows NT System and Application Event logs

In most scenarios, PSS requires this information to understand the environment and the nature of the performance issue. If any part of this information is not available, the troubleshooting process may be prolonged and identifying the performance issue may be delayed. Even if you are currently not experiencing any performance issues, Microsoft recommends that you implement this process. If a performance issue occurs, you can capture the required information as soon as possible. Additionally, if you capture a baseline SQL Profiler log, SQL Server Performance Monitor log, and blocker script when the application is performing as expected, you can use that information for comparison when the application does not perform as expected. If you gather this information in a high traffic SQL Server environment, you may experience some performance degradation. However, you must have this information to identify the cause of the problem and for troubleshooting purposes. The SQL Profiler trace has the most impact on performance. If the performance is severely degraded, you can customize the SQL Profiler trace by reducing the types of events that it captures. Limiting the SQL Profiler trace should provide some improvement. If you have questions or problems setting up and collecting the information, contact PSS.

Back to the top

Blocker script output


The blocker script is critical for identifying blocking scenarios. However, you can use the output from the script to troubleshoot performance problems even when blocking is not an issue. This output also helps to determine if queries are waiting on resources, such as file I/O, or if transactions are not being committed or rolled back as expected. For more information about implementing the blocker script, click the following article numbers to view the articles in the Microsoft Knowledge Base: 251004 How to monitor SQL Server 7.0 blocking 271509 How to monitor SQL Server 2000 blocking

Back to the top

SQL Profiler trace log


The SQL Profiler trace captures the activity on the computer running SQL Server. You can use this information to identify slow running queries and non-optimal execution plans. Additionally, SQL Profiler documents the series of events that occur before the performance problem and helps to identify its cause. To create and implement a SQL Profiler trace by using the GUI, see the "What to Monitor" section of the following Microsoft Knowledge Base article: 224587 How to troubleshoot application performance with SQL Server For more information about how to create and execute a SQL Profiler trace by using Transact-SQL commands, click the following article numbers to view the articles in the Microsoft Knowledge Base: 289742 How to create a SQL Server 7.0 trace 283790 How to create a SQL Server 2000 trace For more information about how to monitor a SQL Profiler trace by using Transact-SQL commands, click the following article numbers to view the articles in the Microsoft Knowledge Base: 289279 INF: How to Monitor SQL Server 7.0 traces 283786 How to monitor SQL Server 2000 traces Note If you have a SQL Profiler trace of a large workload, you can use the Index Tuning Wizard. The Index Tuning Wizard uses the SQL Server query optimizer to determine the optimal set of indexes for the specified queries. The Index Tuning Wizard is a very efficient tool to determine if the correct indexes exist in your database. By implementing the indexes that the wizard suggests, you may be able to increase the performance of your application. For more information about how to use the Index Tuning Wizard, see the "Index Tuning Wizard" topic in SQL Server Books Online.

Back to the top

SQL Server Performance Monitor log


SQL Server is typically affected by the following bottlenecks:

y y y y

CPU Memory File I/O Locking, blocking, or deadlocking

You can use SQL Server Performance Monitor to identify how these potential bottlenecks may affect SQL Server. Additionally, you can use this log to identify when an external process is heavily using the computer running SQL Server and negatively impacting SQL Server performance. Before you start SQL Server Performance Monitor, make sure that the disk counters are on. To do so, run diskperf from a command prompt. If the disk counters are not on, run diskperf -yand then restart the computer. When you create a SQL Server Performance Monitor log, collect the following information:

y y y y y y y y y

Paging file Process Processor All SQL Server counters Memory Threads Logical disk Physical disk System

Note The default interval of 15 seconds should enough time to monitor the server; however, for some timing issues, you may have to reduce the time interval for collecting data. For more information about how to set up a SQL Server Performance Monitor log, click the following article numbers to view the articles in the Microsoft Knowledge Base: 150934 How to create a Performance Monitor log for NT troubleshooting 248345 How to create a log using System Monitor in Windows 2000

Note For more information about monitoring performance in SQL Server 2005, see the "Monitoring and Tuning for Performance" topic in SQL Server 2005 Books Online. Back to the top

sqldiag utility
The sqldiag utility is provided with SQL Server. It collects valuable information about the configuration of the computer running SQL Server, the operating system, and the information that is reported to the SQL Server error logs. For information about how to use the sqldiag utility, see the "sqldiag Utility " topic in SQL Server Books Online. For more information about how to run sqldiag on a clustered SQL Server, click the following article number to view the article in the Microsoft Knowledge Base: 233332 How to run SQLDIAG on a clustered/virtual SQL Server Note In SQL Server 2005, the SQLdiag utility has changed significantly. The command line arguments for this utility are not compatible with SQL Server 2000. This utility may be changed, and applications or scripts that rely on its command line arguments or behavior may not work correctly in future releases. For more information, see the "SQLdiag Utility" topic in SQL Server 2005 Books Online. Back to the top

Microsoft Windows NT System and Application Event logs


You can use the Windows NT system and application event logs to identify issues that you cannot see in other data. These logs help provide a complete view of server activity and provide a more complete understanding of the environment. Back to the top

Where to save these files


The following Microsoft File Exchange FTP server permits you to send and receive files to and from PSS engineers: ftp://ftppss.microsoft.com

3.User Defined Functions In Sql server


User Defined Functions in Microsoft SQL Server 2000

By Don Schlichting
This article will explore the uses, restrictions and benefits of User Defined Functions in Microsoft SQL Server 2000

Introduction
User Defined Functions are compact pieces of Transact SQL code, which can accept parameters, and return either a value, or a table. They are saved as individual work units, and are created using standard SQL commands. Data transformation and reference value retrieval are common uses for functions. LEFT, the built in function for getting the left part of a string, and GETDATE, used for obtaining the current date and time, are two examples of function use. User Defined Functions enable the developer or DBA to create functions of their own, and save them inside SQL Server.

Advantages of User Defined Functions

Before SQL 2000, User Defined Functions (UDFs), were not available. Stored Procedures were often used in their place. When advantages or disadvantages of User Defined Functions are discussed, the comparison is usually to Stored Procedures. One of the advantages of User Defined Functions over Stored Procedures, is the fact that a UDF can be used in a Select, Where, or Case statement. They also can be used to create joins. In addition, User Defined Functions are simpler to invoke than Stored Procedures from inside another SQL statement.

Disadvantages of User Defined Functions


User Defined Functions cannot be used to modify base table information. The DML statements INSERT, UPDATE, and DELETE cannot be used on base tables. Another disadvantage is that SQL functions that return non-deterministic values are not allowed to be called from inside User Defined Functions. GETDATE is an example of a non-deterministic function. Every time the function is called, a different value is returned. Therefore, GETDATE cannot be called from inside a UDF you create.

Types of User Defined Functions


There are three different types of User Defined Functions. Each type refers to the data being returned by the function. Scalar functions return a single value. In Line Table functions return a single table variable that was created by a select statement. The final UDF is a Multi-statement Table Function. This function returns a table variable whose structure was created by hand, similar to a Create Table statement. It is useful when complex data manipulation inside the function is required.

Scalar UDFs
Our first User Defined Function will accept a date time, and return only the date portion. Scalar functions return a value. From inside Query Analyzer, enter: CREATE FUNCTION dbo.DateOnly(@InDateTime datetime) RETURNS varchar(10) AS BEGIN DECLARE @MyOutput varchar(10) SET @MyOutput = CONVERT(varchar(10),@InDateTime,101) RETURN @MyOutput END To call our function, execute: SELECT dbo.DateOnly(GETDATE()) Notice the User Defined Function must be prefaced with the owner name, DBO in this case. In addition, GETDATE can be used as the input parameter, but could not be used inside the function itself. Other built in SQL functions that cannot be used inside a User Defined Function include: RAND, NEWID, @@CONNCECTIONS, @@TIMETICKS, and @@PACK_SENT. Any built in function that is non-deterministic. The statement begins by supplying a function name and input parameter list. In this case, a date time value will be passed in. The next line defines the type of data the UDF will return.

Between the BEGIN and END block is the statement code. Declaring the output variable was for clarity only. This function should be shortened to: CREATE FUNCTION testDateOnly(@InDateTime datetime) RETURNS varchar(10) AS BEGIN RETURN CONVERT(varchar(10),@InDateTime,101) END

Inline Table UDFs


These User Defined Functions return a table variable that was created by a single select statement. Almost like a simply constructed non-updatable view, but having the benefit of accepting input parameters. This next function looks all the employees in the pubs database that start with a letter that is passed in as a parameter. In Query Analyzer, enter and run: USE pubs GO CREATE FUNCTION dbo.LookByFName(@FirstLetter char(1)) RETURNS TABLE AS RETURN SELECT * FROM employee WHERE LEFT(fname, 1) = @FirstLetter To use the new function, enter: SELECT * FROM dbo.LookByFName('A') All the rows having a first name starting with A were returned.

MS SQL

May 7, 2004

User Defined Functions in Microsoft SQL Server 2000

By Don Schlichting

Multi Statement UDFs

Multi Statement User Defined Functions are very similar to Stored Procedures. They both allow complex logic to take place inside the function. There are a number of restrictions

Difference between 2000 and 2005 ?


. What are the major differences between 2000 and 2005 in terms of security? a. Owner = Schema, hard to remove old users at times in 2000 b. Schema is separate. Better granularity in easily controlling security. Logins can be authenticated by certificates. In 2005 c. In 2000 there is no concept of synonyms, in 2005 it is introduced d. In 2000 there in policy based management, in 2008 its there

How to find deadlocks and how to resolve that?


a. Just switch on the trace for 1204, 1222, 3605 b. ex:DBCC Traceon(1204,1222,3505,-1)

How to move logfile location from once drive to another drive?


a. By attach and detach

My log file is full how to solve it?


a. By apply the shrink command b. Or by applying truncate command
Problem As we are reviewing the new features in SQL Server 2008, we found one that looks really interesting - Policy-Based Management. Could you help us to understand how this works and provide some examples? Can you please explain each of the components and how to manage them in the interface and with commands?

Next Steps

How to shrink log files ?


1. Back up the transaction log file to make most of the active virtual log files inactive. Therefore, the inactive virtual log files can be removed in a later step. To do this, run a Transact-SQL statement that is similar to the following Transact-SQL statement.

BACKUP LOG <DatabaseName> TO DISK = '<BackupFile>'


Note In this statement, <DatabaseName> is a placeholder for the name of the database that you are backing up. In this statement, <BackupFile> is a placeholder for the full path of the backup file. For example, run the following Transact-SQL statement.

BACKUP LOG TestDB TO DISK='C:\TestDB1.bak'


2. Shrink the transaction log file. To do this, run a Transact-SQL statement that is similar to the following Transact-SQL statement.

DBCC SHRINKFILE (<FileName>, <TargetSize>) WITH NO_INFOMSGS

credit union ?
a cooperative depository financial institution whose members can obtain loans from their combined savings

Building Society ?
A building society is a financial institution, owned by its members, that offers banking and other financial services, especially mortgage lending. Re: Difference between sql server 2000 and sql server 2005?
1. In SQL Server 2000 the Query Analyzer and Enterprise Manager are seperate,whereas in SQL Server 2005 both were combined as Management Studio. 2. In Sql 2005,the new datatype XML is used,whereas in Sql 2000 there is no such datatype 3. In Sql server2000 we can create 65,535 databases,whereas in Sql server2005 2(pow(20))-1 databases can be created. How to simulate a deadlock for testing purposes? <top>

In Query Analyzer, run the following statements first:

CREATE TABLE t1 (i int) CREATE TABLE t2 (i int) INSERT t1 SELECT 1 INSERT t2 SELECT 9 Open a new window (say Window1) in Query Analyzer, paste the following SQL statements: BEGIN TRAN UPDATE t1 SET i = 11 WHERE i = 1 WAITFOR DELAY '00:00:20' UPDATE t2 SET i = 99 WHERE i = 9 COMMIT Open another window (say Window2) in Query Analyzer and paste the following code: BEGIN TRAN UPDATE t2 SET i = 99 WHERE i = 9 WAITFOR DELAY '00:00:20' UPDATE t1 SET i = 11 WHERE i = 1 COMMIT Now run the code from Window1, followed by Window2 simultaneously. Briefly after 20 seconds, one of the windows will What is index segmentation?
A segment is a part of relational data base and consists of one or more extents. Each extent is further divided into blocks. Every segment has an index for holding all of its data for quick data retrieval. Index segments can be created explicitly by using the CREATE INDEX command. Storage parameters for the extents of the index segment can be specified along with this command.

What is Index Tuning Wizard in sqlserver 2005?


Index Tuning Wizard is a software application that identifies tables which have inefficient indexes. It makes recommendations on how indexes should be built on a database to optimize performance. The recommendations are based on T-SQL commands that the wizard analyzes.

List out what Index Tuning Wizard can do in Sqlserver 2005


1. 2. 3. 4. 5. 6. It identifies tables in need of an index change Implements recommendations Determines how a proposed change might affect performance Has the capability to make indexes change immediately and schedule them Helps to tune indexes.

What is refreshing in SQLServer?


You most likely refresh a development or test environment frequently with a recent production environment backup. Depending on what you are testing or developing, current data may be critical to

ensuring your results are valid. Creating an automated task to restore the database regularly (weekly, daily or even several times a day as needed) will save lots of time and guarantee that you do not miss any necessary restore steps. At a high level, you should complete the following steps to refresh a test or development environment using backup and restore as the refresh method: 1. Back up the production database: You should already have a scheduled process that creates daily full backups, so use the backup files that are already in place. 2. Copy all the users in test environment to some other table in master data base 2. Kill connections to database: In order to do a restore, there can be no active connections to the database. All connections to the database must be killed before you start the restore. 3. Restore the database: Issue the restore command. 4. Re-link users and logins: Users and logins are associated by SIDs (security identifiers). These may not be the same on your production and test environments, so you will need to re-lid

Trouble shooting Alerts


Troubleshooting SQL Server Alerts If you have problems with Microsoft SQL Server alerts, review this troubleshooting checklist to find potential solutions. 1. Check that you are using the latest SQL Server service pack. Because many alert bugs were fixed in SQL Server service packs, you should install the latest SQL Server service pack. Check "How can I check what SQL service pack am I running?" to find out which SQL Server service pack you are running. 2. Check that the account the SQLServerAgent services runs under is a member of the Domain Users group. The LocalSystem account does not have network access rights. Therefore, if you want to forward events to the application logs of other Windows NT or Windows 2000 computers, or your jobs require resources across the network, or you want to notify operators through e-mail or pagers, you must set the account the SQLServerAgent service runs under to be a member of the Domain Users group. 3. If all of the alerts are not firing, check that the SQLServerAgent and EventLog services are running. These services must be started, if you need the alerts to be fired.

So, if these services are not running, you should run them. 4. If an alert is not firing, make sure that it is enabled. The alert can be enabled or disabled. To check if an alert is enabled, you can do the following: 1. Run SQL Server Enterprise Manager. 2. Expand a server group; then expand a server. 3. Expand Management; then expand SQL Server Agent. 4. Double-click the appropriate alert to see if the alert is enabled. 5. Check the history values of the alert to determine the last date that the alert worked. To view the history values of the alert, you can do the following: 1. Run SQL Server Enterprise Manager. 2. Expand a server group; then expand a server. 3. Expand Management; then expand SQL Server Agent. 4. Double-click the appropriate alert to see the alert history. 6. Verify that the counter value is maintained for at least 20 seconds. Because SQL Server Agent polls the performance counters at 20 second intervals, if the counter value is maintained for only a few seconds (less than 20 seconds), there is a high likelihood that the alert will not fire. 7. Check the SQL Server error log, SQL Server Agent error log, and Windows NT or Windows 2000 application log to get a more detailed error description. Comparing the dates and times for alert failure events between the SQL Server error log, the SQL Server Agent error log, and the Windows NT or Windows 2000 application log can help you to determine the reason of the failure. 8. If the alert fires, but the responsible operator does not receive notification, try to send 'e-mail', 'pager', or 'net send' message to

this operator manually. In most cases, this problem arises when you have entered an incorrect 'e-mail', 'pager', or 'net send' addresses. If you can send an 'email', 'pager', or 'net send' message manually to this operator, check the account the SQL Server Agent runs under, as well as the operator's on-duty schedule. 9. If the alert fires, but the notification is not timely, decrease the 'Delay between responses' setting for the alert and try to send notifications to as few operators as possible. To decrease the 'Delay between responses' setting for the alert, you can do the following: 1. Run SQL Server Enterprise Manager. 2. Expand a server group; then expand a server. 3. Expand Management; then expand SQL Server Agent. 4. Double-click the appropriate alert and choose the 'Response' tab. 5. Specify a new 'Delay between responses' setting. 10. Alert cannot send e-mail notification with xp_logevent or RAISERROR. This is an SQL Server 7.0 and SQL Server 2000 bug. This happens if the alert is defined to be restricted to a specific database other than the master database. To work around this, you can define the alert on the master database, or all databases. To define the alert on all databases, you can do the following: 1. Run SQL Server Enterprise Manager. 2. Expand a server group; then expand a server. 3. Expand Management; then expand SQL Server Agent. 4. Double-click the appropriate alert and choose '(All Databases)' in the Database name combobox. 11. Alerts are triggered incorrectly when Security Auditing is enabled. This is an SQL Server 7.0 and SQL Server 2000 bug. This bug was fixed in SQL Server 2000 service pack 1 and in SQL Server 7.0 service pack

4. To work around this problem, you can disable Security Auditing, or you can install the service packs. 12. After Installing SQL Server 7.0 service pack 3, SQL Server Agent alerts may fail to work. This is an SQL Server 7.0 service pack 3 bug. To work around this, you should install SQL Server 7.0 service pack 4. 13. Responses for performance condition alerts are sent every 20 seconds, regardless of the 'Delay between responses' setting for the alert. This is an SQL Server 7.0 bug. To work around this, you should install SQL Server 7.0 service pack 1 or higher.


What is an extended stored procedure? Can you instantiate a COM object by using TSQL?  An extended stored procedure is a function within a DLL (written in a programming language like C, C++ using Open Data Services (ODS) API) that can be called from TSQL, just the way we call normal stored procedures using the EXEC statement. See books online to learn how to create extended stored procedures and how to add them to SQL Server. Yes, you can instantiate a COM (written in languages like VB, VC++) object from T-SQL by using sp_OACreate stored procedure. Also see books online for sp_OAMethod, sp_OAGetProperty, sp_OASetProperty, sp_OADestroy. For an example of creating a COM object in VB and calling it from T-SQL, see My code library section of this site. Re: Define Check points and End Points?
CheckPoints:Whenever we perform any DML operations in the database,it will go to the checkpoint and then commit in the database.If we don't have checkpoints,the data will get store in transaction log file,once it got fill full,it will make the database performance issues. Endpoints:Endpoints are objects that represent a communication point between the server and a client. 1. What is a "constraint"? - A constraint allows you to apply simple referential integrity checks to a table. There are four primary types of constraints that are currently supported by SQL Server: PRIMARY/UNIQUE - enforces uniqueness of a particular table column. DEFAULT - specifies a default value for a column in case an insert operation does not provide one. FOREIGN KEY - validates that every value in a column exists in a column of another table. CHECK - checks that every value stored in a column is in some specified list. Each type of constraint performs a specific type of action. Default is not a constraint. NOT

NULL is one more constraint which does not allow values in the specific column to be null. And also it the only constraint which is not a table level constraint.
What is a deadlock and what is a live lock? How will you go about resolving deadlocks?

1.

Deadlock is a situation when two processes, each having a lock on one piece of data, attempt to acquire a lock on the other's piece. Each process would wait indefinitely for the other to release the lock, unless one of the user processes is terminated. SQL Server detects deadlocks and terminates one user's process. A livelock is one, where a request for an exclusive lock is repeatedly denied because a series of overlapping shared locks keeps interfering. SQL Server detects the situation after four denials and refuses further shared locks. A livelock also occurs when read transactions monopolize a table or page, forcing a write transaction to wait indefinitely.

1486 Error in Mirroring


Error Description: Database mirroring transport is disabled in the endpoint configuration ............ Solution: ALTER ENDPOINT [mirroring] STATE= STARTED Here 'mirroring' is my end point name..

Data Intigrity
Enforcing data integrity ensures the quality of the data in the database. For example, if an employee is entered with an employee_id value of 123, the database should not allow another employee to have an ID with the same value. If you have an employee_rating column intended to have values ranging from 1 to 5, the database should not accept a value of 6. If the table has a dept_id column that stores the department number for the employee, the database should allow only values that are valid for the department numbers in the company. Two important steps in planning tables are to identify valid values for a column and to decide how to enforce the integrity of the data in the column. Data integrity falls into these categories:

y y y y

Entity integrity

Domain integrity

Referential integrity

User-defined integrity

Entity Integrity
Entity integrity defines a row as a unique entity for a particular table. Entity integrity enforces the integrity of the identifier column(s) or the primary key of a table (through indexes, UNIQUE constraints, PRIMARY KEY constraints, or IDENTITY properties).

Domain Integrity
Domain integrity is the validity of entries for a given column. You can enforce domain integrity by restricting the type (through data types), the format (through CHECK constraints and rules), or the range of possible values (through FOREIGN KEY constraints, CHECK constraints, DEFAULT definitions, NOT NULL definitions, and rules).

Referential Integrity
Referential integrity preserves the defined relationships between tables when records are entered or deleted. In Microsoft SQL Server 2000, referential integrity is based on relationships between foreign keys and primary keys or between foreign keys and unique keys (through FOREIGN KEY and CHECK constraints). Referential integrity ensures that key values are consistent across tables. Such consistency requires that there be no references to nonexistent values and that if a key value changes, all references to it change consistently throughout the database.

When you enforce referential integrity, SQL Server prevents users from:

y y y

Adding records to a related table if there is no associated record in the primary table.

Changing values in a primary table that result in orphaned records in a related table.

Deleting records from a primary table if there are matching related records.

For example, with the sales and titles tables in the pubs database, referential integrity is based on the relationship between the foreign key (title_id) in the salestable and the primary key (title_id) in the titles table.

S-ar putea să vă placă și