Found 4381 Articles for MySQL

Set MySQL select in a custom variable

AmitDiwan
Updated on 06-Apr-2020 12:51:59

373 Views

Let us first create a table −mysql> create table DemoTable2013    -> (    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2013 values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2013 values('David'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2013 values('Mike'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable2013 values('Sam'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable2013 values('Bob'); Query OK, 1 row affected (0.12 sec)Display all ... Read More

Format date while inserting records in MySQL

AmitDiwan
Updated on 06-Apr-2020 12:50:12

561 Views

To format date while inserting records, use DATE_FORMAT() in the MySQL INSERT statement. Let us first create a table −mysql> create table DemoTable2012    -> (    -> ShippingDate varchar(20)    -> ); Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2012 values(date_format(curdate(), '%d.%m.%Y')); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2012 values(date_format(now(), '%d.%m.%Y')); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2012 values(date_format('2014-01-21', '%d.%m.%Y')); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement −mysql> select *from ... Read More

MySQL stored procedure to execute SHOW CREATE TABLE?

AmitDiwan
Updated on 06-Apr-2020 12:48:14

475 Views

To execute SHOW CREATE TABLE in a stored procedure, use SHOW CREATE TABLE. Let us first create a table −mysql> create table DemoTable2011    -> (    -> StudentId int NOT NULL AUTO_INCREMENT,    -> StudentName varchar(20),    -> StudentAge int,    -> StudentCountryName varchar(20),    -> PRIMARY KEY(StudentId)    -> ); Query OK, 0 rows affected (0.80 sec)Following is the stored procedure executing SHOW CREATE TABLE −mysql> delimiter // mysql> create procedure test_show_create_demo(table_name varchar(100))    -> begin    -> set @query=concat("SHOW CREATE TABLE ", table_name);    -> prepare st from @query;    -> execute st;    -> end   ... Read More

How to properly use 'exist' function in MongoDB like in SQL?

AmitDiwan
Updated on 27-Mar-2020 12:34:34

163 Views

To check for existence of a record, use findOne() in MongoDB. Let us first create a collection with documents −> db.existsAlternateDemo.insertOne({"StudentName":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e06d23f9e4dae213890ac5c") } > db.existsAlternateDemo.insertOne({"StudentName":"Chris", "StudentAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e06d2559e4dae213890ac5d") } >db.existsAlternateDemo.insertOne({"StudentName":"Chris", "StudentAge":22, "StudentCountryName":"US"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e06d2689e4dae213890ac5e") }Following is the query to display all documents from a collection with the help of find() method −> db.existsAlternateDemo.find();This will produce the following output −{ "_id" : ObjectId("5e06d23f9e4dae213890ac5c"), "StudentName" : "Chris" } { "_id" : ObjectId("5e06d2559e4dae213890ac5d"), "StudentName" : "Chris", "StudentAge" : 21 } { ... Read More

Mean and Mode in SQL Server

Narendra Kumar
Updated on 10-Feb-2020 10:08:33

2K+ Views

Problem statementMean is the average of the given data set calculated by dividing the total sum by the number of values in the data set.Mode of a data set is the value that appears most frequently in a series of dataIf our dataset is {1, 2, 3, 4} then mean value is − (1 + 2 + 3 + 4) / 4 = 2.5If our dataset is {1, 2, 3, 4, 1, 1, 1, 1} then mode value is − 1 as it appears 5 times.ExampleFirst, create a table −CREATE TABLE NUMBERS (    value INT )Insert data into the ... Read More

MySqldb Connection in Python

Pradeep Elance
Updated on 04-Feb-2020 06:44:47

300 Views

Mysql is one of the most widely used open source Dbs. Python provides ways to connect to this DB and use the DB to store and retrive the data from it.Install pymysqlDepending on the python environment you are using, pymysql package can be installed using one of the following methods.# From python console pip install pymysql #Using Anaconda conda install -c anaconda pymysql # Add modules using any python IDE pymysqlConnecting to MySqlNow we can connect to the Mysql environment using the following code. After connecting we are finding out the version of the DB.Exampleimport pymysql # Open database connection ... Read More

Important MYSQL Performance Tuning and Settings after Installation

Sharon Christine
Updated on 24-Jan-2020 09:50:49

550 Views

In this article, we will learn and discuss some important performance tuning settings for MySQL which we need to implement after the MySQL Installation better and speedy performance.Pre-requisitesAssuming that we have already installed the MySQL, I am providing some tips before we start to know about Performance tuning settings for MySQL.Even experienced IT persons may make some mistakes which will lead to many problems, so before we apply any recommendations which are shown in this article, we will keep the below items in mind to avoid issues or problems.We will apply only one setting at a time so that we ... Read More

How to Install and Configure MS SQL (Beta) on CentOS 7

Samual Sam
Updated on 23-Jan-2020 07:57:45

402 Views

In this article, we will learn about – How to install and configure MS SQL on CentOS 7. Microsoft has recently announced that they are planning to release the MS SQL for Linux. Specially the beta versions for RedHat enterprises Linux, Centos & Ubuntu but only with 64-bit editions.PrerequisitesA machine with a minimum of 4 GB RAM and 30 GB Hard disk space.A machine installed with CentOS 7.A user with root privileges or root user.MS SQL Server installation on CentOSSince MS SQL is not available with the default CentOS repository, we needed to add the MS SSQL repository details to ... Read More

Print all odd numbers and their sum from 1 to n in PL/SQL

sudhir sharma
Updated on 22-Jan-2020 09:46:19

3K+ Views

In this problem, we are given a number n and we have to print all odd numbers from 1 to n and also print the sum of numbers from 1 to n in PL/SQL.PL/SQL is a procedural language extension to SQL. The code is a sequence of instructions that are ground in a block with all related declarations and instructions.Let’s see an example of our problem −Input: 7 Output: odd numbers are: 1, 3, 5, 7 Sum of odd numbers is 16To solve this problem, we will take a number and initialize it to 1 and a sum variable with ... Read More

How to Migrate MySQL to MariaDB on Linux?

Sharon Christine
Updated on 22-Jan-2020 08:21:42

428 Views

This article will help you to migrate the database from MySQL to MariaDB as the binary compatibility of MySQL-to-MariaDB in the migration process is very much straightforward.After the Oracle’s acquisition of MySQL, the community has driven an outcome of such movement and developed a new database called MariaDB. MariaDB is the open-source and its compatibility with MySQL. Most of the Linux distributions (RH, CentOS, Fedora) have already started to use the support of MariaDB as a drop-in replacement of MySQL.If we want to migrate the database from MySQL to MariaDB then this article will help.Preparing a MySQL Database and TablesWe ... Read More

Advertisements