DBA Júnior Laboratórios Extra Hugo Torralbo hugo@nervinformatica.com.br 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
Windows Server 2 2
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 3
Prática: Instalação Windows 2008 R2 4 4
Prática: Instalação Windows 2008 R2 5 5
Prática: Instalação Windows 2008 R2 6 6
Prática: Instalação Windows 2008 R2 7 7
Prática: Instalação Windows 2008 R2 8 8
Prática: Instalação Windows 2008 R2 9 9
Prática: Instalação Windows 2008 R2 10 10
Prática: Instalação Windows 2008 R2 11 11
Prática: Instalação Windows 2008 R2 12 12
Prática: Instalação Windows 2008 R2 13 13
Prática: Instalação Windows 2008 R2 14 14
Prática: Instalação Windows 2008 R2 15 15
Prática: Particionamento e Filesystem 16 16
Prática: Particionamento e Filesystem 17 17
Prática: Particionamento e Filesystem 18 18
Prática: Particionamento e Filesystem 19 19
Prática: Particionamento e Filesystem 20 20
Prática: Particionamento e Filesystem 21 21
Prática: Particionamento e Filesystem 22 22
Prática: Particionamento e Filesystem 23 23
Prática: Particionamento e Filesystem 24 24
Prática: Particionamento e Filesystem 25 25
Prática: Particionamento e Filesystem 26 26
Prática: Particionamento e Filesystem 27 27
Prática: Particionamento e Filesystem 28 28
Prática: Particionamento e Filesystem 29 29
Prática: Particionamento e Filesystem 30 30
Prática: Services 31 31
Prática: Services 32 32
Prática: Services 33 33
Prática: CMD 34 34
Prática: CMD C:\Users\Administrator> cd.. C:\Users> cd Adm<TAB> C:\Users\Administrator> cd \ C:\> mkdir teste C:\> dir C:\> cd teste C:\teste> notepad teste.txt Escreva algo no arquivo e salve-o. C:\teste> copy teste.txt teste02.txt C:\teste> more teste02.txt C:\teste> type teste02.txt C:\teste> cd.. C:\> dir C:\> xcopy teste C:\> dir C:\> del teste.txt C:\> help 35 35
Prática: CMD C:\Users\Administrator> NET STOP Spooler C:\Users\Administrator> NET START Spooler C:\Users\Administrator> HOSTNAME C:\Users\Administrator> TASKLIST C:\Users\Administrator> DISKPART DISKPART> LIST DISKPART> LIST DISK DISKPART> EXIT 36 36
Prática: Programação BAT C:\> set MEUDIRETORIO=C:\teste C:\> set C:\> 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:\teste dir %MEUDIRETORIO% C:\teste> REN teste02.txt teste.bat C:\teste> teste.bat Acrescente esta linha no final do arquivo teste.bat e salve-o. teste C:\teste> teste.bat O que aconteceu? 37 37
Prática: Agendamento de Tarefas Abra o Task Scheduler. Start -> Administrative Tools -> Task Scheduler Em Create Basic Task, crie um agendamento para executar diariamente o programa teste.bat. 38 38
Prática: Usuários, Grupos, Domínios 39 39
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 40
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 41
Teoria: Documentação / Livros Documentação Windows Server http://technet.microsoft.com/en-us/library/bb625087.aspx Livro Windows Internals http://technet.microsoft.com/en-us/sysinternals/bb963901.aspx 42 42
Teoria: Certificações / Mercado de Trabalho - Microsoft Certified Solutions Associate (MCSA) - Microsoft Certified Solutions Expert (MCSE) - Microsoft Certified Solutions Master (MCSM) 43 43
SQL Server 44 44
Teoria: Versões e Edições Edições - Compact - Developer - Express - Standard - Business Intelligence - Enterprise Versões 1.0 (OS/2) 1989 SQL Server 1.0 1.1 (OS/2) 1991 SQL Server 1.1 4.21 (WinNT) 1993 SQL Server 4.21 6.0 1995 SQL Server 6.0 6.5 1996 SQL Server 6.5 7.0 1998 SQL Server 7.0 8.0 2000 SQL Server 2000 8.0 2003 SQL Server 2000 64-bit Edition 9.0 2005 SQL Server 2005 10.0 2008 SQL Server 2008 10.5 2010 SQL Server 2008 R2 11.0 2012 SQL Server 2012 45 45
Prática: Instalação SQL Server 46 46
Prática: Instalação SQL Server 47 47
Prática: Instalação SQL Server 48 48
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 49
Prática: Instalação SQL Server 50 50
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 ServerManager PS C:\Users\Administrator> Add-WindowsFeature as-net-framework Reexecute o programa setup. 51 51
Prática: Instalação SQL Server 52 52
Prática: Instalação SQL Server 53 53
Prática: Instalação SQL Server 54 54
Prática: Instalação SQL Server 55 55
Prática: Instalação SQL Server 56 56
Prática: Instalação SQL Server 57 57
Prática: Instalação SQL Server 58 58
Prática: Instalação SQL Server 59 59
Prática: Instalação SQL Server 60 60
Prática: Instalação SQL Server 61 61
Prática: Instalação SQL Server 62 62
Prática: Instalação SQL Server 63 63
Prática: Instalação SQL Server 64 64
Prática: Instalação SQL Server 65 65
Prática: Instalação SQL Server 66 66
Prática: Instalação SQL Server 67 67
Prática: Instalação SQL Server 68 68
Prática: Instalação SQL Server 69 69
Prática: Instalação SQL Server 70 70
Prática: Serviços 71 71
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 -e 1> sp_who 2> 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 72
Teoria: Arquitetura 73 73
Prática: Parâmetros Instância No SSMS, clique com o botão direito na instância e selecione Properties. 74 74
Prática: Parâmetros Instância 75 75
Prática: Parâmetros Instância 76 76
Prática: Parâmetros Instância 77 77
Prática: Parâmetros Instância 78 78
Prática: Parâmetros Instância 79 79
Prática: Parâmetros Instância 80 80
Prática: Parâmetros Instância 81 81
Prática: Banco de Dados 82 82
Prática: Banco de Dados 83 83
Prática: Parâmetros Banco de Dados 84 84
Prática: Parâmetros Banco de Dados 85 85
Prática: Modos de Proteção Simple Recovery Model Bulk-logged Recovery Model Full Recovery Model Altere o modo de Proteção do banco de dados que você criou para Full. 86 86
Teoria: Estruturas físicas File Group Primary data files Secondary data files Log files Logical File Name OS File Name 87 87
Teoria: Estruturas lógicas Database File Group (Tablespace) Schema Objects (Tables, Indexes, Views, Procedures, Functions, Triggers, etc.) 88 88
Prática: Segurança User Login Roles 89 89
Teoria: Query, DML, DDL, DCL DDL (Data Definition Language) CREATE ALTER DROP TRUNCATE DCL (Data Control Language) GRANT REVOKE DML (Data Manipulation Language) SELECT INSERT UPDATE DELETE TCL (Transaction Control Language) COMMIT SAVEPOINT ROLLBACK SET TRANSACTION 90 90
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 91
Teoria: Procedures Criação USE Nerv; GO CREATE PROCEDURE uspgetemployeename @EmployeeID int AS SET NOCOUNT ON; SELECT Name FROM Employee WHERE EmployeeID = @EmployeeID; GO Execução USE Nerv; EXECUTE uspgetemployeename @EmployeeID = 1 GO 92 92
Teoria: Functions Criação USE Nerv; GO CREATE FUNCTION NumberOfEmployees (@DeptID int) RETURNS @TotalOfEmployees int AS BEGIN DECLARE @TotalOfEmployees AS int ; SELECT @TotalOfEmployees = SUM(EmployeeID) FROM Employee WHERE DeptID = @DeptID; RETURN @TotalOfEmployees; END; GO Execução SELECT * FROM NumberOfEmployees (2) GO 93 93
Teoria: Triggers Criação USE Nerv; CREATE TRIGGER Reminder ON Dept AFTER INSERT, UPDATE AS RAISERROR ('Notify Manager', 16, 10); GO 94 94
Prática: PK, FK, Unique, Check, NOT NULL PK CREATE TABLE Employee (EmployeeID int PRIMARY KEY CLUSTERED, EmpName nvarchar(100), DeptID int); FK CREATE TABLE Employee (EmployeeID int, EmpName nvarchar(100), DeptID int REFERENCES Dept(DeptID); UNIQUE CREATE TABLE Employee (EmployeeID int PRIMARY KEY, EmpName nvarchar(100) NONCLUSTERED, DeptID int); CHECK CREATE TABLE Employee (EmployeeID int CHECK (EmployeeID >= 1), EmpName nvarchar(100), DeptID int); NOT NULL CREATE TABLE Employee (EmployeeID int, EmpName nvarchar(100) NOT NULL, DeptID int); Combine todos estes recursos em seu banco de dados de testes. 95 95
Prática: INSERT, UPDATE, DELETE, SELECT Exemplos INSERT 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 96
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 TRANSACTION UPDATE... GO O que aconteceu? 97 97
Prática: Activity Monitor Pressione Control + Alt + A Esta 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 98
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 99
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 100
Prática: Error Log 101 101
Prática: Error Log 102 102
Teoria: Alta Disponibilidade Backup e Restore Log Shipping Database Mirroring (async e sync) AlwaysOn Failover Cluster AlwaysOn Availability Group (async e sync) 103 103
Teoria: Documentação / Livros Livros SQL Server Internals http://www.red-gate.com/community/books/index SQL Server Blogs http://technet.microsoft.com/en-us/sqlserver/bb671052.aspx 104 104
Teoria: Certificações / Mercado de Trabalho Atuais Microsoft 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) Antigos MCTS: SQL Server 2008, Implementation and Maintenance MCTS: SQL Server 2008, Database Development MCTS: SQL Server 2008, Business Intelligence Development and Maintenance MCITP: Database Administrator 2008 MCITP: Database Developer 2008 MCITP: Business Intelligence Developer 2008 Microsoft Certified Master (MCM) Microsoft Certified Architect (MCA) MCTS: SQL Server 2005 MCTS: Microsoft SQL Server 2005, Business Intelligence Development MCITP: Database Developer on SQL Server 2005 MCITP: Database Administrator on SQL Server 2005 MCITP: Business Intelligence Developer on SQL Server 2005 Microsoft Certified Database Administrator SQL Server 2000 105 105