Skip to content

Oracle SQL insert into with With clause

I’m new to sql, so maybe it is a dumb question, but is there any possibility to use With clause with Insert Into? Or are there any common workarounds? I mean something like this: With helper_table As …

Generate class from database table

How can I generate a class from a SQL Server table object? I’m not talking about using some ORM. I just need to create the entities (simple class). Something like: Given some table like: Answer Set @TableName to the name of your table.

Convert nvarchar to bigint in Sql server 2008

I want insert all rows of a table into another table, and I also want convert a nvarchar field into bigint, but when I use convert(bigint, col1) SQL Server shows an error: Error converting data …

SQL WHERE ID IN (id1, id2, …, idn)

I need to write a query to retrieve a big list of ids. We do support many backends (MySQL, Firebird, SQLServer, Oracle, PostgreSQL …) so I need to write a standard SQL. The size of the id set could be big, the query would be generated programmatically. So, what is the best approach? 1) Writing a query u…

Calculate age in MySQL (InnoDB)

If I have a person’s date of birth stored in a table in the form dd-mm-yyyy, and I subtract it from the current date, what format is the date returned in? How can I use this returned format to calculate someone’s age? Answer If the value is stored as a DATETIME data type: Less precise when you con…

Caching SQL queries

If I look in my profiler for SQL-server, it comes up with a lot of duplicate queries such as: A lot of these queries are not needed to display real time data, that is, if someone inserted a new record that was matched in that query it wouldn’t matter if it didn’t display for up to an hour after in…

Importing records from PostgreSQL to MySQL

Was wondering if anyone had any insight or recommended tools for exporting the records from a PostgreSQL database and importing them into a MySQL database. I believe the table structure is 100% identical. Thoughts? Thanks! Answer The command will generate SQL-standard-compliant INSERT statements with all colu…

PostgreSQL visual interface similar to phpMyAdmin?

I’d like to view and possibly edit tables for PostgreSQL visually like phpMyAdmin, where you can see the list of tables, and fields and individual rows for a table. Is there any utility that can do this? Forgive me if this is actually possible in pgAdmin III, but I couldn’t figure out any way to s…