background image

Laboratorium Baz Danych 

Wykonał: 

Wojciech Ćwikliński 

Laboratorium:   

Prowadzący: 

dr inż. Andrzej Sikorski 

Data: 7.10.2013 

Kierunek: ETI 

 

Ad. 5) Utworzenie nowego użytkownika 

use CJDate 
create login wojt with password='www' 
create user wojt for login wojt 
grant control to wojt 

 

Ad. 7) Skonfigurowanie zapory Windows, zezwolenie dostępu dla TCP na porcie 1433.  

 

 

Po wykonaniu tego punktu mogłem zalogować się do bazy danych kolegi obok. Należało wpisać 
zamiast gwiazdki jego numer IP, zmienić „Windows Authentication” na „Server Authentication”  
i podać jego nazwę oraz hasło użytkownika.  

   

Ad. 11) Wykonanie kopii bezpieczeństwa. 

backup database CJDate to disk = 'c:\bd\CJDate.bak' 
restore filelistonly from disk = 'c:\bd\CJDate.bak' 
restore database CJDate from disk = 'c:\bd\CJDate.bak' 
 
backup database Northwind to disk = 'c:\bd\Northwind.bak' 
backup database Northwind  
 

to disk = 'c:\bd\CJDate.bak' 

 

WITH INIT; 

GO 

background image

backup database Northwind to disk = 'c:\bd\Northwind.bak' 
backup database Northwind  
 

to disk = 'c:\bd\CJDate.bak' 

 

WITH DIFFERENTIAL; 

GO 
 
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

background image

 

Laboratorium Baz Danych 

Wykonał: 

Wojciech Ćwikliński 

Laboratorium: 

Prowadzący: 

dr inż. Andrzej Sikorski 

Data: 14.10.2013 

Kierunek: ETI 

 

Ad. 1) 

create login wojt with password='www'  
create user wojt for login wojt  
EXEC sp_addsrvrolemember 'wojt', 'sysadmin' 
 

Ad. 2) 

Zainstalowałem bazę Adventure Works 

Ad.3) 

use Northwind 

A.  select Lastname, Firstname from Employees 
B.  select * from Employees where not country = 'USA' 
C.  select * from [Order Details] where OrderID = '10625' 
D.  select Quantity * UnitPrice from [Order Details] where OrderID = '10625' 
E.  select Quantity * UnitPrice * (1-Discount) from [Order Details] where OrderID = '10625' 

select MAX(Discount) from [Order Details] 

 

Ad.4) 

Utworzyłem nową bazę danych. 

Ad.5) 

A.  select count(*) from S 
B.  select count(*) from S where city = 'London' 
C.  select count(*) from S group by CITY 
D.  select count(*) from S where [STATUS] > 10 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

background image

Laboratorium Baz Danych 

Wykonał: 

Wojciech Ćwikliński 

Laboratorium: 

Prowadzący: 

dr inż. Andrzej Sikorski 

Data: 21.10.2013 

Kierunek: ETI 

 

Ad.10) 

Uruchomienie prostego kodu w Javie 

public class Test1 { 
/** 
* @param args 
*/ 
public static void main(String[] args) { 
// TODO Auto-generated method stub 
System.out.println("Hej! Umiem juz programować w Javie!"); 

 

Ad.11) 

 

import java.sql.*; 
import com.microsoft.sqlserver.jdbc.*; 
 
public class connectDS { 
 
 

public static void main(String[] args) { 

 

 

 

 

 

// Declare the JDBC objects. 

 

 

Connection con = null; 

 

 

CallableStatement cstmt = null; 

 

 

ResultSet rs = null; 

 

 

 

 

 

try { 

 

 

 

// Establish the connection. 

 

 

 

SQLServerDataSource ds = new SQLServerDataSource(); 

 

 

 

ds.setUser("wojt"); 

 

 

 

ds.setPassword("www"); 

 

 

 

ds.setServerName("localhost"); 

 

 

 

ds.setPortNumber(1433); 

 

 

 

ds.setDatabaseName("CJData"); 

 

 

 

con = ds.getConnection(); 

 

 

 

 

 

         

// Execute a stored procedure that returns some data. 

               

cstmt = con.prepareCall("select*from SPJ"); 

               

cstmt.setInt(1, 50); 

               

rs = cstmt.executeQuery(); 

 
 

         

// Iterate through the data in the result set and display it. 

 

         

while (rs.next()) { 

 

               

System.out.println("EMPLOYEE: " + rs.getString("LastName") + 

 

               

 

", " + rs.getString("FirstName")); 

 

               

System.out.println("MANAGER: " + rs.getString("ManagerLastName") + 

 

               

 

", " + rs.getString("ManagerFirstName")); 

background image

 

               

System.out.println(); 

 

         

 

        } 

 

         

 

 

// Handle any errors that may have occurred. 

 

     

catch (Exception e) { 

 

     

 

e.printStackTrace(); 

 

     

 
 

    

finally { 

 

     

 

if (rs != null) try { rs.close(); } catch(Exception e) {} 

 

     

 

if (cstmt != null) try { cstmt.close(); } catch(Exception e) {} 

 

     

 

if (con != null) try { con.close(); } catch(Exception e) {} 

 

     

 


 

 

Ad.12) 

select S# from SPJ where QTY=(select max(QTY) from SPJ) 
select max(QTY) from SPJ 
select S# from SPJ where QTY =800 
select s# from SPJ where QTY=(select MAX(QTY) from SPJ) 
 
declare @max int 
select @max=max(qty) from SPJ 
select * from SPJ where qty = @max 

 

 Zadania z Laboratorium 3x 

Ad. 1) 

create login wojt with password='www' 
create user wojt for login wojt 
use Northwind 
grant select to wojt 
use CJDate 
grant control to wojt 
 

Ad.2) 

select  * from [Order Details], Orders 
where Orders.OrderID=[Order Details].OrderID 
 

Następnie zastosowaliśmy polecenie: 

Select YEAR(OrderDate),[Order Details].OrderID,ProductID, Quantity, UnitPrice, Discount from [Order Details], 
Orders where Orders.OrderID=[Order Details].OrderID 
 
select count(*) from [Order Details]