How do you document your database structure? [closed]

MySQL allows comments on tables and rows. PostgreSQL does as well. From other answers, Oracle and MSSQL have comments too. For me, a combination of UML diagram for a quick refresher on field names, types, and constraints, and an external document (TeX, but could be any format) with extended description of everything database-related – special … Read more

Restore DB — Error RESTORE HEADERONLY is terminating abnormally.

You can check out this blog post. It had solved my problem. http://dotnetguts.blogspot.com/2010/06/restore-failed-for-server-restore.html Select @@Version It had given me following output Microsoft SQL Server 2005 – 9.00.4053.00 (Intel X86) May 26 2009 14:24:20 Copyright (c) 1988-2005 Microsoft Corporation Express Edition on Windows NT 6.0 (Build 6002: Service Pack 2) You will need to re-install to … Read more

Decode equivalent in postgres

There is an equivalent. It’s called a CASE statement. There are two forms of CASE: Simple CASE: CASE search-expression WHEN expression [, expression [ … ]] THEN statements [ WHEN expression [, expression [ … ]] THEN statements … ] [ ELSE statements ] END CASE; Searched CASE: CASE WHEN boolean-expression THEN statements [ WHEN … Read more

SQL Listing all column names alphabetically

This generates a query with all columns ordered alphabetically in the select statement. DECLARE @QUERY VARCHAR(2000) DECLARE @TABLENAME VARCHAR(50) = ‘<YOU_TABLE>’ SET @QUERY = ‘SELECT ‘ SELECT @QUERY = @QUERY + Column_name + ‘, ‘ FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @TABLENAME ORDER BY Column_name SET @QUERY = LEFT(@QUERY, LEN(@QUERY) – 4) + ‘ FROM ‘+ … Read more

How to create a SET-like type on postgresql

Use the HSTORE column type. HSTORE stores key/value pairs. You can use null values if you only care about checking if a key exists. See https://www.postgresql.org/docs/current/static/hstore.html. For example, to ask Is ‘x’ in my hstore?, do CREATE EXTENSION HSTORE; –create extension only has to be done once SELECT * FROM ‘x=>null,y=>null,z=>null’::HSTORE ? ‘x’; I believe … Read more

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