-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshowstatus.sql
More file actions
34 lines (27 loc) · 833 Bytes
/
Copy pathshowstatus.sql
File metadata and controls
34 lines (27 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
-- tudo sobre a tabela
EXEC sp_help 'tb_produtos'
-- lista de colunas e tipos
SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, IS_NULLABLE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'tb_produtos';
-- chave primaria da tabela
EXEC sp_pkeys 'tb_pedidos'
-- chave estrangeira da tabela
EXEC sp_fkeys 'tb_produtos'
-- ver todas as tabelas do banco de dados em orderm crescente
SELECT name
FROM sys.tables
ORDER BY name ASC;
-- ver todas as tabelas do banco de dados em orderm decrescente
SELECT name
FROM sys.tables
ORDER BY name DESC;
-- ver a distribuiçao de valores (ex: por cidade ou estado)
SELECT cidade, COUNT (*) AS total
FROM tb_enderecos
GROUP BY cidade
ORDER BY total DESC;
SELECT uf, COUNT (*) AS total
FROM tb_enderecos
GROUP BY uf
ORDER BY total DESC;