By: Daniel Calbimonte | Updated: 2015-02-27 | Comments | Related: > Other Database Platforms
Problem
In part 1 and part 2 of this series, I compared SQL commands for MariaDB and SQL Server. In this tip, we will show more examples such as concatenation, cursors, how to split comma separated values, how to import xml data and more.
Solution
In this tip we will look at various things you do in a database and the differences between SQL Server and MariaDB.
Requirements and setup
- SQL Server 2014 or earlier versions.
- The MariaDB should be installed. In this tip, I installed MariaDB and the SQL Server on the same Windows OS. You can find the MariaDB installer here.
Code Comparison for SQL Server vs. MariaDB
How to concatenate strings
SQL Server
|
MariaDB |
---|---|
select concat('This is the way to','concatenate') More information: |
select concat('This is the way to','concatenate') |
How to concatenate strings with numbers
SQL Server
|
MariaDB |
---|---|
select concat('This is the way to concatenate the number ',1) |
select concat('This is the way to concatenate the number ',1); |
How to work with cursors
SQL Server
|
MariaDB |
---|---|
/*The example creates a table with names and the cursor concatenates all the names of each row in a single row. Note that in SQL Server the use of cursors is not recommended for performance reasons.*/ create table name(name varchar(30)); insert into name values('John'), DECLARE db_cursor CURSOR FOR DECLARE @name VARCHAR(100),@string VARCHAR(100)='' OPEN db_cursor WHILE @@FETCH_STATUS = 0 FETCH NEXT FROM db_cursor INTO @name CLOSE db_cursor
More information:
|
create table name(name varchar(30)); insert into name values('John'), DELIMITER $$ DECLARE db_cursor1 CURSOR FOR DECLARE CONTINUE HANDLER SET @string = ""; |
How to splits rows with values separated by comas in multiple rows
SQL Server
|
MariaDB |
---|---|
Create table test(name varchar(2000)); insert into test values('Dennis,Joseph,Joel'), SELECT
More information: |
Create table test(name varchar(2000)); insert into test values('Dennis,Joseph,Joel'), SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(t.name, ',', n.n), ',', -1) name |
How to import data from a xml file to a table
SQL Server
|
MariaDB |
---|---|
In SQL Server it is harder to do than using MariaDB. For a complete tutorial, read our article: Importing and Processing data from XML files into SQL Server tables. |
create table mssqltips
LOAD XML INFILE 'filexml2.xml' |
How to backup a database
SQL Server
|
MariaDB |
---|---|
BACKUP DATABASE database-name TO DISK = 'c:\SQL\backup-file.bak' More information: |
--Exit the mysql and in the mysql bin folder, execute this commands(the mysqldump command is used): mysqldump -u loginname -p database_name > backup-file.sql -- You will be prompted to enter your password |
How to restore a database
SQL Server
|
MariaDB |
---|---|
RESTORE DATABASE database-name More information: |
mysqldump -u root -p mysql < backup-file.sql |
How to backup all the databases
SQL Server
|
MariaDB |
---|---|
You can use the Maintenance Wizard, the SSIS Back UP Task or this article for a T-SQL solution: Simple script to backup all SQL Server databases |
mysqldump -u root -p --all-databases > all_databases.sql |
How to send emails
SQL Server
|
MariaDB |
---|---|
EXEC msdb.dbo.sp_send_dbmail More information: |
By default, it is no longer supported. You may need to use other programming tools to integrate this functionality. |
Next Steps
Read Part 1 and Part 2 of this series
For more information about T-SQL and MariaDB, refer to the following links:
- http://www.sqljason.com/
- http://stackoverflow.com/questions/19073500/sql-split-comma-separated-row
- SQL Server T-SQL Tips
About the author
This author pledges the content of this article is based on professional experience and not AI generated.
View all my tips
Article Last Updated: 2015-02-27