Is a view faster than a simple query?

Yes, views can have a clustered index assigned and, when they do, they’ll store temporary results that can speed up resulting queries. Microsoft’s own documentation makes it very clear that Views can improve performance. First, most views that people create are simple views and do not use this feature, and are therefore no different to … Read more

How to get the insert ID in JDBC?

If it is an auto generated key, then you can use Statement#getGeneratedKeys() for this. You need to call it on the same Statement as the one being used for the INSERT. You first need to create the statement using Statement.RETURN_GENERATED_KEYS to notify the JDBC driver to return the keys. Here’s a basic example: public void … Read more

Hibernate show real SQL [duplicate]

Can I see (…) the real SQL If you want to see the SQL sent directly to the database (that is formatted similar to your example), you’ll have to use some kind of jdbc driver proxy like P6Spy (or log4jdbc). Alternatively you can enable logging of the following categories (using a log4j.properties file here): log4j.logger.org.hibernate.SQL=DEBUG … Read more

Select statement to find duplicates on certain fields

To get the list of fields for which there are multiple records, you can use.. select field1,field2,field3, count(*) from table_name group by field1,field2,field3 having count(*) > 1 Check this link for more information on how to delete the rows. http://support.microsoft.com/kb/139444 There should be a criterion for deciding how you define “first rows” before you use … Read more

must appear in the GROUP BY clause or be used in an aggregate function

[*] Yes, this is a common aggregation problem. Before SQL3 (1999), the selected fields must appear in the GROUP BY clause[*]. To workaround this issue, you must calculate the aggregate in a sub-query and then join it with itself to get the additional columns you’d need to show: SELECT m.cname, m.wmname, t.mx FROM ( SELECT … Read more

Postgres and Indexes on Foreign Keys and Primary Keys

PostgreSQL automatically creates indexes on primary keys and unique constraints, but not on the referencing side of foreign key relationships. When Pg creates an implicit index it will emit a NOTICE-level message that you can see in psql and/or the system logs, so you can see when it happens. Automatically created indexes are visible in … Read more

Rename a column in MySQL

Use the following query: ALTER TABLE tableName CHANGE oldcolname newcolname datatype(length); The RENAME function is used in Oracle databases. ALTER TABLE tableName RENAME COLUMN oldcolname TO newcolname datatype(length); @lad2025 mentions it below, but I thought it’d be nice to add what he said. Thank you @lad2025! You can use the RENAME COLUMN in MySQL 8.0 … Read more

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