Showing posts with label Database. Show all posts
Showing posts with label Database. Show all posts

0 SQL SERVER – Reset sa Password

1.Open the SQL Server express management studio
2.Connect to SQL Server using windows authentication
3.Right click the server name and choose properties
4.Go to security tab. Change server authentication to “SQL Server and Windows Authentication mode”
5.Click OK and restart SQL Server
6.Go to SQL Server studio management express
7.Expand the server and choose security and expand logins
8.Right click on SA, from properties modify the password and confirm password

Or 

To reset the sa password, you can make the following:
1. Login to the SQL Server box as the Administrator.
2. Run SQL Server Enterprise Manager.
3. Right-click the server name and choose ‘Edit SQL Server Registration properties’.
4. Choose ‘Use Windows authentication’ and click OK button.
5. Expand a server, expand a Security and click Logins.
6. Double-click the sa login and specify new password on the General tab. (enable Login to)

Or You Can Use

USE [master]
GO
ALTER LOGIN [sa] WITH DEFAULT_DATABASE=[master],
DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=ON, CHECK_POLICY=ON
GO
USE [master]
GO
ALTER LOGIN [sa] WITH PASSWORD=N’’ MUST_CHANGE
GO

Or 

From a command prompt
OSQL -S -E
1> EXEC sp_password NULL, ‘’, ‘sa’
2> GO

0 Tips & Tricks - SQL Server 2008

Did you know... How to perform date/time conversions using SQL Server
The first considerations is the actual date/time needed. The most common is the current date/time using getdate(). To change the format of the date, you convert the requested date to a string and specify the format number corresponding to the format needed using select convert(varchar, getdate(),)


Did you know.. How to get operating system content into SQL Server
Use the xp_cmdshell extended stored procedure to access the file system and bring the contents into SQL Server. By using a combination of both OS level commands and SQL Server commands you can pull this data into SQL Server for processing.


Did you know... How to delete duplicate rows when there is no primary key
An option that SQL Server gives you is the ability to set ROWCOUNT which limits the numbers of records affected by a command. The default value is 0 which means all records, but this value can be set prior to running a command.

0 What are Indexes? (SQL)

Microsoft SQL Server index is a structure associated with a table that speeds retrieval of the rows in the table.
An index contains keys built from one or more columns in the table. These keys are stored in a
structure that allows SQL Server to find the row or rows associated with the key values quickly and efficiently. If a table is created with no indexes, the data rows are not stored in any particular order. This structure is called a heap.

The two types of SQL Server indexes are:

Clustered
Clustered indexes sort and store the data rows in the table based on their key values. Because the data rows are stored in sorted order on the clustered index key, clustered indexes are efficient for finding rows. There can only be one clustered index per table, because the data rows themselves can only be sorted in one order. The data rows themselves form the lowest
level of the clustered index.

The only time the data rows in a table are stored in sorted order is when the table contains a clustered index. If a table has no clustered index, its data rows are stored in a heap.

Nonclustered
Nonclustered indexes have a structure that is completely separate from the data rows. The
lowest rows of a nonclustered index contain the nonclustered index key values and each key value entry has pointers to the data rows containing the key value. The data rows are not stored in order based on the nonclustered key. The pointer from an index row in a nonclustered index to a data row is called a row locator. The structure of the row locator depends on whether the data pages are stored in a heap or are clustered. For a heap, a row locator is a pointer to the row. For a table with a clustered index, the row locator is the clustered index key

0 What are DBCC COMMANDS? (SQL)

The Transact-SQL programming language provides DBCC statements that act as the “database consistency checker” for Microsoft® SQL Server™. These statements check the physical and logical consistency of a database. Many DBCC statements can fix detected problems. These database consistency-checking statements are grouped into these categories.

Maintenance Statements:
Maintenance tasks on a database, index, or filegroup.
  1. DBCC DBREPAIR
  2. DBCC SHRINKFILE
  3. DBCC DBREINDEX
  4. DBCC UPDATEUSAGE
  5. DBCC SHRINKDATABASE
Miscellaneous Statements:
Miscellaneous tasks such as enabling row-level locking or removing a dynamic-link library (DLL) from memory
  1. DBCC dllname (FREE)
  2. DBCC TRACEOFF
  3. DBCC HELP
  4. DBCC TRACEON
  5. DBCC PINTABLE
  6. DBCC UNPINTABLE
  7. DBCC ROWLOCK
Status Statements:
Status Checks
  1. DBCC INPUTBUFFER
  2. DBCC SHOW_STATISTICS
  3. DBCC OPENTRAN
  4. DBCC SQLPERF
  5. DBCC OUTPUTBUFFER
  6. DBCC TRACESTATUS
  7. DBCC PROCCACHE
  8. DBCC USEROPTIONS
  9. DBCC SHOWCONTIG
Validation Statements:
Validation operations on a database, table, index, catalog, filegroup, system tables, or allocation of database pages.
  1. DBCC CHECKALLOC
  2. DBCC CHECKTABLE
  3. DBCC CHECKCATALOG
  4. DBCC NEWALLOC
  5. DBCC CHECKDB
  6. DBCC TEXTALL
  7. DBCC CHECKFILEGROUP
  8. DBCC TEXTALLOC
  9. DBCC CHECKIDENT

0 What are Isolation levels? (SQL)

An isolation level determines the degree to which data is isolated for use by one process and
guarded against interference from other processes.

Read Committed - SQL Server acquires a share lock while reading a row into a cursor but frees the lock immediately after reading the row. Because a shared lock request is blocked by an exclusive lock, a cursor is prevented from reading a row that another task has updated but not yet committed. Read committed is the default isolation level setting for both SQL Server and ODBC.

Read Uncommitted - SQL Server requests no locks while reading a row into a cursor and honors no exclusive locks. Cursors can be populated with values that have already been updated but not yet committed. The user is bypassing all of SQL Server’s locking transaction control mechanisms.

Repeatable Read or Serializable - SQL Server requests a shared lock on each row as it
is read into the cursor as in READ COMMITTED, but if the cursor is opened within a transaction, the shared locks are held until the end of the transaction instead of being freed after the row is read. This has the same effect as specifying HOLDLOCK on a SELECT statement.

0 What are the different types of Filebackup options? (SQL)

All data and objects in the database, such as tables, stored procedures, triggers, and views, are stored only within the following operating system files:

Primary
This file contains the startup information for the database and is used to store data. Every database has one primary data file.

Secondary
These files hold all of the data that does not fit in the primary data file. If the primary file can hold all of the data in the database, databases do not need to have secondary data files. Some databases may be large enough to need multiple secondary data files or to use secondary files on separate disk drives to spread data across multiple disks.

Transaction Log
These files hold the log information used to recover the database. There must be at least
one log file for each database. File groups allow files to be grouped together for administrative and data allocation/placement purposes

Rules of Files and Filegroups
Rules for designing files and filegroups include:
  1. A file or filegroup cannot be used by more than one database. For example, file sales.mdf
    and sales.ndf, which contain data and objects from the sales database, cannot be used by any other database.
  2. A file can be a member of only one filegroup.
  3. Data and transaction log information cannot be part of the same file or filegroup.
  4. Transaction log files are never part of any filegroups.
Types of BackUP
  1. Database
  2. Transaction log
  3. Differential
  4. Filegroup & Backup

1 What are the different types of Joins? (SQL)

Joins as used to combine the contents of two or more tables and produce a result set that incorporates rows and columns from each table. Tables are typically joined using data that they have in common Join conditions can be specified in either the FROM or WHERE clauses; specifying them in the FROM clause is recommended. WHERE and HAVING clauses can also contain search conditions to further filter the rows selected by the join conditions.

Joins can be categorized as:

Inner joins - (the typical join operation, which uses some comparison operator like = or <>). An inner join is a join in which the values in the columns being joined are compared using a comparison operator Inner joins use a comparison operator to match rows from two tables based on the values in common columns from each table.

Equi Join - It returns all the columns in both tables, and returns only the rows for which
there is an equal value in the join column ( SELECT * FROM authors AS a INNER JOIN
publishers AS p ON a.city = p.city ORDER BY a.au_lname DESC )

Self Join - A table can be joined to itself in a self-join

Outer joins - Outer joins can be a left, right, or full outer join. Outer joins are specified with one of the following sets of keywords when they are specified in the FROM clause:

LEFT JOIN or LEFT OUTER JOIN - The result set of a left outer join includes all the rows from the left table specified in the LEFT OUTER clause, not just the ones in which the joined columns match. When a row in the left table has no matching rows in the right table, the associated result set row contains null values for all select list columns coming from the right table.

RIGHT JOIN or RIGHT OUTER JOIN - A right outer join is the reverse of a left outer join. All rows from the right table are returned. Null values are returned for the left table any time
a right table row has no matching row in the left table.

FULL JOIN or FULL OUTER JOIN - A full outer join returns all rows in both the left and right tables. Any time a row has no match in the other table, the select list columns from the other table contain null values. When there is a match between the tables, the entire result set row contains data values from the base tables.
Cross joins - Cross joins return all rows from the left table, each row from the left table is combined with all rows from the right table. Cross joins are also called Cartesian products.
 

Dot Net - Pros & Cons Copyright © 2011 - |- Template created by O Pregador - |- Powered by Blogger Templates