Wednesday, June 12, 2019

MySQL Basic Operations

Here are some basic operations need to keep in mind for the MySQL beginners jumping into it from MS-SQL
- First things is, need to have MySQL Workbench to be installed for the same
- For MYSql most of the syntaxes remains same but still there are some points to note and are belows.

(1) ";" required for multiple query in batch
- For query to execute, it requires ";" at the end of statement. Also, same would be apply if there are multiple queries are there .
- for e.g.
MS-SQL - Select * From Table1
Select * From Table2
MySQL  - Select * From Table1;
Select * From Table2;

(2) Finding top item
- With respect to fetch top 1 item, here in MySQL same would be fetched by limit
- for e.g
MS-SQL - Select top 1 * from Table
MySQL  - Select * From Table limit 1;

(3) Call Stored Procedure
MS-SQL - exec procname
MySQL  - CALL `dbname`.`procname`(parameter, if any);

(4) Get Current Date
MS-SQL - GETDATE()
MySQL  - NOW()

(5) Null Check for field
MS-SQL - ISNULL(field, 'default value')
MySQL  - IFNULL(field. 'default value')

(6) If Exist: 
MS-SQL - 
If Exists(Select ID From Table Where ID = 10)
Begin
End
Else
Begin
End
MySQL
if exists(select Id from users where Id=_UserId) then

else

end If;

(7) Temporary Table
MS-SQL - There are couple of way to do so
- Temporary CREATE TABLE #TableName
(
column1 VARCHAR(50) 
)
- Global Temporary Table
SELECT column1 INTO ##TempTable

MySQL
- CREATE TEMPORARY TABLE TempTable