Skip to main content

Posts

Showing posts with the label sql

Getting the size of your Microsoft (MS) SQL database

I foudn this at Stack Overflow, and thought it woud be great to save it since it works well. SELECT t.NAME AS TableName, s.Name AS SchemaName, p.rows AS RowCounts, SUM(a.total_pages) * 8 AS TotalSpaceKB, SUM(a.used_pages) * 8 AS UsedSpaceKB, (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB FROM sys.tables t INNER JOIN sys.indexes i ON t.OBJECT_ID = i.object_id INNER JOIN sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id INNER JOIN sys.allocation_units a ON p.partition_id = a.container_id LEFT OUTER JOIN sys.schemas s ON t.schema_id = s.schema_id WHERE t.NAME NOT LIKE 'dt%' AND t.is_ms_shipped = 0 AND i.OBJECT_ID > 255 GROUP BY t.Name, s.Name, p.Rows ORDER BY t.Name   It returns a table that you can use to calculate the total size. Original post Get size of all tables in database Obvioulsy you must use the database first.

SQL Quick, viewing a store procedure

I had to blog this, seems as though it took me almost an hour to find ;) If you want to view a stored procedure using SQL, how do you do it? The command I found to work is: EXEC sp_HelpText " yourStoredProcName " Then to alter it, you do as follows USE AdventureWorks2012; GO ALTER PROCEDURE Purchasing.uspVendorAllInfo @Product varchar(25) AS codeOfProc.... GO

Some things I have learnt, that are Easy Peasy, about databases and SQL Express

The is real 101 stuff, but though I would blog it anyway. To create a new database is SQL Express: Run SQL Server Management Studio (if you do not have it download it from Microsoft downloads) Expand the connected database engine (if you are not connect to one then connect) Then right click on the Databases folder Click New database… Then fill in a database name and ok There is a new empty database. The data type to use for a new table in SQL express that is autoinc Create a new table Type in the column name Select datatype int In Column Properties click the [+] next to Identity Specification Next to (Is Identity) select Yes If you want to make that the primary key right click on the row and select Set Primary Key Oh and when you create a table it asks you to name it when you save it.