Renaming Columns in an SQL SELECT Statement

You can alias the column names one by one, like so SELECT col1 as `MyNameForCol1`, col2 as `MyNameForCol2` FROM `foobar` Edit You can access INFORMATION_SCHEMA.COLUMNS directly to mangle a new alias like so. However, how you fit this into a query is beyond my MySql skills 🙁 select CONCAT(‘Foobar_’, COLUMN_NAME) from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = … Read more

Search a whole table in mySQL for a string

Try something like this: SELECT * FROM clients WHERE CONCAT(field1, ”, field2, ”, fieldn) LIKE “%Mary%” You may want to see SQL docs for additional information on string operators and regular expressions. Edit: There may be some issues with NULL fields, so just in case you may want to use IFNULL(field_i, ”) instead of just … Read more

Test for Upper Case – T-Sql

Using collations eg: if (‘a’=’A’ Collate Latin1_General_CI_AI) print’same 1′ else print ‘different 1’ if (‘a’=’A’ Collate Latin1_General_CS_AI) print’same 2′ else print ‘different 2’ The CS in the collation name indicates Case Sensitive (and CI, Case Insensitive). The AI/AS relates to accent sensitivity. or in your example SUBSTRING(author,1,1) <> LOWER(SUBSTRING(author,1,1)) COLLATE Latin1_General_CS_AI

SQL use CASE statement in WHERE IN clause

No you can’t use case and in like this. But you can do SELECT * FROM Product P WHERE @Status=”published” and P.Status IN (1,3) or @Status=”standby” and P.Status IN (2,5,9,6) or @Status=”deleted” and P.Status IN (4,5,8,10) or P.Status IN (1,3) BTW you can reduce that to SELECT * FROM Product P WHERE @Status=”standby” and P.Status … Read more

Check constraint on existing column with PostgresQL

Use alter table to add a new constraint: alter table foo add constraint check_positive check (the_column > 0); More details and examples are in the manual: http://www.postgresql.org/docs/current/static/sql-altertable.html#AEN70043 Edit Checking for specific values is done in the same way, by using an IN operator: alter table foo add constraint check_positive check (some_code in (‘A’,’B’));

SQL query to get the deadlocks in SQL SERVER 2008 [duplicate]

You can use a deadlock graph and gather the information you require from the log file. The only other way I could suggest is digging through the information by using EXEC SP_LOCK (Soon to be deprecated), EXEC SP_WHO2 or the sys.dm_tran_locks table. SELECT L.request_session_id AS SPID, DB_NAME(L.resource_database_id) AS DatabaseName, O.Name AS LockedObjectName, P.object_id AS LockedObjectId, … Read more

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