How to DROP multiple columns with a single ALTER TABLE statement in SQL Server?

For SQL Server: ALTER TABLE TableName DROP COLUMN Column1, Column2; The syntax is DROP { [ CONSTRAINT ] constraint_name | COLUMN column } [ ,…n ] For MySQL: ALTER TABLE TableName DROP COLUMN Column1, DROP COLUMN Column2; or like this1: ALTER TABLE TableName DROP Column1, DROP Column2; 1 The word COLUMN is optional and can … Read more

MySQL Cannot Add Foreign Key Constraint

To find the specific error run this: SHOW ENGINE INNODB STATUS; And look in the LATEST FOREIGN KEY ERROR section. The data type for the child column must match the parent column exactly. For example, since medicalhistory.MedicalHistoryID is an INT, Patient.MedicalHistory also needs to be an INT, not a SMALLINT. Also, you should run the … Read more

T-SQL Cast versus Convert

CONVERT is SQL Server specific, CAST is ANSI. CONVERT is more flexible in that you can format dates etc. Other than that, they are pretty much the same. If you don’t care about the extended features, use CAST. EDIT: As noted by @beruic and @C-F in the comments below, there is possible loss of precision … Read more

Simulating group_concat MySQL function in Microsoft SQL Server 2005?

No REAL easy way to do this. Lots of ideas out there, though. Best one I’ve found: SELECT table_name, LEFT(column_names , LEN(column_names )-1) AS column_names FROM information_schema.columns AS extern CROSS APPLY ( SELECT column_name + ‘,’ FROM information_schema.columns AS intern WHERE extern.table_name = intern.table_name FOR XML PATH(”) ) pre_trimmed (column_names) GROUP BY table_name, column_names; Or … Read more

Connect different Windows User in SQL Server Management Studio (2005 or later)

While there’s no way to connect to multiple servers as different users in a single instance of SSMS, what you’re looking for is the following RUNAS syntax: runas /netonly /user:domain\username program.exe When you use the “/netonly” switch, you can log in using remote credentials on a domain that you’re not currently a member of, even … Read more

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