Lab 2 DBS
Lab 2 DBS
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 Installation Centre is used for the installation of new Instances,
Installation
Up gradating and Updating the SQL Server.
Centre
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 defines
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'
Operators Allowed in the WHERE Clause
With the WHERE clause, the following operators can be used:
Operator Description
= Equal
IN If you know the exact value you want to return for at least one of the columns
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:
For the table in task 2, generate a query for updating the table with fully qualified names and
update the following values: