Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Thursday, July 30, 2015

How to compare two tables schema by SQL query in MS SQL?

How to compare two tables schema  by SQL query in MS SQL?
SELECT name,system_type_id,user_type_id,max_length,precision,scale,collation_name,is_nullable into #Tablescehma1
FROM sys.columns WHERE object_id = OBJECT_ID('TABLE1')

SELECT name,system_type_id,user_type_id,max_length,precision,scale,collation_name,is_nullable into #Tablescehma2
FROM sys.columns WHERE object_id = OBJECT_ID('TABLE2')

select * from #Tablescehma1
except
select * from #Tablescehma2

Friday, May 1, 2015

SQLBolt, interactive lessons to learn SQL in browser

http://sqlbolt.com/
Welcome to SQLBolt, a series of interactive lessons and exercises designed to help you quickly learn SQL right in your browser

Tuesday, December 16, 2014

In MS SQL, how to count total number of major objectsr, such as table, view, store procedure etc?

Select type_desc as Type, COUNT(*) AS Count from SYS.OBJECTS
Where type_desc not in ('SYSTEM_TABLE','INTERNAL_TABLE','SERVICE_QUEUE')
group by type_desc