--Aula 01 - Usando SQLCMD
CREATE DATABASE DB2778
GO
USE DB2778
GO
CREATE TABLE clientes
(
cod_cli INT IDENTITY PRIMARY KEY,
nome_cli CHAR(50) NOT NULL,
sexo_cli CHAR(01),
datanasc_cli DATETIME,
numfilhos_cli TINYINT,
status_cli CHAR(01), --0 Inativo 1 Ativo
email_cli VARCHAR(100),
cid_cli CHAR(30)
)
GO
SET NOCOUNT ON
INSERT INTO clientes VALUES
('Adriana de Oliveira', 'F', '1959-10-13', 1, '1','adrianao@people.com.br', 'Brasília'),
('Adriana Souza', 'F', '1960-08-17', 2, '1','adrianas@people.com.br', 'São José dos Campos'),
('Adriano Ferreira', 'M', '1949-06-20', 0, '1','adriano@people.com.br', 'Cajamar'),
('Aguinaldo da Silva', 'M', '1932-05-21', 3, '1','aguif@people.com.br', 'Taubaté'),
('Alberto Francisco', 'M', '1948-03-23', 4, '1','alberto@people.com.br', 'São Paulo'),
('Alessandra dos Santos', 'F', '1950-01-03', 0, '1','alesantos@people.com.br', 'Brasília'),
('Alex Santos', 'M', '1983-10-05', 1, '1','alexs@people.com.br', 'Taubaté'),
('Ana Carla de Freitas', 'F', '1985-12-07', 1, '1','acarla@people.com.br', 'São Paulo'),
('Ana Maria de Souza', 'F', '1992-10-09', 2, '1','amaria@people.com.br', 'São José dos Campos'),
('Bruna Luiza', 'F', '1993-09-10', 1, '1','brunal@people.com.br', 'Taubaté'),
('Carlos Alberto', 'M', '1975-08-13', 2, '0','carlosa@people.com.br', 'Cajamar'),
('Daniel de Paula', 'M', '1977-06-14', 0, '1','danielp@people.com.br', 'Taubaté'),
('Edna dos Santos', 'F', '1961-05-16', 0, '1','ednal@people.com.br', 'Taubaté'),
('Felipe Lopes', 'M', '1962-03-17', 1, '1','felipep@people.com.br', 'São Paulo'),
('Gilberto Marques', 'M', '1968-01-19', 2, '1','gilbertom@people.com.br', 'São Paulo'),
('Heloisa da Silva', 'F', '1977-11-21', 1, '1','heloisas@people.com.br', 'Brasília'),
('Isa de Lima', 'F', '1980-09-22', 1, '1','isal@people.com.br', 'São Paulo'),
('Janaina Aparecida', 'F', '1982-08-25', 1, '1','janainal@people.com.br', 'Cajamar'),
('Lilian de Souza', 'F', '1986-07-27', 2, '0','lilians@people.com.br', 'Taubaté'),
('Marcia Lima', 'F', '1988-10-27', 3, '1','marcial@people.com.br', 'São José dos Campos'),
('Tatiana Matias', 'F', '1993-07-28', 2, '1','tatianam@people.com.br', 'São José dos Campos')
INSERT clientes (nome_cli, sexo_cli, datanasc_cli, numfilhos_cli)
VALUES ('Viviane Souza Gomes', 'F', '1996-06-30', 1)
SELECT * FROM clientes
-- Conectando via SQLCMD
SQLCMD –S DBSERVER1\SQLINSTANCE1
-- Verificando o nome da instância em uso
SELECT CONVERT(VARCHAR(25),SERVERPROPERTY('SERVERNAME')) AS [INSTANCE]
GO
-- Logando com previlégios administrativos
-- DAC - Dedicated Administrator Connection
SQLCMD –A
SHUTDOWN WITH NOWAIT
GO
--********************************************************
-- script_01.sql
--********************************************************
SELECT @@SERVERNAME
GO
SELECT @@VERSION
GO
SELECT TOP 3 NAME FROM master..sysdatabases
GO
--********************************************************
sqlcmd -E -i f:\script_01.sql
--********************************************************
--********************************************************
-- script_02.sql
--********************************************************
SELECT TOP $(tcount) name FROM sys.databases
--********************************************************
sqlcmd -E -i f:\script_02.sql -v tcount = 10
--********************************************************
--********************************************************
-- script_03.sql
--********************************************************
SELECT name FROM sys.databases
--********************************************************
SQLCMD -E -i f:\script_03.sql -o f:\output_01.txt
--********************************************************
--********************************************************
-- script_04.sql
--********************************************************
SELECT name
FROM $(db).dbo.sysobjects
WHERE xtype = 'U'
--********************************************************
sqlcmd -E -i c:\script_04.sql -v db = "AdventureWorks"
--********************************************************
Nenhum comentário:
Postar um comentário