Category Archives: mysql

sybase: insert multiple lines at once

The syntax to insert multiple lines at one in sybase, using an ‘insert’ query, is as follow: insert into <table_name> (column1, column2, …) (select col1, col2, … from <src_table> where <where_clause>) Regular single-line insert syntax is as follow: insert into <table_name> (column1, column2, …) values (value1, value2, …)

sybase: how to find if a table exists

To find if a table exists in sybase, run the following query: SELECT 1 FROM sysobjects WHERE name = ‘my_table_name’ AND type = ‘U’ You can also wrap it into an IF EXISTS() test as follow: IF EXISTS (SELECT 1 FROM sysobjects WHERE name = ‘my_table_name’ AND type = ‘U’) BEGIN //DO SOMETHING END GO sources http://stackoverflow.com/questions/307942/how-do-i-conditionally-create-a-table-in-sybase-tsql

sybase: randomly retrieve rows

To retrieve random rows within sybase, you must first set rowcount to the number of rows you want to retrieve then use ‘rand()’ function in the order by clause, as follows: set rowcount 10 select * from myTable order by rand() go sources http://www.sybaseteam.com/get-random-records-from-a-table-t-784.html

sybase: what version am I running?

It’s pretty easy to find out which version of sybase you’re running thanks to @@version variable. Simply execute the following query: select @@version go

sybase: retrieve table description

To retrieve description of a table, use sp_help stored procedure as follows: sp_help ‘<table_name>’ Below is an example of the query and its output: sp_help ‘my_table’ go >>

sybase: how to rename a table

To rename a table, you can use the stored procedure called sp_rename as follows: sp_rename oldName, newName go Note: don’t forget to run ‘go’ after each call to stored procedure function sp_* sources http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.ase_15.0.sprocs/html/sprocs/sprocs185.htm

sybase: how to backup/duplicate a table (with or without data)

Let’s say you want to backup a table. Well, it’s pretty easy! Simply run the following query: with data select * into database_name..new_table from database_name..src_table go without data select * into database_name..new_table from database_name..src_table where 1=2 go WARNING: this duplicate only table structure but NOT indexes nor primary keys nor constraints sources http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.39996_1250/html/svrtsg/svrtsg121.htm http://www.vbrad.com/article.aspx?id=14

sybase sql: perform update on joined tables

With sybase you can easily update a table using entries found in another one using the join syntax as illustrated below: UPDATE table1 SET t1.field1 = t2.field2 FROM table1 t1 JOIN table2 t2 ON t1.field_id = t2.field_id

Limit statement in sybase sql

In mysql, to limit the number of rows to be retrieved to, let say, 5, you simply append LIMIT statement at the end of your request. SELECT * FROM myTable LIMIT 5; In sybase, such statement does not exists. You need first to execute a “SET ROWCOUNT” statement and then run your select query as illustrated below: SET ROWCOUNT 5 SELECT * FROM myTable  

PhpMyAdmin: change default collation / charset

To change default collation proprosed in phpmyadmin, simply define the following entry in you config.inc.php file: $cfg[‘DefaultConnectionCollation’] = ‘utf8_general_ci’; That’s it. sources http://wiki.phpmyadmin.net/pma/Config