DBMS Lab # 03-04
DBMS Lab # 03-04
DBMS Lab # 03-04
Now using the following steps, install SQL Server 2000 in your PC’s.
Term Definition
Standard (x86 and SQL Server Standard is a complete data platform that
x64) provides ease of use and manageability. This includes built-in
business intelligence capabilities to run departmental
applications. For more information, see Features Supported
by the Editions of SQL Server 2008.
Server
Description
components
SQL Server SQL Server Database Engine includes the Database Engine, the core service
Database for storing, processing, and securing data, Replication, full-text search, and
Engine tools for managing relational and XML data.
Analysis Analysis Services includes the tools for creating and managing online
Services analytical processing (OLAP) and data mining applications.
Reporting Reporting Services includes server and client components for creating,
Services managing, and deploying tabular, matrix, graphical, and free-form reports.
Reporting Services is also an extensible platform that you can use to develop
report applications.
Integration Integration Services is a set of graphical tools and programmable objects for
Services moving, copying, and transforming data.
Management
Description
tools
SQL Server SQL Server Management Studio is an integrated environment to access,
Management configure, manage, administer, and develop components of SQL Server.
Studio Management Studio lets developers and administrators of all skill levels use
SQL Server. Internet Explorer 6 SP1 or a later version is required for
Management Studio installation.
SQL Server SQL Server Configuration Manager provides basic configuration
Configuration management for SQL Server services, server protocols, client protocols, and
Manager client aliases.
SQL Server
SQL Server Installation Centre is used for the installation of new Instances,
Installation
Up gradating and Updating the SQL Server.
Centre
To install Microsoft SQL Server 2008 Express Edition, follow these steps:
Run the setup file through the administrative account. The Microsoft SQL Server 2008
Installation Center will begin.
Now go to the Start menu and Search SQL Server Management Studio. A new window will be
opened. Connect to the server.
Now place the following sample code in the query window, run it and see the output:
On the left side you will see databases named master etc.
On clicking any of the database, you’ll see default tables in that database. You can also right
click on any of the table and select ‘return all rows’ to see the entire values in the table.
But you have to create your own database with your own name.
Now create the table in the above created database using the CREATE TABLE command:
Syntax:
CREATE
TABLE table_name (
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
....
); --// CREATE TABLE is the keyword.
SELECT *
FROM Student;
Number types:
float(n) Floating precision number data from -1.79E + 308 to 1.79E + 308. 4 or 8 bytes
sql_variant Stores up to 8,000 bytes of data of various data types, except text, ntext, and
timestamp
timestamp Stores a unique number that gets updated every time a row gets
created or modified. The timestamp value is based upon an internal
clock and does not correspond to real time. Each table may have only
one timestamp variable
SQL DML Commands
SQL can be divided into two parts: The Data Manipulation Language (DML) and the Data
Definition Language (DDL).
The query and update commands form the DML part of SQL:
• SELECT - extracts data from a database
• UPDATE - updates data in a database
• DELETE - deletes data from a database
• INSERT INTO - inserts new data into a database
The DDL part of SQL permits database tables to be created or deleted. It also define indexes
(keys), specify links between tables, and impose constraints between tables.
The second form specifies both the column names and the values to be inserted:
5 Tjessem Jakob
UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value
Note: Notice the WHERE clause in the UPDATE syntax. The WHERE clause specifies
which record or records that should be updated. If you omit the WHERE clause, all records
will be updated!
5 Tjessem Jakob
Now we want to update the person "Tjessem, Jakob" in the "Persons" table.
We use the following SQL statement:
UPDATE Persons
SET Address='Nissestien 67', City='Sandnes'
WHERE LastName='Tjessem' AND FirstName='Jakob'
UPDATE Persons
SET Address='Nissestien 67', City='Sandnes'
Note: Notice the WHERE clause in the DELETE syntax. The WHERE clause specifies
which record or records that should be deleted. If you omit the WHERE clause, all records
will be deleted!
Note: Be very careful when deleting records. You cannot undo this statement!
SQL SELECT Statement
The SELECT statement is used to select data from a database.The result is stored in a result
table, called the result-set.
The syntax used for SELECT query is:
SELECT column_name(s)
FROM table_name
and
SELECT * FROM table_name
Example
The "Persons" table:
Now we want to select the content of the columns named "LastName" and "FirstName" from
the table above.
We use the following SELECT statement:
Hansen Christ
Svendson Tove
Pettersen Michael
SELECT * Example
Now we want to select all the columns from the "Persons" table.
We use the following SELECT statement:
Example
The "Persons" table:
P_Id LastName FirstName Address City
Now we want to select only the distinct values from the column named "City" from the table
above.
We use the following SELECT statement:
SELECT DISTINCT City FROM Persons
Example
The "Persons" table:
P_Id LastName FirstName Address City
Now we want to select only the persons living in the city "Sandnes" from the table above.
We use the following SELECT statement:
This is correct:
SELECT * FROM Persons WHERE Year=1965 This is
wrong:
SELECT * FROM Persons WHERE Year='1965'
= Equal
IN If you know the exact value you want to return for at least one of the columns
The OR operator displays a record if either the first condition or the second condition is true.
Now we want to select only the persons with the first name equal to "Tove" AND the last
name equal to "Svendson":
We use the following SELECT statement:
SELECT * FROM Persons
WHERE FirstName='Tove'
AND LastName='Svendson'
OR Operator Example
Now we want to select only the persons with the first name equal to "Tove" OR the first
name equal to "Christ":
We use the following SELECT statement:
You can also combine AND and OR (use parenthesis to form complex expressions).
Now we want to select only the persons with the last name equal to "Svendson" AND the
first name equal to "Tove" OR to "Christ":
We use the following SELECT statement:
Example
The "Persons" table:
Now we want to select all the persons from the table above, however, we want to sort the
persons by their last name.
We use the following SELECT statement:
TASK 1:
Create the following table using SQL and using the INSERT INTO command, insert the
following values in the table created.
Name Reg_No Courses Course_Code Offered_By
Ikram 09 DIP
Hassan 10
TASK 2:
Using the UPDATE statement, update the above table for the following values:
Name Reg_No Courses Course_Code Offered_By
TASK 3:
Using the DELETE statement, delete the record for the student having name Akram and
Ahsan in the above table. Also delete the record for the course having course code=1001.
TASK 4:
Select distinct values from the above table for the last three columns.
TASK 5:
Sort the above table in descending order by their name.
TASK 6:
Create and delete any database while multiple users are using it with ROLLBACK
command.
TASK 7:
For the table in task 2, generate a query for updating the table with fully qualified names and
update the following values: