Best way to add a new column with an initial (but not default) value?

To add the column with a default and then delete the default, you can name the default: ALTER TABLE tbl ADD col INTEGER NOT NULL CONSTRAINT tbl_temp_default DEFAULT 1 ALTER TABLE tbl drop constraint tbl_temp_default This filled in the value 1, but leaves the table without a default. Using SQL Server 2008, I ran this … Read more

Mysql set default value to a json type column

From version 8.0.13 onwards, the documentation says (emphasis is mine): The BLOB, TEXT, GEOMETRY, and JSON data types can be assigned a default value only if the value is written as an expression, even if the expression value is a literal. You can make your default an expression by surrounding the literal value with parentheses: … Read more

Add a column if it doesn’t exist to all tables?

You cannot use variables, like @tableName, in DDL. Besides, splinting the name into part and ignoring the schema can only result in bugs. You should just use the ”?” replacement in the SQL batch parameter and rely on the MSforeachtable replacement: EXEC sp_MSforeachtable ‘ if not exists (select * from sys.columns where object_id = object_id(”?”) … Read more

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