Exploring without light….

Slides:



Advertisements
Similar presentations
Tables Lesson 6. Skills Matrix Tables Tables store data. Tables are relational –They store data organized as row and columns. –Data can be retrieved.
Advertisements

Quick-and-dirty.  Commands end in a semi-colon ◦ If you forget, another prompt line shows up  Either continue the command or…  End it with a semi-colon.
FIRST COURSE Microsoft Access (Basics). XP Objectives Define the terms field, record, table, relational database, primary key, and foreign key. Learn.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Managing the Data SQL Overview. Client\Server RDMS (relational database management system) Client\Server RDMS (relational database management system)
1 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management.
1 Working with MS SQL Server II. 2 The sqlcmd Utility Command line utility for MS SQL Server databases. Previous version called osql Available on classroom.
SQL Basics. SQL SQL (Structured Query Language) is a special-purpose programming language designed from managing data in relational database management.
How a little code can help with support.. Chris Barba – Developer at Cimarex Energy Blog:
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
ASP.NET Programming with C# and SQL Server First Edition
Learningcomputer.com SQL Server 2008 – Introduction to Transact SQL.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
Eurotrace Hands-On The Eurotrace File System. 2 The Eurotrace file system Under MS ACCESS EUROTRACE generates several different files when you create.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Relational Databases Database Driven Applications Retrieving Data Changing Data Analysing Data What is a DBMS An application that holds the data manages.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals SELECT … FROM.
Said Salomon Unitrin Direct Insurance T-SQL for Beginners Said Salomon CODE CAMP
Module 5: Upgrading to SQL Server 7.0. Overview Planning an Upgrade Preparing to Upgrade Verifying the Upgrade Setting a Compatibility Level.
Metadata Metadata is information about data or other information.
Intro to SQL Management Studio. Please Be Sure!! Make sure that your access is read only. If it isn’t, you have the potential to change data within your.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
Database Management Supplement 1. 2 I. The Hierarchy of Data Database File (Entity, Table) Record (info for a specific entity, Row) Field (Attribute,
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Advanced SQL Equi-Join One-sided.
MySQL Quick Guide. Start and End MySQL MySQL is installed as a service. To start MySQL: –Control Panel/Administrative Tools/Services/MySQL/ start MySQL.
Database Basics BCIS 3680 Enterprise Programming.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
Jennifer Widom Relational Databases The Relational Model.
1 Working with MS SQL Server Beginning ASP.NET in C# and VB Chapter 12.
COMPREHENSIVE Access Tutorial 1 Creating a Database.
Advanced Database & Client Server Introduction to MS SQL Server 2000 and Transact SQL -
 What is DB Testing ?  Testing at the Data Access Layer  Need for Testing DB Objects  Common Problems that affect the Application  Should Testers.
Chapter 12 Introducing Databases. Objectives What a database is and which databases are typically used with ASP.NET pages What SQL is, how it looks, and.
DbFit for FitNesse with Data Warehouse worked examples Chris SAUNDERS - September 2014 [AdventureWorks2014] Source Data (multiple.
Understanding Core Database Concepts Lesson 1. Objectives.
ASP.NET Programming with C# and SQL Server First Edition
Y.-H. Chen International College Ming-Chuan University Fall, 2004
Database Access with SQL
CS320 Web and Internet Programming SQL and MySQL
Using SQL Server through Command Prompt
CS1222 Using Relational Databases and SQL
Database Management  .
Databases A brief introduction….
Using SQL to Prepare Data for Analysis
20761B 12: Using Set Operators Module 12   Using Set Operators.
Chapter 7 Working with Databases and MySQL
Structured Query Language
Chapter 8 Working with Databases and MySQL
Relational Databases The Relational Model.
Relational Databases The Relational Model.
CS1222 Using Relational Databases and SQL
Introduction To Structured Query Language (SQL)
Intro to Relational Databases
Access Tutorial 1 Creating a Database
There’s a particular style to it…
Introduction To Structured Query Language (SQL)
CS1222 Using Relational Databases and SQL
Relational Database Design
CS1222 Using Relational Databases and SQL
CS3220 Web and Internet Programming SQL and MySQL
There’s a particular style to it…
CS3220 Web and Internet Programming SQL and MySQL
There’s a particular style to it…
CS1222 Using Relational Databases and SQL
Understanding Core Database Concepts
There’s a particular style to it…
CS1222 Using Relational Databases and SQL
Presentation transcript:

Exploring without light…. Database spelunking Exploring without light….

The hardest thing about writing SQL is figuring out the database relationships.

Finding SQL Server instances Just ask SQL Server Browser Use PowerShell [System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources() Command prompt Sqlcmd -L Only shows instances within a domain Only shows instances current login has permissions to see SQL Browser services must be running

From Command Prompt

From PowerShell

Relational databases store database designs in a database ANSI INFORMATION_SCHEMA Microsoft SYS Schema

List databases with an instance Query SYS schema select * from sys.databases Query INFORMATION_SCHEMA INFORMATION_SCHEMA doesn’t have a Database object

Find a table by name In a specific database In a specific instance Use Management Studio Query SYS schema select * from sys.tables where [name] like '%log%‘ Query INFORMATION_SCHEMA select * from INFORMATION_SCHEMA.tables where TABLE_NAME like '%log%' In a specific instance SYS and INFORMATION_SCHEMA have database scope (mostly) You can only search one database at a time Use TSQL Build a cursor of databases, loop to query sys.tables Sample file: findTableInInstance.sql Across multiple instances Use PowerShell Loop through instances using System.Data.SqlClient to create separate connection for each instance. Sample file: findTableInInstanceList.ps1

Find a column by name In a specific database In a specific instance Use Management Studio Query SYS schema use AdventureWorksDW2012 select t.name, c.name from sys.columns c inner join sys.tables t on t.object_id = c.object_id where c.[name] like '%Reseller%' In a specific instance SYS and INFORMATION_SCHEMA have database scope (mostly) Use TSQL Build a cursor of databases, loop to query sys.tables Sample file: findColumnWithinInstance.sql Across multiple instances Use PowerShell Loop through instances using System.Data.SqlClient to create separate connection for each instance.

Find a string in any stored procedure in a database select distinct OBJECT_NAME(id) from syscomments where OBJECTPROPERTY(id, ‘IsProcedure’) = 1 and [text] like ‘%categoryID%’ order by OBJECT_NAME(id)

Find a string in any view in a database use AdventureWorks2012 select distinct OBJECT_NAME(id) from syscomments where OBJECTPROPERTY(id, 'isView') = 1 and [text] like '%emp%' order by OBJECT_NAME(id)

Find actual Foreign Key relationships USE AdventureWorks2012; GO SELECT f.name AS foreign_key_name ,OBJECT_NAME(f.parent_object_id) AS table_name ,COL_NAME(fc.parent_object_id, fc.parent_column_id) AS constraint_column_name ,OBJECT_NAME (f.referenced_object_id) AS referenced_object ,COL_NAME(fc.referenced_object_id, fc.referenced_column_id) AS referenced_column_name ,is_disabled ,delete_referential_action_desc ,update_referential_action_desc FROM sys.foreign_keys AS f INNER JOIN sys.foreign_key_columns AS fc ON f.object_id = fc.constraint_object_id WHERE f.parent_object_id = OBJECT_ID(‘Production.BillOfMaterials');

Find potential Foreign Key relationships Build a cursor of tables & columns For each table Build a cursor of columns For each column Concatenate a list of tables with that column name Sample file: findColumnWithinInstance.sql

Profile a table Build a cursor of columns for specified table For each column Count number of records, unique values, null values Concatenate a list of field values for column Sample file: ProfileTable.sql