SELECT COLUMN_NAME, DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'myTableName'?
Here are some pro tips for working with T-SQL:
Use SET NOCOUNT ON: This statement stops the message indicating the number of rows affected by a query, which can improve performance.
Avoid using SELECT *: Instead of selecting all columns, specify only the columns you need. This reduces the amount of data returned and can improve performance.
Use stored procedures: Stored procedures can be pre-compiled and cached, which can improve performance. They can also simplify complex queries and make them easier to maintain.
Use indexing: Indexes can improve query performance by allowing the database engine to quickly find the data it needs.
Use parameterized queries: Parameterized queries can improve performance by reusing execution plans and reducing the risk of SQL injection attacks.
Use temporary tables wisely: Temporary tables can be useful, but they can also slow down performance if they are not used properly. Avoid creating temporary tables in loops or for small amounts of data.
Use transactions: Transactions ensure that a group of SQL statements are treated as a single unit of work, which can help maintain the consistency of data.
Use common table expressions (CTEs): CTEs can simplify complex queries and make them easier to read and maintain.
Use window functions: Window functions allow you to perform calculations across multiple rows, which can be useful for tasks like ranking or running totals.
Monitor performance: Keep an eye on query performance and use tools like SQL Profiler to identify bottlenecks and optimize your queries.
1. What are Sparse Columns
Answer
Sparse Column is a column that is most likely to be NULL, when you mark a Column as Sparse #SQL Server does some #optimization behind the scene to make sure that Data stored in a #TPH (a Wide Table with some roles of #NULL values ) does not consume a lot of space on disk.
2. What is TPH in Entity Framework
- Read this documentation to understand Model Inheritance and #TPC, TPH, and #TPT
https
//docs.microsoft.com/en-us/ef/core/modeling/inheritance
3. In EF Core, you could UseHilo the DbContext Model Configuration section to let the EF Core know that on a Certain table you would want the ID to be generated before the insert. This is important when you are relying on one insert of record then retrieve the ID of that record to insert other records into another table and reference the ID as a foreign key.
Inserting One record and then waiting until the record is inserted to only get the ID creates a round trip to the database which could slow down the application. However, using a UseHilo in the OnModelCreate cuts this round trip in one as you would then bundle all your inserts in _dbContext.AddRang() and add several different types of Entity referencing to one Parent ID as a foreign key.
Mark said:
The videos are great, thank you for the post again.