Tuesday, January 24, 2012

SQL SELECT QUERY

Sql have Several Query for interect with Database.

Select Query is one of the most important Query here we will see the different Uses of Select Query.

* To simply select the all Datas from Database Table

 select  *  from table_name


 above statements select all the  rows from Data Table.

* To count just number of rows(all)  from table  


select count(*) from table_name 


above query count all the rows from given table

* now if you want count distinct rows from table you have to specify distinct word before count key word
like 


select  count( distinct  column_name) from table_name 


above query  remove duplication from count result .

* Use select method to insert data from one table to another table 


insert into tbl_insert_table (first_column , last_column)
select first_value , last_value from tbl_select_table 

Monday, January 23, 2012

How to connect SQL Server using Server Explorer

Here we will see to connect SQL server using Server Explorer

First of all when you have created any project suppose named as "DEMO" 


Now as per given below click
-> click on View  ->  Server Explorer





 you can create the  database right from within Visual Studio 2005. First, if Server Explorer is not visible select View, Server Explorer from the menu as . Now right Click on Data Connections, and pick “Add Connection…”.

Note do NOT pick the Create New SQL Server Database… option, this works with full blown SQL Server such as SQL Server Express.
Here on the next screen you can see that you have to choose Data Source ..
choose the "Microsoft SQL Server" click continue 
now after choosing the  Data Source 
on the next screen as you can see below here Data Source which you have entered by using   change button you can select othe Data Source .

Now In the Server  Name Dropdown box select your server name and as you can see the next panel that is "Log on to Server" there are given two modes windows authentication and SQl Server Authentication .

if you want use or create Database in your machine locally you have to select windows authentication and in the case you want connect remote server select the SQL Server Authentication here you have to specify the remote server User Name or Password .

next you have to specify the Your Database Name here our database name "Demo"




Returning to the Server Explorer, your new database (which I named Demo) should be listed in your Data Connections tree. Click the + button to expand, and you can see the Tables, System Views (not to be confused with a traditional database view), and a Replication folder.

Note that if you wanted to open an existing  database, you’d simply skip the steps associated with the Create button. Instead you’d simply pick “Add Connection…”, key in (or browse for) the database name, enter the password and click Open.


How to Connect Sql Server using web.config file



Hi Everyone who newly to MS SQL Server. Here I have described Various Mathods to connect with SQL server to use it various Functionality.

1) Using Web.Config File  in your Visual Studio

As you create your project in Visual Studio you will find web.config file It is a good practice to store the connection string for your application in a config file rather than as a hard coded string in your code. The way to do this differs between .NET 2.0 and .NET 3.5 (and above). This article cover booth.

Connection string in .NET 2.0 config file
In the appSettings location, add a key named whatever you like to reference your connection string to.
<appSettings>
<add key="myConnectionString" value="server=localhost;database=myDb;uid=myUser;password=myPass;" />
</appSettings>
To read the connection string from code, use the ConfigurationSettings class.
string connStr = ConfigurationSettings.AppSettings("myConnectionString");
Now you have the connection string loaded from web.config into your string variable in code.

Connection string in .NET 3.5 (and above) config file
Do not use appsettings in web.config. Instead use the connectionStrings section in web.config.
<connectionStrings>
<add name="myConnectionString" connectionString="server=localhost;database=myDb;uid=myUser;password=myPass;" />
</connectionStrings>
To read the connection string into your code, use the ConfigurationSettings class.
string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;

Sql Introduction


Hi ! Wel Come to Sql Discussion Blog.

This is Discussion or Debate Blog on SQL for spreading knowledge for basic fundamentals of SQL Database.
Here Everyone can share their knowledge on Sql by discussion forum .


SQL is a standard language for accessing and manipulating databases which stands for Structured Query Language.


SQL is a Common Language for variety Databases for accessing the Data from DataBase.

The Heart of any Database is the RDBMS.

RDBMS stands for Relational Database Management System.
RDBMS is the basis for SQL, and for all modern database systems like MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access.
The data in RDBMS is stored in database objects called tables.
A table is a collection of related data entries and it consists of columns and rows.