Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access

Tag: table

SQL

How to list all tables referencing a table by Foreign Key in MS SQL

- 04.10.24 - ErcanOPAK comment on How to list all tables referencing a table by Foreign Key in MS SQL

SELECT DISTINCT schema_name(fk_tab.schema_id) + ‘.’ + fk_tab.name as foreign_table, ‘>-‘ as rel, schema_name(pk_tab.schema_id) + ‘.’ + pk_tab.name as primary_table FROM sys.foreign_keys fk INNER JOIN sys.tables fk_tab on fk_tab.object_id = fk.parent_object_id INNER JOIN sys.tables pk_tab on pk_tab.object_id = fk.referenced_object_id WHERE pk_tab.[name] = ‘Your table’ — enter table name here — and schema_name(pk_tab.schema_id) = ‘Your table schema […]

Read More
SQL

How to check seed value of tables in SQL

- 15.03.24 - ErcanOPAK comment on How to check seed value of tables in SQL

–View the current value: DBCC CHECKIDENT (“{table name}”, NORESEED) –Set it to the max value plus one: DBCC CHECKIDENT (“{table name}”, RESEED) –Set it to a spcefic value: DBCC CHECKIDENT (“{table name}”, RESEED, {New Seed Value})  

Read More
SQL

How to insert results of a stored procedure into a temporary table

- 13.10.23 - ErcanOPAK comment on How to insert results of a stored procedure into a temporary table

CREATE TABLE #tmpTable ( COL1 int, COL2 int, COL3 nvarchar(max), COL4 nvarchar(max), COL5 bit ) INSERT INTO #tmpTable exec SpGetRecords ‘Params’ NOTE: The columns of #tmpTable must be the same as SpGetRecords. Otherwise, there will be a problem. If there are no parameters in the stored procedure, you don’t need to use ‘Params’.

Read More
SQL

How to use OUTPUT for Insert, Update and Delete in SQL

- 19.09.23 - ErcanOPAK comment on How to use OUTPUT for Insert, Update and Delete in SQL

The OUTPUT clause was introduced in SQL Server 2005. The OUTPUT clause returns the values of each row that was affected by an INSERT, UPDATE, or DELETE statement. It even supports a MERGE statement, which was introduced in SQL Server 2008 version. The OUTPUT clause has access to two temporary or in-memory SQL tables, INSERTED […]

Read More
SQL

How to get difference between 2 tables in MSSQL

- 17.06.23 - ErcanOPAK comment on How to get difference between 2 tables in MSSQL

If you have two tables A and B, both with column C, here are the records, which are present in the table A but not in B: SELECT A.* FROM A LEFT JOIN B ON (A.C = B.C) WHERE B.C IS NULL To get all the differences with a single query, a full join must be used, like this: […]

Read More
ASP.Net MVC / JavaScript

How to remove searching, filtering, ordering and info from Asp.NET MVC Datatable

- 15.09.22 - ErcanOPAK comment on How to remove searching, filtering, ordering and info from Asp.NET MVC Datatable

var table = $(“#datatable”).DataTable({ “paging”: false, “ordering”: false, “searching”: false, “info”: false });  

Read More
SQL

How to get ‘n’th row in Sql Query with OFFSET FETCH NEXT and ROW_NUMBER()

- 20.07.22 | 21.07.22 - ErcanOPAK comment on How to get ‘n’th row in Sql Query with OFFSET FETCH NEXT and ROW_NUMBER()

In SQL Server 2012+, you can use OFFSET…FETCH. The below query will help you to get 2nd row. But with little changes, you can get the ‘n’th row as well. SELECT <column(s)> FROM <table(s)> ORDER BY <sort column(s)> OFFSET 1 ROWS — Skip this number of rows FETCH NEXT 1 ROWS ONLY; — Return this […]

Read More
ASP.Net MVC / ASP.Net WebForms / C# / SQL

How to add default value for Entity Framework migrations for DateTime and Bool

- 19.06.22 | 16.01.26 - ErcanOPAK comment on How to add default value for Entity Framework migrations for DateTime and Bool

When working with Code First Migrations, developers often struggle with setting default values at the database level. While you can set a default value in your C# class, doing it directly in the SQL schema is much more robust. Here is how you can achieve this using defaultValue and defaultValueSql. 1. Using Static Default Values […]

Read More
CSS

Hide element in CSS with Display and Visibility

- 30.10.21 - ErcanOPAK comment on Hide element in CSS with Display and Visibility

visibility: hidden (Hide but keep the space) <div stlye=”visibility: hidden;”>The Components We want to Hide</div> By default, the value of the visibility property is visible. However, if you want to make an image invisible, you can set the value of visibility to hidden.   display: none (Hide and remove the space) <div stlye=”display: none;”>The Components We want to Hide</div> The display […]

Read More
SQL

How To Get All Row Count For All Tables In SQL Server Database

- 04.08.21 - ErcanOPAK comment on How To Get All Row Count For All Tables In SQL Server Database

SELECT (SCHEMA_NAME(A.schema_id) + ‘.’ + A.Name) AS TableName , SUM(B.rows) AS RecordCount FROM sys.objects A INNER JOIN sys.partitions B ON A.object_id = B.object_id WHERE A.type = ‘U’ GROUP BY A.schema_id, A.Name ORDER BY RecordCount DESC  

Read More
ASP.Net MVC / JavaScript

How to solve ajax.reload() not working for DataTables in JS File

- 22.06.20 | 16.01.26 - ErcanOPAK comment on How to solve ajax.reload() not working for DataTables in JS File

If you are working with DataTables, you’ve likely encountered that frustrating moment: your data changes in the database, but your table refuses to refresh. You call table.ajax.reload(); and… nothing happens, or worse, you get a console error. Let’s break down why this happens and how to fix it with a single line of code. 1. […]

Read More
ASP.Net MVC

Default Settings for Datatable in MVC

- 21.06.20 - ErcanOPAK comment on Default Settings for Datatable in MVC

When working with DataTables over multiple pages it is often useful to set the initialisation defaults to common values (for example you might want to set dom to a common value so all tables get the same layout). This can be done using the $.fn.dataTable.defaults object. This object will take all of the same parameters as the DataTables initialisation […]

Read More
SQL

How to create Local and Global Temp Tables in MS SQL

- 11.04.20 - ErcanOPAK comment on How to create Local and Global Temp Tables in MS SQL

Creating Local Temp Table [with #]: SELECT TOP(10) ID INTO #TempTable FROM MyTable Craeting Global Temp Table [with ##]: SELECT TOP(10) ID INTO ##TempTable FROM MyTable Reaching Local Temp Table with Query: SELECT name FROM tempdb..sysobjects WHERE name LIKE ‘#TempTable%’  

Read More
ASP.Net WebForms / C#

How to calculate the sum of the datatable column in asp.net?

- 14.03.20 | 14.04.20 - ErcanOPAK comment on How to calculate the sum of the datatable column in asp.net?

To calculate the sum of a column in a DataTable use the DataTable.Compute method. DataTable dt; … int sumValue; sumValue = dt.Compute(“Sum(TheSumColumn)”, string.Empty);

Read More
C#

How to select distinct rows in a datatable in C#

- 10.03.20 - ErcanOPAK comment on How to select distinct rows in a datatable in C#

dataTable.DefaultView.ToTable(true, “target_column”); first parameter in ToTable() is a boolean which indicates whether you want distinct rows or not. second parameter in the ToTable() is the column name based on which we have to select distinct rows. Only these columns will be in the returned datatable. If you need to get distinct based on two columns: dataTable.DefaultView.ToTable(boolean, params string[] columnNames)

Read More
SQL

List all Foreign Keys referencing a given table in SQL Server

- 20.11.19 | 27.11.19 - ErcanOPAK comment on List all Foreign Keys referencing a given table in SQL Server

EXEC sp_fkeys ‘TableName’ You can also specify the schema: EXEC sp_fkeys @pktable_name = ‘TableName’, @pktable_owner = ‘dbo’

Read More
SQL

Drop all the tables, stored procedures, triggers, constraints and all the dependencies in one sql statement

- 27.10.19 | 22.11.19 - ErcanOPAK comment on Drop all the tables, stored procedures, triggers, constraints and all the dependencies in one sql statement

These 2 scripts clean all views, SPS, functions PKs, FKs and tables. 1. The First script by Adam Anderson, updated to support objects in other schemas than dbo: — check constraints select @stmt = isnull( @stmt + @n, ” ) + ‘alter table [‘ + schema_name(schema_id) + ‘].[‘ + object_name( parent_object_id ) + ‘] drop […]

Read More
SQL

Convert a Comma-Delimited List to a Table in SQL

- 11.06.18 | 14.04.20 - ErcanOPAK comment on Convert a Comma-Delimited List to a Table in SQL

You can check the example code:

Read More
SQL

Add Default Value in SQL Server

- 03.06.18 | 03.06.18 - ErcanOPAK comment on Add Default Value in SQL Server

If there is no default value for the column then you can use this query: ALTER TABLE MyTable ADD CONSTRAINT df_MyTable_MyColumn DEFAULT 0 FOR MyColumn

Read More
January 2026
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Dec    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (923)
  • How to add default value for Entity Framework migrations for DateTime and Bool (814)
  • Get the First and Last Word from a String or Sentence in SQL (808)
  • How to select distinct rows in a datatable in C# (784)
  • How to make theater mode the default for Youtube (664)
  • Add Constraint to SQL Table to ensure email contains @ (561)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (544)
  • Average of all values in a column that are not zero in SQL (510)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (460)
  • Find numbers with more than two decimal places in SQL (427)

Recent Posts

  • C# Value Types Copied More Than You Think
  • C# Async Void Is Dangerous
  • C# Foreach vs For Performance Difference
  • SQL Deletes Lock Tables
  • SQL Queries Slow Despite Indexes
  • .NET Core APIs Feel Slow Under Load
  • ASP.NET Core Memory Grows Slowly
  • Git Conflicts Keep Reappearing
  • Git Rebase Feels Dangerous
  • Ajax Forms Submit Twice

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (923)
  • How to add default value for Entity Framework migrations for DateTime and Bool (814)
  • Get the First and Last Word from a String or Sentence in SQL (808)
  • How to select distinct rows in a datatable in C# (784)
  • How to make theater mode the default for Youtube (664)

Recent Posts

  • C# Value Types Copied More Than You Think
  • C# Async Void Is Dangerous
  • C# Foreach vs For Performance Difference
  • SQL Deletes Lock Tables
  • SQL Queries Slow Despite Indexes

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com