SQL – DISTINCT and GROUP BY Difference

Distinct and Group By executed the same result as well as query plan of execution.Group BY clause is used whenever aggregate functions are used.Distinct use to remove the duplicates and it can’t be use in aggregate functions. examples for DISTINCTSELECT DISTINCT col1FROM table1 examples for GROUP BY SELECT col1FROM table1GROUP BY col1 both query willContinue reading “SQL – DISTINCT and GROUP BY Difference”

SQL – Find number Rows, Columns for each table in the database

From below query you will get the number of data present in each table of databases. Most consume table data. –created the temp table to store the tables data sizeCREATE TABLE #DBEachTable (TableName sysname ,RowCounts INT,ReservedSize VARCHAR(50),DataSize VARCHAR(50),IndexSize VARCHAR(50),UnusedSize VARCHAR(50)) –insert the tables data in created temp tableINSERT #DBEachTableEXEC sp_msforeachtable ‘sp_spaceused ”?”’ –fetching the eachContinue reading “SQL – Find number Rows, Columns for each table in the database”

SQL – Display Primary and Foreign Key Relationships Table With Their Constraints

In below query, We can view the relationships between more than one table as primary and foreign key … SELECT PK_Table = PK.TABLE_NAME,PK_Column = PT.COLUMN_NAME,K_Table = FK.TABLE_NAME,FK_Column = CU.COLUMN_NAME,Constraint_Name = C.CONSTRAINT_NAMEFROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS CINNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS FK ON C.CONSTRAINT_NAME = FK.CONSTRAINT_NAMEINNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS PK ON C.UNIQUE_CONSTRAINT_NAME = PK.CONSTRAINT_NAMEINNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE CU ON C.CONSTRAINT_NAME = CU.CONSTRAINT_NAMEINNER JOINContinue reading “SQL – Display Primary and Foreign Key Relationships Table With Their Constraints”

Top 10 SQL Interview Questions

What is SQL ?SQL is Structured Query Language . This is a standard language used to perform tasks such as INSERT/UPDATE/DELETE and SELECT of data from a database. What is Database ?Database is nothing but an organized form of data for easy access, storing, retrieval and managing of data. Constraints in SQL ?NOT NULL –Continue reading “Top 10 SQL Interview Questions”

Design a site like this with WordPress.com
Get started