Anda di halaman 1dari 5

SQL SERVER

Microsoft SQL Server is a Relational Database Management System (RDBMS) .SQL Server comes in
many editions, few are free and few are paid versions. Most of the versions provide the basic services
like

SQL server 2005

• SQL Server database engine - create, store, update and retrieve your data
• SQL Server Management Studio Basic - visual database management tool for creating,
editing and managing databases
• Full-text Search - powerful, high-speed engine for searching text-intensive data
• Reporting Services - integrated report creation and design environment to create reports
• Management Studio Express [SSMSE]: GUI for your database instance

We can use a combination of these features and tools to discover trends and patterns that exist in your
data, and then use the trends and patterns to make intelligent decisions about difficult business
problems.
SQL Server 2005 Express Edition

INSTALLATION

The SQL Server 2005 Installation Wizard is Microsoft Windows Installer-based, and provides a single
feature tree for installation of all Microsoft SQL Server 2005 components:

• SQL Server Database Engine


• Analysis Services
• Reporting Services
• Notification Services
• Integration Services
• Management Tools
• Documentation and Samples

ACCESSING

Go to Start > All Programs > Microsoft SQL Server > SQL Server Management Studio Express >
Server Name\SQL Express > Connect

The default databases created along with the server installation are as follows:

• Master: Stores system level information such as user accounts, configuration settings, and info
on all other databases.
• Model: Used as a template for all other databases that are created.
• Msdb: Used by the SQL Server Agent for configuring alerts and scheduled jobs etc
• tempdb: Holds all temporary tables, temporary stored procedures, and any other temporary
storage requirements generated by SQL Server.

CREATE DATABASE

• Right click on the "Databases" icon and select "New Database” displayed in the Object
Explorer,
• Name the database and click on ok button,
• New db appears under "Databases" section of SQL Server Management Studio which is based
on the “Model" database,
• We can use left pane to navigate to your database and expand the tree,
• Our new data base will already contains a number of objects like system functions,
• System views, system stored procedures, and (hidden) system tables.

CREATE TABLE

Ensure that the right database is expanded ,right click on the "Tables" icon and select "New Table”
• While you have this screen open, do the following:
• Using the values in the screenshot, complete the details in the "Column Name" column, the
"Data Type" column, "Length" column, and "Allow Nulls" column.
• Make the Individual ID column an "identity column", by setting "Is Identity" to "Yes" (this
option is under the "Identity Specification" section in the bottom pane).
• Set the "Default Value" of the DateCreated column to (getdate()) which will automatically insert
the current date into that field for each new record
• Save the table by selecting File > Save Table_1:
• Name your table when prompted
• Newly created table will appear under your database in the "Tables" section.

EDIT ROWS
We can use the "Edit Top 200 Rows" option to add data to our table to enter/change the data
directly in the table

DISADVANTAGES OF DIRECT ENTRY

The above mentioned method is fine to create/modify small amount of data but in case of large chunks
of data, multiple environments (eg.a development , staging , and production environment), with
duplicate databases configured in each environment, you will need to re-enter the same data into each
environment.

BETTER METHOD
Its more efficient to write a SQL script. Using a script enables you to re-enter the data as many times as
you like. If you need to rebuild your database for any reason, you can simply run your script to enter
the data. If you have multiple environments, once again you can run your script against each
environment.

SQL SCRIPTS

Create a New Query


click the "New Query" button to write a SQL query against our database .This interface can be used to
create database objects (such as databases, tables, views etc), insert data into a database table, select
data, update data, delete data.
To run an SQL query:
1. Type your query into the workspace on the right pane
2. Click "Execute" (you can also press F5)
The results of the query are displayed in the bottom pane.
SAMPLE QUERIES

SQL is divided into two main categories; Data Manipulation Language (DML), and Data Definition
Language (DDL).

DML: Data Manipulation Language

• SELECT - INSERT - UPDATE - DELETE

DDL: Data Definition Language

• CREATE DATABASE - ALTER DATABASE - DROP DATABASE - CREATE TABLE -


ALTER TABLE - DROP TABLE

Sample Queries

DML
SELECT * FROM TableName : To retrieve all columns from a table called TableName.
SELECT * FROM Table1, Table2 WHERE tablename.columnname = ‘criteria’: To retrieve
data from two tables simultaneously according on criteria based.
SELECT * FROM table_name WHERE column_name = 'criteria'
SELECT * FROM TableName ORDER BY columnname : by default ascending order
SELECT * FROM TableName ORDER BY columnname DESC : by descending order
SELECT * FROM TableName ORDER BY columnname1, columnname2
SELECT TOP 3 * FROM TableName : to retrieve top 3 rows
SELECT TOP 40 PERCENT * FROM TableName : to get a percentage of the result set
SELECT TOP 40 PERCENT * FROM TableName ORDER BY ColumnName DESC
SELECT DISTINCT(ColumnName) FROM Individual : to get the number of unique values

Etc…..

DDL
ALTER TABLE table_name ADD column_name datatype
ALTER TABLE table_name ALTER COLUMN column_name datatype
ALTER TABLE table_name DROP COLUMN column_name

Etc….

Query Designer:
It’s a GUI that allows to build complex queries to run against your SQL Server database. The query
designer generates the SQL for us.
To build a query with the query designer:
• Select Query > Design Query in Editor
• Add the tables you want to run the query against.
• Select the column/s you want to display in your query:
• Click "OK"
We can find the query has been added to our workspace and can then run it as you would any other
query.

CREATE INDEX
Create Index against a table to make searches more efficient by enabling the database application to
find data quickly without having to scan the whole table.

CREATE INDEX index_name ON table_name (column_name)

Views, Stored Procedures etc…..

Still Lot More….:)


Mallika & Venny