Friday, March 22, 2013

Create a SQL Login User in SQL Server 2008


This article will give a walkthrough on creating a SQL Login user. 

Step 1
Login to SQL Server 2008 instance using windows authentication
Image1.gif

Step 2

Right click on server instance name and select properties.
Image2.gif


Step 3

Property window will be open. In that select the Security tab.
Image3.gif

In server authentication tab you can see your SQL Server in configured for 
  1. Windows authentication mode
  2. SQL Server and Windows Authentication mode
So if you want to enable SQL User login to SQL Server then select checked mixed mode here .
Image4.gif

And then click ok. Now SQL Server is configured for mixed mode login. 

Step 4

Now to create SQL LOGIN, right click on Security tab and select New and then Login .
Image5.gif

Step 5

When you click on Login you will get the below window
Image6.gif

Give the Login Name
Image7.gif

Select SQL Server Authentication and provide your desired password
Image8.gif

Disable Enforce password policy
Image9.gif

Select default database
Image10.gif

Leave default language and click OK to create a new SQL Server login 

Now in object explorer you can see User1 login .
Image11.gif

Now at time of connecting to SQL Server login User1 can be used. 

Wednesday, March 20, 2013

SQL SERVER – Retrieve SQL Server Installation Date Time


I have been asked this question a number of times and my answer always has been “Search online and you will find the answer.” Every single time someone follows my answer, he finds the accurate answer in just a few clicks. However, this question is getting very popular nowadays, so I decided to answer this question through a blog post.

I usually prefer creating my own T-SQL script but in today’s case, I have taken the script from the Web. I have seen this script in so many places that I do not know who the original creator is, so I’m not sure who should get credit for the script.

Question: How do I retrieve SQL Server Installation date?
Answer: Run the following query and it will give you the date of SQL Server Installation.

SELECT create_date
FROM sys.server_principals
WHERE sid = 0x010100000000000512000000

Question: I have installed SQL Server Evaluation version. How do I know what is the expiry date for it?
Answer: SQL Server evaluation period lasts for 180 days. The expiration date is always 180 days from the initial installation. The following query will give the expiration date of evaluation version:

-- Evaluation Version Expire DateSELECT create_date AS InstallationDate,DATEADD(DD, 180, create_date) AS 'Expiry Date'FROM sys.server_principals
WHERE sid = 0x010100000000000512000000
GO

I believe there is a way to do this using registry, but I have not explored it personally. Now as what I’ve said earlier, there are many different blog posts on this subject. Let me list a few which I really enjoyed to read as they shared a few more insights about this subject:

Reference: Pinal Dave (http://blog.sqlauthority.com)

What is Optimistic Locking ?

Optimistic Locking is 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 (i.e. different version to yours), then you abort the transaction and the user can re-start it.
(Read more here http://bit.ly/sql-interview)