Primary Key for Table
All tables with Primary Key All tables missing Primary Key t.type – object type: Table View c.type – type of constraint: Primary key Unique key Foreign key Check constraint Default constraint
All tables with Primary Key All tables missing Primary Key t.type – object type: Table View c.type – type of constraint: Primary key Unique key Foreign key Check constraint Default constraint
sp_help table01 Table Table Columns Identity Row Guid Column Filegroup Index Constraint Table is Referenced By Foreign Key
Use TRUNCATE instead of DELETE If you need to clear the data in a table, use TRUNCATE instead of DELETE. TRUNCATE lock the table instead of at each row. No triggers are activated and no logs are generated resulting in faster performance. Note: TRUNCATE TABLE will reset your identity to the initial seed, whereas DELETE... » read more
The following SQL Server Not Exists query will find the Employees whose Occupation is neither Skilled Manual nor Clerical. Note: Using NOT EXISTS may have a performance hit. Try to use LEFT JOIN and WHERE column is NULL to test if there is a performance improvement. Sometimes, NOT EXISTS may be faster, and sometimes it... » read more
SSMS -> Database Name -> Task -> Generate Script Select object -> Next Click on “Advanced” in the “Types of Data to Script” select “Data only” Generated Script
All SP Exec All SP one SP at a time Following script will try to add permissions (execute permissions) on all procedures on all databases on the server for the role defined.
The schema change it taking so long because you are assigning a default value to the column during the change and enforcing that with a non-nullable column, and it has to populate the column for millions of rows, which is an incredibly expensive operation. Alternative to making it faster would be to add it in... » read more
Stop using PRINT. Start using RAISERROR. PRINT PRINT with GO RAISEERROR with NOWAIT Source:
The LAG function has the ability to fetch data from a previous row, while LEAD fetches data from a subsequent row. Sources:
Fix: Shrink database file to recover unused space. Add more disk space. Purge data from database. Move data to another database or data warehouse. Sources: