How to change the default collation of a table?

To change the default character set and collation of a table including those of existing columns (note the convert to clause): alter table <some_table> convert to character set utf8mb4 collate utf8mb4_unicode_ci; Edited the answer, thanks to the prompting of some comments: Should avoid recommending utf8. It’s almost never what you want, and often leads to … Read more

How to check if a table exists in a given schema

It depends on what you want to test exactly. Information schema? To find “whether the table exists” (no matter who’s asking), querying the information schema (information_schema.tables) is incorrect, strictly speaking, because (per documentation): Only those tables and views are shown that the current user has access to (by way of being the owner or having … Read more

The object ‘DF__*’ is dependent on column ‘*’ – Changing int to double

Try this: Remove the constraint DF_Movies_Rating__48CFD27E before changing your field type. The constraint is typically created automatically by the DBMS (SQL Server). To see the constraint associated with the table, expand the table attributes in Object explorer, followed by the category Constraints as shown below: You must remove the constraint before changing the field type.

What’s the difference between RANK() and DENSE_RANK() functions in oracle?

RANK() gives you the ranking within your ordered partition. Ties are assigned the same rank, with the next ranking(s) skipped. So, if you have 3 items at rank 2, the next rank listed would be ranked 5. DENSE_RANK() again gives you the ranking within your ordered partition, but the ranks are consecutive. No ranks are … Read more

How to calculate age (in years) based on Date of Birth and getDate()

There are issues with leap year/days and the following method, see the update below: try this: DECLARE @dob datetime SET @dob=’1992-01-09 00:00:00′ SELECT DATEDIFF(hour,@dob,GETDATE())/8766.0 AS AgeYearsDecimal ,CONVERT(int,ROUND(DATEDIFF(hour,@dob,GETDATE())/8766.0,0)) AS AgeYearsIntRound ,DATEDIFF(hour,@dob,GETDATE())/8766 AS AgeYearsIntTrunc OUTPUT: AgeYearsDecimal AgeYearsIntRound AgeYearsIntTrunc ————————————— —————- —————- 17.767054 18 17 (1 row(s) affected) UPDATE here are some more accurate methods: BEST METHOD FOR … Read more

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