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”

Create your website at WordPress.com
Get started