How to check if a stored procedure exists before creating it

I realize this has already been marked as answered, but we used to do it like this: IF NOT EXISTS (SELECT * FROM sys.objects WHERE type=”P” AND OBJECT_ID = OBJECT_ID(‘dbo.MyProc’)) exec(‘CREATE PROCEDURE [dbo].[MyProc] AS BEGIN SET NOCOUNT ON; END’) GO ALTER PROCEDURE [dbo].[MyProc] AS …. Just to avoid dropping the procedure.

Create unique constraint with null columns

Postgres 15 or newer Postgres 15 (currently beta) adds the clause NULLS NOT DISTINCT. The release notes: Allow unique constraints and indexes to treat NULL values as not distinct (Peter Eisentraut) Previously NULL values were always indexed as distinct values, but this can now be changed by creating constraints and indexes using UNIQUE NULLS NOT … Read more

How to convert DateTime to VarChar

Here’s some test sql for all the styles. DECLARE @now datetime SET @now = GETDATE() select convert(nvarchar(MAX), @now, 0) as output, 0 as style union select convert(nvarchar(MAX), @now, 1), 1 union select convert(nvarchar(MAX), @now, 2), 2 union select convert(nvarchar(MAX), @now, 3), 3 union select convert(nvarchar(MAX), @now, 4), 4 union select convert(nvarchar(MAX), @now, 5), 5 union … Read more

Recommended SQL database design for tags or tagging [closed]

Three tables (one for storing all items, one for all tags, and one for the relation between the two), properly indexed, with foreign keys set running on a proper database, should work well and scale properly. Table: Item Columns: ItemID, Title, Content Table: Tag Columns: TagID, Title Table: ItemTag Columns: ItemID, TagID

Cast from VARCHAR to INT – MySQL

As described in Cast Functions and Operators: The type for the result can be one of the following values: BINARY[(N)] CHAR[(N)] DATE DATETIME DECIMAL[(M[,D])] SIGNED [INTEGER] TIME UNSIGNED [INTEGER] Therefore, you should use: SELECT CAST(PROD_CODE AS UNSIGNED) FROM PRODUCT

MySQL LIKE IN()?

A REGEXP might be more efficient, but you’d have to benchmark it to be sure, e.g. SELECT * from fiberbox where field REGEXP ‘1740|1938|1940’;

Difference between “read commited” and “repeatable read”

Read committed is an isolation level that guarantees that any data read was committed at the moment is read. It simply restricts the reader from seeing any intermediate, uncommitted, ‘dirty’ read. It makes no promise whatsoever that if the transaction re-issues the read, will find the Same data, data is free to change after it … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)