Mysql: Setup the format of DATETIME to ‘DD-MM-YYYY HH:MM:SS’ when creating a table

“MySQL retrieves and displays DATETIME values in ‘YYYY-MM-DD HH:MM:SS’ format.” This is from mysql site. You can store only this type, but you can use one of the many time format functions to change it, when you need to display it. Mysql Time and Date functions For example, one of those functions is the DATE_FORMAT, … Read more

Adding named foreign key constraints in a SQL Create statement

In SQL Server, you can use the constraint keyword to define foreign keys inline and name them at the same time. Here’s the updated script: CREATE TABLE galleries_gallery ( id INT NOT NULL PRIMARY KEY IDENTITY, title NVARCHAR(50) UNIQUE NOT NULL, description VARCHAR(256), templateID INT NOT NULL CONSTRAINT FK_galerry_template REFERENCES galleries_templates(id), jsAltImgID INT NOT NULL … Read more

PostgreSQL Error: Relation already exists

I finally discover the error. The problem is that the primary key constraint name is equal the table name. I don know how postgres represents constraints, but I think the error “Relation already exists” was being triggered during the creation of the primary key constraint because the table was already declared. But because of this … Read more

create table in postgreSQL

First the bigint(20) not null auto_increment will not work, simply use bigserial primary key. Then datetime is timestamp in PostgreSQL. All in all: CREATE TABLE article ( article_id bigserial primary key, article_name varchar(20) NOT NULL, article_desc text NOT NULL, date_added timestamp default NULL );

Postgres table column name restrictions?

Here’s a nice table of reserved words in PostgreSQL: http://www.postgresql.org/docs/current/static/sql-keywords-appendix.html It is probably best to simply avoid using those words as table- or column-names. An alternative, however, is to enclose the identifier in double-quotes, e.g.: CREATE TABLE IF NOT EXISTS apiss ( skey TEXT, time INTEGER, “user” TEXT, ip TEXT); Additionally, Postgres reserves system column … Read more

MySQL: Error Code: 1118 Row size too large (> 8126). Changing some columns to TEXT or BLOB

I tried all the solutions here, but only this parameter innodb_strict_mode = 0 solved my day… From the manual: The innodb_strict_mode setting affects the handling of syntax errors for CREATE TABLE, ALTER TABLE and CREATE INDEX statements. innodb_strict_mode also enables a record size check, so that an INSERT or UPDATE never fails due to the … Read more

tech