Beda Query Script SQL Server dan MySQL

No.KeteranganSQL ServerMySQL
1List columns of a tablesp_columns table_namedescribe table_name
2Get datetimeGetDate()Now()
3Get timezoneSELECT SYSDATETIMEOFFSET()SELECT @@system_time_zone;
4Length of StringLen(‘String’)Character_Length(‘String’)
5Concatenation of stringsSELECT (‘String1’ + ‘String2’)SELECT Concat(‘String1’, ‘String2’)
6Select first 10 recordsSELECT TOP 10 * from TableSELECT * FROM Table LIMIT 10;
7Update Join TableUpdate table1 set column_name = b.column_name from table1 a inner join table2 b where a.key_id = b.key_idupdate table1 a inner join tale2 b on a.key_id = b.key_id  set a.column_name = b.column_name;
8Create procedureCreate procedure proc_name (@argument data_type) as begin….endDELIMITER $$
CREATE PROCEDURE proc_name(IN argument data_type)
begin…..end$$DELIMITER ;
9Select intoSelect column1, column2 into new_table_name from tablecreate table new_table_name select column1, column2 from table;
10Cursorcreate procedure Test
as begin
declare @Nama varchar(255)
declare @SemuaNama varchar(255)set @SemuaNama = ”declare Cursor1 cursor for select Nama from UserPass where FlagAktif = ‘A’
Open Cursor1
Fetch Cursor1 into @Nama
While @@Fetch_Status = 0
begin
select @SemuaNama = @SemuaNama + @Nama +’;’
Fetch Cursor1 into @Nama
end
Close Cursor1
deallocate Cursor1select @SemuaNamaend
DELIMITER $$
CREATE PROCEDURE createEmailList (
INOUT emailList varchar(4000)
)
BEGIN
DECLARE finished INTEGER DEFAULT 0;
DECLARE emailAddress varchar(100) DEFAULT “”;— declare cursor for employee email
DEClARE curEmail
CURSOR FOR
SELECT email FROM employee where level = 3 and active = 1;— declare NOT FOUND handler
DECLARE CONTINUE HANDLER
FOR NOT FOUND SET finished = 1;OPEN curEmail;getEmail: LOOP
FETCH curEmail INTO emailAddress;
IF finished = 1 THEN
LEAVE getEmail;
END IF;
— build email list
SET emailList = CONCAT(emailAddress,”;”,emailList);
END LOOP getEmail;
CLOSE curEmail;END$$
DELIMITER ;

Leave a Reply

Your email address will not be published. Required fields are marked *