Showing posts with label Ms SQL Server. Show all posts
Showing posts with label Ms SQL Server. Show all posts

Tuesday, August 27, 2013

How do you select random rows in MsSQL Server?

SELECT TOP 10 *
FROM <TableName>
ORDER BY NEWID();

Thursday, March 14, 2013

How could you import or export bulk data in SQL Server?

Import/Load data:
bcp itinerary.dbo.tariff in "C:\mobile\itinerary.txt" -N -S <ServerName/IP> -U <userid> -P <password> -T

Export/Extract Data:
bcp itinerary.dbo.tariff out "C:\fruit\inventory.txt" -c -S <ServerName/IP> -U <userid> -P <password> -T -h "TABLOCKX"

What is the maximum number of columns in a row in SQL Server?

1024 columns.

How many columns per SELECT statement are possible in SQL Server?

4096

What are the types of temp tables in Ms SQL Server?

1. Local Temp Table
Table prefixed with a single hash (#) denotes a local temporary table available to the current connection for the user. It disappears when the user disconnects.

CREATE TABLE #tempLocal ( Uid int, Fname varchar(50), Lname varchar(50) )

2. Global Temp Table
Table prefixed with double hash (##) denotes a global temporary table available to all users via all connections. They are deleted only when all connections are closed.

CREATE TABLE ##tempGlobal ( Uid int, Fname varchar(50), Lname varchar(50) )

What is the maximum no. of SPROC nesting in Ms SQL Server?

The maximum level of SPROC nesting is 32.

Which TCP/IP port does Ms SQL Server run on?

Ms SQL Server runs on port 1433.

How could you select top N records in Ms SQL Server?

SELECT TOP N * FROM <TableName>

Or

SELECT TOP N PERCENT <Column_01>, <Column_02>
FROM <TableName>
WHERE <Condition>

Or

( For SQL Server 7.0 or earlier )
SET ROWCOUNT N
SELECT <Column_01>, <Column_02>, <Column_03>
FROM <TableName>
ORDER BY <Column_Name> DESC

Wednesday, August 1, 2012

What is the maximum number of Index per table in MS SQL Server?

For SQL Server 2005:
 1 Clustered Index + 249 Nonclustered Index = 250 Index
For SQL Server 2008:
 1 Clustered Index + 999 Nonclustered Index = 1000 Index