Handout 2 - Introduction To SQL Server
Handout 2 - Introduction To SQL Server
Haramaya University
College of Computing and Informatics
RECOMMENDED TEXTS:
We are using SQL Server 2000 – the current version. Previous versions are SQL Server 6.5
and SQL Server 7.0 – you are most likely to see 7.0 & 2000 in use.
Page 1 of 6
655445332.doc FBE – Computer Science Dept
1. A Client sends a request to the server – e.g. to view some data, or run a query.
2. The server carries out the request – the server does the work of retrieving the data or
executing the query.
3. The server then returns the result set to the client.
This way of doing things means that the client does not have to be a very high spec pc – it
just has to display the data.
The server installation includes the relational database engine and the physical storage of the
database.
Many databases can be stored on one server – the number of databases is limited by the
amount of disk space on the server.
Page 2 of 6
655445332.doc FBE – Computer Science Dept
When installed on a client PC, the SQL Server client tools include software that is used to
connect to the database server and a set of interfaces to allow you to view what is on the
server and to retrieve and store data from/into a database.
On the client computer, click Start -> Programs -> Microsoft SQL Server.
You should have the following items:
Books OnLine
Enterprise Manager
Query Analyzer
(There may be more items in the group, but these are the ones we will be using for now.)
Books OnLine – if this is installed, it is a good resource for help & information about SQL
Server and SQL commands. Be aware that some of the information about the SQL language
may apply only to SQL Server.
Enterprise Manager – this is your interface to see what databases are on the server and what
tables, views etc and data are in the database. It is also an interface for carrying out database
management/administration tasks.
Query Analyzer – this is the tool you use to write and run SQL queries against any database
on the server (as long as you have permissions to the database). It can also be used to run
database management/administration tasks.
When you start up the Enterprise Manager or the Query Analyzer, your PC makes a
connection to the SQL Server server over the client-server network.
If the Client Tools have been newly-installed on your PC, there will be no servers registered.
To register a server:
- Right-click and select New SQL Server Registration
- Check the box From now on I want to perform this task without using the wizard
(we will try to get to know the interface without using wizards all the time)
- This will bring up the Registered SQL Server Properties dialog box
- Click the ‘…’ box to view a list of available servers – select fbe-Server2 and click
OK
- [If fbe-server2 is not in the list, click Cancel and then type fbe-server2 into the
Server text box]
- Leave the default of Use Windows Authentication selected for the Connection.
- Leave the Options at their defaults – these are:
Page 3 of 6
655445332.doc FBE – Computer Science Dept
o Server Group – if there are multiple SQL Servers in a network, you can
organise them into groups e.g. Production Servers and Test Servers
o Display SQL Server state in console – choose if you want to see the state
of the server
o Automatically start SQL Server when connecting – to start up the SQL
Server (on the server) if it not already started when you connect
- Click OK
- You will see the fbe-server2 server under the SQL Server Group node
The Enterprise Manager is the main console for management of the DBMS. The interface is
displayed as a tree-like structure, with several nodes in a hierarchical structure:
Console Root (the top level)
Microsoft SQL Servers (this console can be used to manage other MS servers, such
as web servers)
SQL Server Group (there can be more than one group of servers)
Server (there can be more than one server registered)
Databases
Data Transformation Services
Management
Replication
Security
Support Services
Meta Data Services
Page 4 of 6
655445332.doc FBE – Computer Science Dept
1.2.3 Databases
System dbs – these are always present: master, model, msdb – these contain system
information that the DBMS engine uses. Master is used by SQL Server to monitor
the state of the system – it records information about the databases on the server,
server logins and other information about various database objects. It represents the
database schema or catalog. Model is a template used when you create a new
database. MSDB is used by the SQL Server Agent service (a scheduling application,
which we will look at later in the course). These databases should not be deleted.
Sample dbs – northwind, pubs – these are supplied with SQL Server as demo
applications. You can view these, but try not to change them – as, if you make a
change, it is changed on the server so it is changed for everyone. On a production
server, these can be deleted if the disk space is required.
TempDB – this is another system database, and should not be deleted or changed. It
is used by SQL Server as a temporary storage area e.g. during the execution of a
query.
User databases – any databases we have created on the server will also appear here.
SQL Server can be used to run one or many databases. It is capable of handling
1000’s of user connections at any one time (although this may be constrained by other
factors such as the capacity of the network in which the server is installed).
1.2.4 Management
This is where you can carry out database administration/management tasks such as
scheduling jobs to run at regular times, creating backups of databases, viewing logs and
database activity.
We will look at some of these functions later in the course.
1.2.5 Security
This is where you can create and modify database logins and assign permissions to those
logins.
We will look at the area of database security later in the course.
Page 5 of 6
655445332.doc FBE – Computer Science Dept
The objects in the database are grouped into the following types:
Diagrams – you can create and save a diagram showing some or all of the tables in the db,
and the relationships between them. You can make changes to the relationships on the
diagram (note that if you make a change, it will change the database on the server, so be
careful of what you change).
Tables – shows the tables in the database; can also view and modify the design for the
tables.
Views – shows the views in the database; a view is defined as a select query on one or
more tables – once created, a view can be used like a table. So we can say it is a virtual
table.
Stored Procedures – a stored procedure is a group of T-SQL statements saved and
compiled by SQL Server into an execution plan. A stored procedure can receive
parameters (inputs) and produce output to return to whatever called it.
Users – a database can only be accessed by valid users. A database user is either a
Windows account or a SQL Server user that has been granted access to a particular
database.
Roles – a database role applies to a single database only; it consists of Windows accounts.
Rules – a rule is the same as a CHECK constraint. We will use CHECK constraints rather
than rules, as this is the preferred way of doing this in SQL Server 2000. A rule or check
constraint is used to check that the value entered in a table column is valid e.g. must be
between 0 and 100 for an integer field.
Defaults – a default value for a field specifies what value to put in a table column if no
value is specified for that column when a row is inserted into the table. The preferred way
to do this is to specify the default when the table is created, using the SQL DEFAULT
keyword. We will use this method.
User Defined Types – it is possible to create custom data types for table columns. A user-
defined type is based on the system data-types (integer, char etc – we will cover these in a
later class).
User Defined Functions – the T-SQL language includes many built-in functions. It is also
possible to create custom functions, using T-SQL, that can be called like any other
function when writing T-SQL scripts.
Full-text Catalogs – these are used for searching character fields in the database.
Page 6 of 6