Found 6705 Articles for Database

How to set MySQL default value NONE?

AmitDiwan
Updated on 24-Sep-2019 13:03:19

784 Views

To set the default value in MySQL, you need to use the DEFAULT keyword. Let us first create a table −mysql> create table DemoTable (    ClientCountryName varchar(100) DEFAULT 'NONE' ); Query OK, 0 rows affected (0.65 sec)We have set DEFAULT above for values not entered while insertion. Now, let us insert some records in the table using the insert command. We haven’t inserted values here for some of the rows. The DEFAULT gets set there −mysql> insert into DemoTable values('US'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.09 sec) ... Read More

MySQL select statement to fetch 5 characters from the left of the string

AmitDiwan
Updated on 24-Sep-2019 13:01:07

257 Views

To fetch number of characters from the left of the string, use the LEFT method in MySQL. Let us first create a table −mysql> create table DemoTable (    Name varchar(100) ); Query OK, 0 rows affected (6.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Sam Brown'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('David Miller'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('Adam Smith'); Query OK, 1 row affected (7.01 sec) mysql> insert into DemoTable values('Carol Taylor'); Query OK, 1 row affected (0.68 sec)Display all ... Read More

Can we use SELECT NULL statement in a MySQL query?

AmitDiwan
Updated on 24-Sep-2019 12:56:07

255 Views

Yes, we can use the SELECT NULL statement in a MySQL query. Let us first create a table −mysql> create table DemoTable (    Name varchar(100) ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('Sam'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Bob'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected ... Read More

Update only a single value from a MySQL table where select from same table ordered in descending order?

AmitDiwan
Updated on 24-Sep-2019 12:53:55

102 Views

For this, use ORDER BY DESC with the LIMIT clause. The ORDER BY DESC order in descending order where LIMIT sets the number of records you want. Here, we will set LIMIT 1 since we want only a single record. Let us first create a table −mysql> create table DemoTable (    StudentName varchar(100),    StudentMarks int ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 45); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Bob', 78); Query OK, 1 row affected (0.16 sec) mysql> ... Read More

Return true or false in a MySQL select if another field contains a string?

AmitDiwan
Updated on 24-Sep-2019 12:45:24

2K+ Views

To return TRUE or FALSE if another field contains a string, use IF(). Let us first create a tablemysql> create table DemoTable (    FirstName varchar(100),    LastName varchar(100) ); Query OK, 0 rows affected (1.28 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 'Brown'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('David', 'Miller'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Adam', 'Smith'); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following ... Read More

How to get a value more than a particular value from varchar column in MySQL?

AmitDiwan
Updated on 24-Sep-2019 12:40:10

475 Views

Since the column wherein you want to get the value more than a particular value is VARCHAR, use the CAST() function. For example, to fetch the value more than 999 from a column with varchar values.Let us first create a table −mysql> create table DemoTable (    Value varchar(100) ); Query OK, 0 rows affected (1.02 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('900'); Query OK, 1 row affected (0.49 sec) mysql> insert into DemoTable values('1090'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('860'); Query OK, 1 row affected (0.25 ... Read More

MySQL query to check if a string contains a value (substring) within the same row?

AmitDiwan
Updated on 24-Sep-2019 12:36:49

1K+ Views

Since we need to match strings from the same row, use LIKE operator. Let us first create a table −mysql> create table DemoTable (    FirstName varchar(100),    FullName varchar(100) ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John', 'John Smith'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('David', 'John Miller'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Bob', 'Sam Miller'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Chris', 'Chris Brown'); Query OK, 1 row affected ... Read More

Program for Fibonacci numbers in PL/SQL

Sunidhi Bansal
Updated on 24-Dec-2024 17:56:51

12K+ Views

Given ‘n’ numbers the task is to generate the Fibonacci numbers in PL/SQL starting from 0 to n, where the Fibonacci series of integers is in the form 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 Where integers 0 (1st place) and 1 (2nd place) will have a fixed place after that, the previous two digits will be added to get the integer of the next place as shown below. 0+1=1 (3rd place) 1+1=2 (4th place) 2+1=3 (5th place) and So on. Formula Sequence F(n) ... Read More

Difference between SQL and NoSQL

Kiran Kumar Panigrahi
Updated on 28-Jul-2022 11:51:45

4K+ Views

Both SQL and NoSQL Databases have their set of advantages and disadvantages. SQL databases can be considered when you are looking for data consistency, reliability, integrity, and when the data is structured. NoSQL databases are a much better option if the data is large, semi-structured, or unstructured and you are looking for faster storage and retrieval of data.With so many databases available in the market, it can get a little challenging for an enterprise to decide whether they should choose an SQL Database or a NoSQL Database. This article will show you the key differences between the two types of ... Read More

Difference between Normalization and Denormalization

Kiran Kumar Panigrahi
Updated on 02-Dec-2022 05:33:16

23K+ Views

The process to alter the structure of a database is basically categorized into two ways, one is Normalization and the other is Denormalization. The basic difference between normalization and denormalization is that the database normalization removes the redundancy of data and anomalies in a poorly designed table, while denormalization combines multiple table data into one so that it can be queried quickly. Read through this article to find out more about normalization and denormalization and how they are different from each other. What is Normalization? Normalization is used to remove redundant data from the database and to store non-redundant and ... Read More

Advertisements