Tuesday, December 4, 2007

How do you select Top 3 records from your database

How do you select Top 3 records from your database

    Step 1

    To select top 3 records from all you need to do is issue this command in SQL Analyzer

    Select top 3 * from employees

    Step 2

    You can use a number to denote the number of records to return or percentage to do it.

    Select top 30 percent * from employees

    An example of screen layout is shown below:

    Edited By:Melanie Michael Jominin

© 2001 ISC/Inner Esteem

All rights reserved. All other product names and trademarks are registered properties of their respective owners.

301001

How to find the status and information of connected servers in your MSSQL Server

How to find the status and information of connected servers in your MSSQL Server

Step 1

To find the information of servers connected to MS SQL Server, go to SQL Analyzer and then issue the following command

Exec sp_helpserver

It will reveal status of servers and replication connected to MS SQL Server.

What is the difference between a remote server and a linked server

What is the difference between a remote server and a linked server

Remote Server is recognized and use by SQL server for replication task. Link Server are registered SQL Server from another machine.

How do I pass Query to Linked Server

How do I pass Query to Linked Server

Step 1

To pass query to linked server, user can choose to use this command

SELECT * FROM jaguar.northwind.dbo.employees

Or

SELECT *

FROM OPENQUERY(jaguar, 'SELECT * FROM northwind.dbo.employees')

GO

in SQL Analyzers

Both of these command will return data results from a linked server called Jaguar.

How to add Linked Server to MS SQL Server

How to add Linked Server to MS SQL Server

Step 1

User can add a linked server by using SQL Analyzer with the following command

exec sp_addlinkedserver 'JAGUAR', 'SQL Server'

This will add a linked server with the name jaguar (running on MS SQL Server) to MS SQL Server.

What is SQL Profiler

What is SQL Profiler

SQL Profiler allow you to create one or more template to monitor your database

How to view MS SQL Logs

How to view MS SQL Logs

Step 1

To view MS SQL logs, go to Enterprise Manager and choose Management .After that select SQL Server Logs

A list of logs written by SQL server will be display on your right hand side.

How do I create a trace statement in SQL Profiler

How do I create a trace statement in SQL Profiler

Step 1

To create a trace statement in SQL Profiler, go to Start ,choose Programs then select Microsoft SQL Server. After that click on Profiler

Step 2

When a new window appear choose File and select New Trace or CTRL+N

Another window will appear

Step 2

Verify the username and password is valid .Then click OK to continue.

Step 3

We will call this trace TestDemo. Under the Trace Name, enter TestDemo.

Then click on Events tab.

We will now determine which database Event we would like to handle. Here we perform tracing on TSQL transactions.

Step 4

Click OK.

The newly created trace would report a list of transaction that involve BEGIN TRANS, COMMIT, SAVE and ROLLBACK status.

How to kill processes

How to kill processes

Step 1

To kill a process go to Enterprise Manager and select Management ,after that choose Process

Step 2

Then right click on a process that you wanted to kill. When the menu popup, click on Kill Process

How to check on current activity

How to check on current activity

Step 1

To check on current activity in MSSQL server, go to Enterprise Manager nad select Management

An example of the layout is illustrated below:

From here, user can get information on current activity that is related to Processes, Lock/Process ID and Lock Objects.

To view more information on it just clicks on each of the component here.

How to assign Database Access to user

How to assign Database Access to user

Step 1

To assign database access to user, view go to Enterprise Manager, select the database that you would like to assign a particular user into. Expand it and go to Users.

Selecting New Database User is not creating a new user to your database but merely assign list of users that you have already created to a particular database.

Then a window will appear prompting user to provide list of names

How to create a new user

How to create a new user

Step 1

To create a new user in your database, go to Enterprise Manager and select the Security folder. Then right click on Login

Then another new window will appear.

Step 2

Under the name, create a user call Demo_admin. As for the authentication choose SQL Server Authentication.

Step 3

Choose Demo as the default database.

Step 4

Click on Server Roles tab and choose System Administrators

Step 5

User can actually assign which database that this particular user has access to in the Database Access tab.

Step 6

For this section we will choose only Demo database and the access roles we will set it to db_owner. Click Ok when done.

How to create a view

How to create a view

Step 1

To create a view go to Enterprise Manager, select the database that your view would reside and then right click on view

Then another window will appear

Step 2

Click on Add Table and another window appear. Here you need to select Employees table and click on Add

Step 3

Select Employees table and click on Add

Step 4

Under the Column choose Employee_id and then for its criteria enter the value 2.

Step 5

Notice that the SQL query will change accordingly.

Click on the red exclamation mark to run it.

Step 6

To save your View just click on the floppy icon on your top left hand side.

How to work with views

How to work with views

View provide a logical representation of data in your database. If interconnects data from various tables that might have multiple table.

Monday, December 3, 2007

How to delete a column with T-SQL

How to delete a column with T-SQL

Step 1

To drop a column from your table use back the good old ALTER TABLE command. The following command will remove CreditCard column from your table called Employee.

USE DEMO

ALTER TABLE EMPLOYEE DROP COLUMN CREDITCARD

Step 2

After you press F5 you column will be removed.

How to alter table to add a new column with T-SQL

How to alter table to add a new column with T-SQL

Step 1

Altering table can be done by using ALTER TABLE command. The command below will add a new column into your EMPLOYEE table with a datatype varchar and size 20.

USE DEMO

ALTER TABLE EMPLOYEE ADD CREDITCARD VARCHAR(20)

Step 2

Switch to SQL Analyzer and then enter the following command before pressing F5.

Your table will have a new column called CreditCard.

How to alter a table in MS SQL Server

How to alter a table in MS SQL Server

Step 1

To alter a table in MSSQL, go to Enterprise Manager, expand Database folder and then select Table. Right after that select the table that you would like to modify as show in the diagram below.

Another window will appear.

From here user can change their database structure.

How to create Tables in SQL Server

How to create Tables in SQL Server

Step 1

To create a table in SQL Server 2000, go to Enterprise Manager, expand Databases and then select a database that you want your table to reside.

Expand it and right click to make the menu popup. There select New Table

Step 2

The another window will appear. Then enter the appropriate field name and data type.

In this example we are trying to create an employee table with Employee name set to varchar(50) and EmployeeID to char(10).

How do I use Data Transformation package

How do I use Data Transformation package

    Step 1

    To create a data transformation package go to Enterprise Manager, expand the Data Transformation Services and choose Local Package

    Then DTS package will appear as show in the diagram below. We will try to construct a simple DTS package that will prompt user a message upon success.

    Step 2

    First of all we need to create a Microsoft Access Connection. You can set it to any database that you might have. The configuration might look something like this.

    Step 3

    Then we create another connection, this time a SQL OLEDB connection.

    We will set to import data to be place on a table in Demo database. The configuration for our second connection look like this

    Step 4

    After that we need to define the Transform Task properties indicated by the black arrow line.

    Double click on it and then a windows similar to the one shown below will appear. We are trying to import Department table from our access database to table also called Department SQL Server database

    The source tab look like the one show below :

    Step 5

    Next click on Destination tab. Just click on Create in the table name.

    Step 6

    Then user can click on Transformation tab to check the fields that will be imported over.

    Step 7

    Click OK when done.

    Step 8

    We will now create an Active X object. Just drag from the toolbox that is located on your left hand side.

Step 9

Inside the textbox, key in the following Vbscript MSGBOX("HEY YOU DID IT")

Step 10

Click on Ok when done.

Step 11

Then hold down your CTRL key and click on our OLEDB provide and the Active X object.

Step 12

Then link them by selecting Workflow and the click on On Success. That means that if you process is successful it will trigger a messagebox saying that you did it.

The completed diagram look like the one show below:

Step 13

When you run it, you will see this message appearing.

What are the different data type available in MS SQL Server

What are the different data type available in MS SQL Server

There are 2 news datatypes available in MSSQL server 2000 which are bigint and sql_variant.

Other data types available in MSSQL.

Binary

Bigint

bit

Char

datetime

Decimal

Float

image

Int

Money

Nchar

Ntext

nvarchar

Numeric

Real

Smalldatetime

smallint

smallmoney

sql_variant

sysname

Text

timestamp

tinyint

varbinary

varchar

Uniqueidentifier

How to delete an index

How to delete an index

Step 1

If user would like to delete an index in Dmo database and then right click Employee table. When a popup menu appear, go to All task and then select Manage Index

Then another new window will appear as indicated below:

Step 2

From here choose the index that you would like to remove and click on Delete.

How to view Indexing within your database

How to view Indexing within your database

Step 1

To view index within your database, just open Enterprise Manager. Then select the database that you wish to work with.

Step 2

Choose Northwind and then right click on it and choose View then click on Task Pad

Step 3

After that, select Table Info Tab and a list of information on indexes will appear.

How to manage index

How to manage index

Step 1

Go to Enterprise manager, expand your database. In this case we are using Demo database and then right click Employee table that we have created earlier. When a popup menu appear, go to All task and then select Manage Index

Then another new window will appear as indicated below:

Step 2

To edit your Indexes, click on Edit. This will lead you to another windows as shown below:

Step 3

In this example we will modify the fill factor to 85. Just click on Fill factor and set the value to 85.

How to create index in your table

How to create index in your table

Step 1

To create an index in your table, open Enterprise Manager and then under Tools choose Wizard.

A new window will appear and then choose Create Index Wizard

Step 2

Create Index wizard will appear

Step 3

Click Next to continue

Step 4

We will set the Demo as the database and Employee as the tablename. Click Next to continue.

Step 5

Check on Employee_id to include it in index. Click Next to continue.

We will create a cluster index here.

Step 6

Fill factor determine the maximum value before extending it into another page. We will choose Optimal and then click on Next to continue.

Step 7

We will keep this as Employee_Index_1 and click Finish to complete it.

What are the types of indexing available in MSSQL 2000

What are the types of indexing available in MSSQL 2000

Cluster index is an index that stored by MSSQL in a B-tree format whereby the parent tree contains references to the child below it and it is particularly useful in storing value with a range of values.

Full text indexes are used to search complex stream of strings effectively and efficiently that cannot be created for multiple database, that means multiple database cannot share a full text indexes.

How to delete the connected Server from your group

How to delete the connected Server from your group

Step 1

To delete connected servers in your group, go to Enterprise Manager and expand your group of servers. Then select JAGUAR and right click on it and choose Delete SQL Server Registration.

Step 2

The server will prompt you whether you wanted to remove it. Click Yes.

How to connect to another SQL Server in your network

How to connect to another SQL Server in your network

Step 1

To register another MS SQL Server, go to your SQL Server and right click on it.

Then another popup menu will appear. From here choose New SQL Server Registration.

Then register SQL Server Wizard will appear

Step 2

Click on Next to continue. We will attempt to connect to a server called JAGUAR.

Step 3

Add it into Added Server column and click Next to continue.

Step 4

Click Next to continue.

Step 5

Accept the default and click Next to continue.

Step 6

Click on Finish to let SQL Server Wizard to find and add this server into your group of SQL Servers.

Then your Enterprise Manager would look something like this.