Exclusively for you!! Trial version of Google Apps, Apply Coupon-CNHPGX6T6QRWGV!!

Few lines about SQL Use statement

Database @Image courtesy of ddpavumba/ FreeDigitalPhotos.net

Few lines about SQL Use statement

Welcome to CodeSpread!

We see this statement in Management Studio now and then and it is used quite extensively. For Example,

USE MyDatabaseName


MyDatabaseName : MyDatabaseName is the name of the database that we want to connect with.

How it works?

When we login to SQL Server, we automatically gets connected to the default database. It runs under the security context of current database user. In condition of no default database user for the SQL Server login, the login connects as guest.

We sometimes receive an error that ‘…login does not have sufficient permissions..’. Here,If the current user does not have CONNECT permission on the database, the USE statement will fail.

So, It is required to have CONNECT permission for the target database.


  • If the target database is not defined, then it is by default set to master.
  • USE is executed at both compile and execution time and takes effect immediately.

Author: hershey

A passion for knowledge drives me to do programming, A passion for programming drives me to create something different, A passion for creation drives me to spread the knowledge.

Share This Post On


  1. nice superb explaination

    Post a Reply
  2. thanks for the tutorial
    I am having a problem.
    The feature “Create SQL server database” isn’t available , I can’t select it.
    Can you help, please ?

    Post a Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

More from CodeSpread:

  • Questions related to Connection Pooling in .NET Questions related to Connection Pooling in .NET What is Connection Pooling in .NET? Here, the term connection refers to connecting to a data source and Pooling means grouping together of resources. So, Connection + Pooling means grouping toget...
  • SQL:Target a SubQuerySQL:Target a SubQueryPeople ask me a lot about subquery so I thought let’s answer with a article touching a bit of everything about subquery. Before discussing SubQuery, there are few things which we should know lik...
  • IDENTITY as SQL Property and IDENTITY as SQL FunctionIDENTITY as SQL Property and IDENTITY as SQL FunctionIDENTITY as SQL Property: Almost all the time, We have a table with a primary key and would like to insert a new value automatically in the primary key field. To achieve this, We have IDENTITY ...
  • SQL: Common Table Expression called CTESQL: Common Table Expression called CTEI remember somebody talked about CTE or Common Table Expression with me and tried helplessly to make me understand it. Honestly, I listened very peacefully but was not able to figure out the exact ...
  • SQL:My first SSIS PackageSQL:My first SSIS PackageI would like to share my experience about a situation, where I was given a task to export a file(say XML) from FTP location and get the data from this file populated into our database tables. Moreo...
  • Transact-SQL : Try-Catch BlockTransact-SQL : Try-Catch BlockSimilar to exception-handling features of .Net, T-SQL code provides a TRY-CATCH block. It is one of the implicit features of T-SQL and a famous error handling technique to catch errors. A TRY-CA...
  • Verify existence of SQL tables using Object_ID()Verify existence of SQL tables using Object_ID()Why Object_ID() ? Let’s create a SQL table “Employee” [code] CREATE TABLE Employee ( [EmployeeID] [int] IDENTITY(1,1) PRIMARY KEY, [EmployeeName] [varchar](50) NULL, [Salary] [int] NUL...
  •  SQL Formatting standards – Capitalization, Indentation, Comments, Parenthesis SQL Formatting standards – Capitalization, Indentation, Comments, Parenthesis A post by guest author Milena Petrovic Nobody likes to read a wall of text, even when it’s just plain text. When it comes to reading code, the problem is even bigger. Code can have different for...