Skip to main content

Posts

Find size of SQL Server tables and other objects with stored procedure

my colleague needs a query to seek for all tables in certain Database then use it to display informati on such as: Created Date, Rows in that tables, etc at first i look over sp_spaceused but it end up wrapping query which is hard because undocumented and it failed :( also considerations can be used for SQL 2000 so i google it and found this link , it works for SQL 2000 and above i tweak a bit to meet my requirement but credit goes to  Richard Ding here is the query that i used USE master; GO IF OBJECT_ID(N'dbo.sp_SOS', N'P') IS NOT NULL   DROP PROCEDURE dbo.sp_SOS; GO CREATE PROCEDURE dbo.sp_SOS   @DbName sysname = NULL,   @SchemaName sysname = NULL,   @ObjectName sysname = N'%',   @TopClause nvarchar(20) = NULL,   @ObjectType nvarchar(50) = NULL,   @ShowInternalTable nvarchar(3) = NULL,   @OrderBy nvarchar(100) = NULL,   @UpdateUsage bit = 0 AS /*=============================================================...

Print Escape Character for printer Barcode in .NET

fiuhh, this case is one of the most annoying 'simple' approach requirement is to send 'barcode' to printer directly, because often we using Image print (creating image on the fly then send it to barcode printer)..this one althought works but often the image become blur / discarded so we need to 'communicate' to barcode printer using its 'language' the 'language' depends on the printer itself..in my case, we using SATO barcode printer so the 'language' is SBPL  (visit the link for more info) first we need to design the label we can use SBPL and design it 'on the fly' make us a little bit crazy or we can use SATO LABEL Gallery Free to do the job and generate SBPL equivalent for us so we can use it in our code after we design it, we use "Print to file" method for the printer then print it so we can see what its send to the printer the generated SBPL will contain 'unseen' character in visual studio ID...

Reset Identity Column Value in SQL Server

if u have identity column and of course before deployed it to production, u'll need to test the value when u done, u probably want to reset it to initial value (0 for example) so u have 'fresh' data for production u'll be need to use this syntax DBCC CHECKIDENT (orders, RESEED, 0) PS: the next value will be always +1, so in my case next value will be 1 until then

Date and Time format in SQL

this are some DATE and TIME format to use in SQL that i found when i'm googling a little YY-MM-DD SELECT SUBSTRING(CONVERT(VARCHAR(10), GETDATE(), 120), 3, 8) AS [YY-MM-DD] SELECT REPLACE(CONVERT(VARCHAR(8), GETDATE(), 11), '/', '-') AS [YY-MM-DD] 99-01-24 YYYY-MM-DD SELECT CONVERT(VARCHAR(10), GETDATE(), 120) AS [YYYY-MM-DD] SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 111), '/', '-') AS [YYYY-MM-DD] 1999-01-24 MM/YY SELECT RIGHT(CONVERT(VARCHAR(8), GETDATE(), 3), 5) AS [MM/YY] SELECT SUBSTRING(CONVERT(VARCHAR(8), GETDATE(), 3), 4, 5) AS [MM/YY] 08/99 MM/YYYY SELECT RIGHT(CONVERT(VARCHAR(10), GETDATE(), 103), 7) AS [MM/YYYY] 12/2005 YY/MM SELECT CONVERT(VARCHAR(5), GETDATE(), 11) AS [YY/MM] 99/08 YYYY/MM SELECT CONVERT(VARCHAR(7), GETDATE(), 111) AS [YYYY/MM] 2005/12 Month DD, YYYY  1 SELECT DATENAME(MM, GETDATE()) + RIGHT(CONVERT(VARCHAR(12), GETDATE(), 107), 9) AS [Month DD, YYYY] July 04, 2006 1 Mon YYYY 1 SELECT SUBSTRING(CONV...

Search specific string inside Stored Procedure, View, Function, Trigger, Table Name, Table Field in SQL Server

this query can be used to search specific string inside, no need to right click  - modify - and search manually from Query designer / SSMS DECLARE @NextString NVARCHAR(40) DECLARE @Pos INT DECLARE @NextPos INT DECLARE @String NVARCHAR(40) DECLARE @Delimiter NVARCHAR(40) DECLARE @Query nvarchar(2000) DECLARE @WHERE nvarchar(1000) DECLARE @Query2 nvarchar(2000) DECLARE @Where2 nvarchar(1000) SET @Query =  'SELECT DISTINCT so.name, ' +    'CASE so.xtype ' +     'WHEN ''P'' THEN ''SPROC'' ' +     'WHEN ''IF'' THEN ''FUNCTION'' ' +     'WHEN ''FN'' THEN ''FUNCTION'' ' +     'WHEN ''V'' THEN ''VIEW'' ' +     'WHEN ''U'' THEN ''TABLE'' ' +     'WHEN ''TR'' THEN ''TRIGGER'' ' +    'END AS [TYPE] ' +  'FROM...

Cannot obtain the schema rowset "DBSCHEMA_TABLES_INFO" for OLE DB provider "SQLNCLI" for linked server [linked_server_name]

just got this error when try to execute query against LinkServer (SQL 2000) from SQL 2005 eventhough the link can create but i can't do 4 parts query select * from LINKED.DB.DBO.TABLE the problem because SQL 2000 needs to run certain SP that not exists in master so the LINK query can run create   procedure  sp_tables_info_rowset_64       @table_name  sysname ,       @table_schema      sysname   =   null,           @table_type  nvarchar ( 255 )   =   null as declare @Result int set @Result = 0 exec  @Result =  sp_tables_info_rowset  @table_name , @table_schema ,  @table_type this  solution  originally POST  by  Marek Adamczuk until then