DBA_JR

105
DBA Júnior Laboratórios Extra Hugo Torralbo [email protected] Esta obra está licenciada sob a licença Creative Commons Atribuição-SemDerivados 3.0 Brasil. Para ver uma cópia desta licença, visite http://creativecommons.org/licenses/by-nd/3.0/br/. 1

description

Oracle básico

Transcript of DBA_JR

Page 1: DBA_JR

DBA JúniorLaboratórios Extra

Hugo [email protected]

Esta obra está licenciada sob a licençaCreative Commons Atribuição-SemDerivados 3.0 Brasil.

Para ver uma cópia desta licença, visite http://creativecommons.org/licenses/by-nd/3.0/br/.

1

Page 2: DBA_JR

Windows Server

2 2

Page 3: DBA_JR

3

Teoria: Versões e Edições

Versões - Windows NT 3.5 - Windows NT 4 - Windows 2000 Server - Windows Server 2003 - Windows Server 2003 R2 - Windows Server 2008 - Windows Server 2008 R2 - Windows Server 2012

Edições Windows 2012 - Foundation - Essentials - Standard - Datacenter

3

Page 4: DBA_JR

4

Prática: Instalação Windows 2008 R2

4

Page 5: DBA_JR

5

Prática: Instalação Windows 2008 R2

5

Page 6: DBA_JR

6

Prática: Instalação Windows 2008 R2

6

Page 7: DBA_JR

7

Prática: Instalação Windows 2008 R2

7

Page 8: DBA_JR

8

Prática: Instalação Windows 2008 R2

8

Page 9: DBA_JR

9

Prática: Instalação Windows 2008 R2

9

Page 10: DBA_JR

10

Prática: Instalação Windows 2008 R2

10

Page 11: DBA_JR

11

Prática: Instalação Windows 2008 R2

11

Page 12: DBA_JR

12

Prática: Instalação Windows 2008 R2

12

Page 13: DBA_JR

13

Prática: Instalação Windows 2008 R2

13

Page 14: DBA_JR

14

Prática: Instalação Windows 2008 R2

14

Page 15: DBA_JR

15

Prática: Instalação Windows 2008 R2

15

Page 16: DBA_JR

16

Prática: Particionamento e Filesystem

16

Page 17: DBA_JR

17

Prática: Particionamento e Filesystem

17

Page 18: DBA_JR

18

Prática: Particionamento e Filesystem

18

Page 19: DBA_JR

19

Prática: Particionamento e Filesystem

19

Page 20: DBA_JR

20

Prática: Particionamento e Filesystem

20

Page 21: DBA_JR

21

Prática: Particionamento e Filesystem

21

Page 22: DBA_JR

22

Prática: Particionamento e Filesystem

22

Page 23: DBA_JR

23

Prática: Particionamento e Filesystem

23

Page 24: DBA_JR

24

Prática: Particionamento e Filesystem

24

Page 25: DBA_JR

25

Prática: Particionamento e Filesystem

25

Page 26: DBA_JR

26

Prática: Particionamento e Filesystem

26

Page 27: DBA_JR

27

Prática: Particionamento e Filesystem

27

Page 28: DBA_JR

28

Prática: Particionamento e Filesystem

28

Page 29: DBA_JR

29

Prática: Particionamento e Filesystem

29

Page 30: DBA_JR

30

Prática: Particionamento e Filesystem

30

Page 31: DBA_JR

31

Prática: Services

31

Page 32: DBA_JR

32

Prática: Services

32

Page 33: DBA_JR

33

Prática: Services

33

Page 34: DBA_JR

34

Prática: CMD

34

Page 35: DBA_JR

35

Prática: CMDC:\Users\Administrator> cd ..C:\Users> cd Adm<TAB>C:\Users\Administrator> cd \C:\> mkdir testeC:\> dirC:\> cd testeC:\teste> notepad teste.txt

Escreva algo no arquivo e salve-o.

C:\teste> copy teste.txt teste02.txtC:\teste> more teste02.txtC:\teste> type teste02.txtC:\teste> cd ..C:\> dirC:\> xcopy testeC:\> dirC:\> del teste.txtC:\> help

35

Page 36: DBA_JR

36

Prática: CMD

C:\Users\Administrator> NET STOP SpoolerC:\Users\Administrator> NET START Spooler

C:\Users\Administrator> HOSTNAME

C:\Users\Administrator> TASKLIST

C:\Users\Administrator> DISKPARTDISKPART> LISTDISKPART> LIST DISKDISKPART> EXIT

36

Page 37: DBA_JR

37

Prática: Programação BATC:\> set MEUDIRETORIO=C:\testeC:\> setC:\> echo %MEUDIRETORIO%C:\> cd %MEUDIRETORIO%C:\teste> notepad teste02.txt

Deixe apenas estas duas linhas no arquivo teste02.txt e salve-o.set MEUDIRETORIO=C:\testedir %MEUDIRETORIO%

C:\teste> REN teste02.txt teste.batC:\teste> teste.bat

Acrescente esta linha no final do arquivo teste.bat e salve-o.teste

C:\teste> teste.batO que aconteceu?

37

Page 38: DBA_JR

38

Prática: Agendamento de TarefasAbra o Task Scheduler.Start -> Administrative Tools -> Task Scheduler

Em Create Basic Task, crie um agendamento para executar diariamente o programa teste.bat.

38

Page 39: DBA_JR

39

Prática: Usuários, Grupos, Domínios

39

Page 40: DBA_JR

40

Prática: Verificação de Desempenho

Inicie o Task Manager.Start, Run, taskmgr

Clique em Resource Monitor.Que informações o Resource Monitor possui, e o Task Manager não?

Inicie o Performance Monitor.Start -> Administrative Tools -> Performance Monitor

Adicione 5 contadores úteis ao Performance Monitor.

40

Page 41: DBA_JR

41

Prática: Event Viewer

Inicie o Event Viewer.Start -> Administrative Tools -> Event Viewer

Analisando o Event Viewer, quando o computador foi inicializado?

Analisando o Event Viewer, quando o segundo disco foi adicionado?

41

Page 42: DBA_JR

42

Teoria: Documentação / Livros

Documentação Windows Serverhttp://technet.microsoft.com/en-us/library/bb625087.aspx

LivroWindows Internals http://technet.microsoft.com/en-us/sysinternals/bb963901.aspx

42

Page 43: DBA_JR

43

Teoria: Certificações / Mercado de Trabalho

- Microsoft Certified Solutions Associate (MCSA) - Microsoft Certified Solutions Expert (MCSE) - Microsoft Certified Solutions Master (MCSM)

43

Page 44: DBA_JR

SQL Server

44 44

Page 45: DBA_JR

45

Teoria: Versões e EdiçõesEdições- Compact- Developer- Express- Standard- Business Intelligence- Enterprise

Versões1.0 (OS/2) 1989 SQL Server 1.01.1 (OS/2) 1991 SQL Server 1.14.21 (WinNT) 1993 SQL Server 4.216.0 1995 SQL Server 6.06.5 1996 SQL Server 6.57.0 1998 SQL Server 7.08.0 2000 SQL Server 20008.0 2003 SQL Server 2000 64-bit Edition9.0 2005 SQL Server 200510.0 2008 SQL Server 200810.5 2010 SQL Server 2008 R211.0 2012 SQL Server 2012

45

Page 46: DBA_JR

46

Prática: Instalação SQL Server

46

Page 47: DBA_JR

47

Prática: Instalação SQL Server

47

Page 48: DBA_JR

48

Prática: Instalação SQL Server

48

Page 49: DBA_JR

49

Prática: Instalação SQL Server

Habilite o Network Discovery.

Pressione a tecla F5 no ambiente de rede, até VBOXSRV aparecer.

Copie o instalador do SQL Server para a VM, e execute-o.

Após a finalização da extração, execute o programa setup.

49

Page 50: DBA_JR

50

Prática: Instalação SQL Server

50

Page 51: DBA_JR

51

Prática: Instalação SQL Server

Inicie o PowerShell.Start -> All Programs -> Acessories -> Windows PowerShell

Habilite o .Net 3.5.PS C:\Users\Administrator> Import-Module ServerManagerPS C:\Users\Administrator> Add-WindowsFeature as-net-framework

Reexecute o programa setup.

51

Page 52: DBA_JR

52

Prática: Instalação SQL Server

52

Page 53: DBA_JR

53

Prática: Instalação SQL Server

53

Page 54: DBA_JR

54

Prática: Instalação SQL Server

54

Page 55: DBA_JR

55

Prática: Instalação SQL Server

55

Page 56: DBA_JR

56

Prática: Instalação SQL Server

56

Page 57: DBA_JR

57

Prática: Instalação SQL Server

57

Page 58: DBA_JR

58

Prática: Instalação SQL Server

58

Page 59: DBA_JR

59

Prática: Instalação SQL Server

59

Page 60: DBA_JR

60

Prática: Instalação SQL Server

60

Page 61: DBA_JR

61

Prática: Instalação SQL Server

61

Page 62: DBA_JR

62

Prática: Instalação SQL Server

62

Page 63: DBA_JR

63

Prática: Instalação SQL Server

63

Page 64: DBA_JR

64

Prática: Instalação SQL Server

64

Page 65: DBA_JR

65

Prática: Instalação SQL Server

65

Page 66: DBA_JR

66

Prática: Instalação SQL Server

66

Page 67: DBA_JR

67

Prática: Instalação SQL Server

67

Page 68: DBA_JR

68

Prática: Instalação SQL Server

68

Page 69: DBA_JR

69

Prática: Instalação SQL Server

69

Page 70: DBA_JR

70

Prática: Instalação SQL Server

70

Page 71: DBA_JR

71

Prática: Serviços

71

Page 72: DBA_JR

72

Prática: Conexão

Inicie o Microsoft SQL Server Management Studio (SSMS).

Efetue logon com SQL Server Authentication, e com o usuário sa.O que deve ser colocado em Server Name?Como você pode se conectar no SQL Server do vizinho?

Clique em New Query.Na tela que se abrir, digite sp_who, e depois pressione F5.

Inicie o CMD.C:\Users\Administrator> sqlcmd -e1> sp_who2> go

Como você pode se conectar no SQL Server com sa via sqlcmd?Como você pode se conectar no SQL Server do vizinho via sqlcmd?C:\Users\Administrator> sqlcmd -?

72

Page 73: DBA_JR

73

Teoria: Arquitetura

73

Page 74: DBA_JR

74

Prática: Parâmetros Instância

No SSMS, clique com o botão direito na instância e selecione Properties.

74

Page 75: DBA_JR

75

Prática: Parâmetros Instância

75

Page 76: DBA_JR

76

Prática: Parâmetros Instância

76

Page 77: DBA_JR

77

Prática: Parâmetros Instância

77

Page 78: DBA_JR

78

Prática: Parâmetros Instância

78

Page 79: DBA_JR

79

Prática: Parâmetros Instância

79

Page 80: DBA_JR

80

Prática: Parâmetros Instância

80

Page 81: DBA_JR

81

Prática: Parâmetros Instância

81

Page 82: DBA_JR

82

Prática: Banco de Dados

82

Page 83: DBA_JR

83

Prática: Banco de Dados

83

Page 84: DBA_JR

84

Prática: Parâmetros Banco de Dados

84

Page 85: DBA_JR

85

Prática: Parâmetros Banco de Dados

85

Page 86: DBA_JR

86

Prática: Modos de Proteção

Simple Recovery Model Bulk-logged Recovery Model Full Recovery ModelAltere o modo de Proteção do banco de dados que você criou para Full.

86

Page 87: DBA_JR

87

Teoria: Estruturas físicas

File Group Primary data files Secondary data files Log files

Logical File Name OS File Name

87

Page 88: DBA_JR

88

Teoria: Estruturas lógicas

Database File Group (Tablespace) Schema Objects (Tables, Indexes, Views, Procedures, Functions, Triggers, etc.)

88

Page 89: DBA_JR

89

Prática: Segurança

User Login Roles

89

Page 90: DBA_JR

90

Teoria: Query, DML, DDL, DCLDDL (Data Definition Language)CREATEALTERDROPTRUNCATE

DCL (Data Control Language)GRANTREVOKE

DML (Data Manipulation Language)SELECTINSERTUPDATEDELETE

TCL (Transaction Control Language)COMMITSAVEPOINTROLLBACKSET TRANSACTION

90

Page 91: DBA_JR

91

Prática: Tabelas, Índices, Views

CREATE TABLE Employee (EmployeeID int, EmpName nvarchar(100), DeptID int);

CREATE TABLE Dept (DeptID int, DeptName nvarchar(100));

CREATE CLUSTERED INDEX IX_Employee ON Employee (EmployeeID);CREATE NONCLUSTERED INDEX IX_EmployeeName ON Employee (EmpName);

CREATE VIEW EmployeesList AS SELECT EmpName FROM Employee;

91

Page 92: DBA_JR

92

Teoria: Procedures

CriaçãoUSE Nerv;GOCREATE PROCEDURE uspGetEmployeeName @EmployeeID intAS SET NOCOUNT ON; SELECT Name FROM Employee WHERE EmployeeID = @EmployeeID;GO

ExecuçãoUSE Nerv;EXECUTE uspGetEmployeeName @EmployeeID = 1GO

92

Page 93: DBA_JR

93

Teoria: Functions

CriaçãoUSE Nerv;GOCREATE FUNCTION NumberOfEmployees (@DeptID int)RETURNS @TotalOfEmployees intAS BEGIN

DECLARE @TotalOfEmployees AS int ;SELECT @TotalOfEmployees = SUM(EmployeeID)FROM EmployeeWHERE DeptID = @DeptID;

RETURN @TotalOfEmployees;END;GO

ExecuçãoSELECT * FROM NumberOfEmployees (2)GO

93

Page 94: DBA_JR

94

Teoria: Triggers

CriaçãoUSE Nerv;CREATE TRIGGER ReminderON DeptAFTER INSERT, UPDATE AS RAISERROR ('Notify Manager', 16, 10);GO

94

Page 95: DBA_JR

95

Prática: PK, FK, Unique, Check, NOT NULL

PKCREATE TABLE Employee (EmployeeID int PRIMARY KEY CLUSTERED, EmpName nvarchar(100), DeptID int);

FKCREATE TABLE Employee (EmployeeID int, EmpName nvarchar(100), DeptID int REFERENCES Dept(DeptID);

UNIQUECREATE TABLE Employee (EmployeeID int PRIMARY KEY, EmpName nvarchar(100) NONCLUSTERED, DeptID int);

CHECKCREATE TABLE Employee (EmployeeID int CHECK (EmployeeID >= 1), EmpName nvarchar(100), DeptID int);

NOT NULLCREATE TABLE Employee (EmployeeID int, EmpName nvarchar(100) NOT NULL, DeptID int);Combine todos estes recursos em seu banco de dados de testes.

95

Page 96: DBA_JR

96

Prática: INSERT, UPDATE, DELETE, SELECT

ExemplosINSERT INTO Employee (EmployeeID, EmpName, DeptID)VALUES (1, 'Ricardo Portilho Proni', 1);

UPDATE Employee SET EmpName = 'Portilho' WHERE EmployeeID = 1;

DELETE FROM Employee WHERE EmployeeID = 2;

SELECT EmpName, DeptID FROM Employee WHERE EmployeeID = 1;

Execute INSERT de 10 registros, UPDATE de 2, DELETE de 2, e 2 SELECTs diferentes.

96

Page 97: DBA_JR

97

Prática: Transações e Isolamento

Execute um UPDATE de seu modelo de dados, em todas os registros da Employee.Abra outra sessão, e execute SELECT em todos os dados da tabela.O que aconteceu?

Repita a operação, mas antes do UPDATE, coloque como abaixo.

BEGIN TRANSACTIONUPDATE ...GO

O que aconteceu?

97

Page 98: DBA_JR

98

Prática: Activity Monitor

Pressione Control + Alt + AEsta visualização é similar a que outra ferramenta?

Execute novamente o cenário de concorrência, e observe o Activity Monitor.

Execute a procedure sp_who.Execute a procedure sp_who2.Qual a diferença das duas procedures?Que informações estas duas procedures possem do Activity Monitor?

98

Page 99: DBA_JR

99

Prática: Backup

Clique com o botão direito no banco de dados de testes, e execute um backup.

Execute o backup também via linha de comando.

BACKUP DATABASE Nerv TO DISK = 'C:\temp\Nerv.BAK'GO

BACKUP LOG Nerv TO DISK = 'C:\temp\Nerv.TRN'GO

99

Page 100: DBA_JR

100

Prática: Rotinas de Manutenção

No SSMS, clique em Management -> Maintenance Plans.Crie um Plano que faça um backup e valide a estrutura do banco de dados de teste.

100

Page 101: DBA_JR

101

Prática: Error Log

101

Page 102: DBA_JR

102

Prática: Error Log

102

Page 103: DBA_JR

103

Teoria: Alta Disponibilidade

Backup e Restore Log Shipping Database Mirroring (async e sync) AlwaysOn Failover Cluster AlwaysOn Availability Group (async e sync)

103

Page 104: DBA_JR

104

Teoria: Documentação / Livros

LivrosSQL Server Internalshttp://www.red-gate.com/community/books/index

SQL Server Blogshttp://technet.microsoft.com/en-us/sqlserver/bb671052.aspx

104

Page 105: DBA_JR

105

Teoria: Certificações / Mercado de TrabalhoAtuaisMicrosoft Certified Solutions Associate (MCSA)Microsoft Certified Solutions Expert - Data Platform (MCSE)Microsoft Certified Solutions Expert - Business Intelligence (MCSE)Microsoft Certified Solutions Master - Data Platform(MCSM)

AntigosMCTS: SQL Server 2008, Implementation and MaintenanceMCTS: SQL Server 2008, Database DevelopmentMCTS: SQL Server 2008, Business Intelligence Development and MaintenanceMCITP: Database Administrator 2008MCITP: Database Developer 2008MCITP: Business Intelligence Developer 2008Microsoft Certified Master (MCM)Microsoft Certified Architect (MCA)MCTS: SQL Server 2005MCTS: Microsoft SQL Server 2005, Business Intelligence Development MCITP: Database Developer on SQL Server 2005MCITP: Database Administrator on SQL Server 2005MCITP: Business Intelligence Developer on SQL Server 2005Microsoft Certified Database Administrator – SQL Server 2000

105