Created
February 11, 2020 05:11
-
-
Save dungdm93/4fd6612c9408b65612f5beb1e0ca8da7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Show all databases | |
SELECT | |
database_id, | |
name, | |
create_date | |
FROM sys.databases; | |
--or using Stored Procedure | |
EXEC sp_databases; | |
-- Switch database | |
USE AdventureWorks; | |
-- Check current db name | |
SELECT DB_NAME(); | |
-- List all tables of current db | |
SELECT | |
TABLE_NAME, | |
TABLE_SCHEMA | |
FROM INFORMATION_SCHEMA.TABLES; | |
-- List all columns of given table | |
SELECT | |
ORDINAL_POSITION, | |
TABLE_NAME, | |
COLUMN_NAME, | |
DATA_TYPE, | |
CHARACTER_MAXIMUM_LENGTH, | |
IS_NULLABLE, | |
COLUMN_DEFAULT | |
FROM INFORMATION_SCHEMA.COLUMNS | |
WHERE TABLE_NAME = 'Product'; | |
SELECT CONSTRAINT_NAME, TABLE_NAME, TABLE_SCHEMA, CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA | |
FROM INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE | |
WHERE TABLE_NAME = 'Product'; | |
sp_help 'SalesLT.Product'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment