dba júnior laboratórios extra -...

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

Upload: dothien

Post on 02-Dec-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

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

Windows Server

2 2

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

4

Prática: Instalação Windows 2008 R2

4

5

Prática: Instalação Windows 2008 R2

5

6

Prática: Instalação Windows 2008 R2

6

7

Prática: Instalação Windows 2008 R2

7

8

Prática: Instalação Windows 2008 R2

8

9

Prática: Instalação Windows 2008 R2

9

10

Prática: Instalação Windows 2008 R2

10

11

Prática: Instalação Windows 2008 R2

11

12

Prática: Instalação Windows 2008 R2

12

13

Prática: Instalação Windows 2008 R2

13

14

Prática: Instalação Windows 2008 R2

14

15

Prática: Instalação Windows 2008 R2

15

16

Prática: Particionamento e Filesystem

16

17

Prática: Particionamento e Filesystem

17

18

Prática: Particionamento e Filesystem

18

19

Prática: Particionamento e Filesystem

19

20

Prática: Particionamento e Filesystem

20

21

Prática: Particionamento e Filesystem

21

22

Prática: Particionamento e Filesystem

22

23

Prática: Particionamento e Filesystem

23

24

Prática: Particionamento e Filesystem

24

25

Prática: Particionamento e Filesystem

25

26

Prática: Particionamento e Filesystem

26

27

Prática: Particionamento e Filesystem

27

28

Prática: Particionamento e Filesystem

28

29

Prática: Particionamento e Filesystem

29

30

Prática: Particionamento e Filesystem

30

31

Prática: Services

31

32

Prática: Services

32

33

Prática: Services

33

34

Prática: CMD

34

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

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

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

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

39

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

39

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

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

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

43

Teoria: Certificações / Mercado de Trabalho

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

43

SQL Server

44 44

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

46

Prática: Instalação SQL Server

46

47

Prática: Instalação SQL Server

47

48

Prática: Instalação SQL Server

48

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

50

Prática: Instalação SQL Server

50

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

52

Prática: Instalação SQL Server

52

53

Prática: Instalação SQL Server

53

54

Prática: Instalação SQL Server

54

55

Prática: Instalação SQL Server

55

56

Prática: Instalação SQL Server

56

57

Prática: Instalação SQL Server

57

58

Prática: Instalação SQL Server

58

59

Prática: Instalação SQL Server

59

60

Prática: Instalação SQL Server

60

61

Prática: Instalação SQL Server

61

62

Prática: Instalação SQL Server

62

63

Prática: Instalação SQL Server

63

64

Prática: Instalação SQL Server

64

65

Prática: Instalação SQL Server

65

66

Prática: Instalação SQL Server

66

67

Prática: Instalação SQL Server

67

68

Prática: Instalação SQL Server

68

69

Prática: Instalação SQL Server

69

70

Prática: Instalação SQL Server

70

71

Prática: Serviços

71

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

73

Teoria: Arquitetura

73

74

Prática: Parâmetros Instância

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

74

75

Prática: Parâmetros Instância

75

76

Prática: Parâmetros Instância

76

77

Prática: Parâmetros Instância

77

78

Prática: Parâmetros Instância

78

79

Prática: Parâmetros Instância

79

80

Prática: Parâmetros Instância

80

81

Prática: Parâmetros Instância

81

82

Prática: Banco de Dados

82

83

Prática: Banco de Dados

83

84

Prática: Parâmetros Banco de Dados

84

85

Prática: Parâmetros Banco de Dados

85

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

87

Teoria: Estruturas físicas

File Group Primary data files Secondary data files Log files

Logical File Name OS File Name

87

88

Teoria: Estruturas lógicas

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

88

89

Prática: Segurança

User Login Roles

89

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

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

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

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

94

Teoria: Triggers

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

94

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

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

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

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

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

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

101

Prática: Error Log

101

102

Prática: Error Log

102

103

Teoria: Alta Disponibilidade

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

103

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

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