SQL Server Basic Queries

Simple Sql Server Queries From the basics :

create database temp

/* creation of database */

use temp

/* use of database */

create table temp1(id int,names varchar(20))

/* creation of table */

select *from temp1

/* selection of table data */

create table temp2(age int,addres nvarchar(20))

select *from temp2

delete temp2

/* deletes only table data */

drop table temp2

/* remove the table from database */

insert into . . . → Read More: SQL Server Basic Queries

Basic Queries in T-SQL

Like PL/SQL in oracle T-SQL(Transact SQL) in SQL server

Examples for simple queries

create database tsql

use tsql

1.declaring variables ,set values to those and print

declare @x int,@name varchar(50),@date datetime

set @x=10

set @name=‘hari’

set @date=getdate()

print @x

print @name

print @date

output :

. . . → Read More: Basic Queries in T-SQL

How to import data from excel/csv file to sql server

1.Import data from excel to sql server using openrowset command.

Example : import.xls

Suppose  if  the  excel  is  present  in  ur d  drive. Execute the following query to import the data.

select * into excelfile from openrowset(‘Microsoft.Jet.OLEDB.4.0′,

‘Excel 8.0;Database=d:\import.xls’, [Sheet1$])

/* The above query creates table excelfile and inserts the data . . . → Read More: How to import data from excel/csv file to sql server

Find n th highest salary -sql queries

Q) TOP N Analysis Query without using Analytical Functions

- Analytical Functions are not supported in some previous versions of Database .Analytical functions like ‘Dense_Rank’ ,’Rank’ etc are not used in this example to make the query more general .

This . . . → Read More: Find n th highest salary -sql queries