Found 6702 Articles for Database

What is the Maximum Value of smallint(6) unsigned in MySQL?

Arjun Thakur
Updated on 30-Jul-2019 22:30:24

1K+ Views

The maximum value of SMALLINT(6) unsigned in MySQL is 65535. The number 6 does not affect the actual range. It can only be used to display width on the command line.The Minimum Value signed is-32768The Maximum Value unsigned is65535The Maximum value signed is32767Let us understand this with zerofill and create a table using the following query.mysql> create table smallIntDemo -> ( -> FirstNumber smallint(6) zerofill -> ); Query OK, 0 rows affected (1.95 sec)Now you can insert records in the table using insert command. Whenever you insert beyond the range 65535, it will not insert in the table, since this ... Read More

How to select an empty result set in MySQL?

Anvi Jain
Updated on 30-Jul-2019 22:30:24

854 Views

Select an empty result set with the help of dummy table ‘dual’ from MySQL. The query is as follows −mysql> select 1 from dual where false; Empty set (0.00 sec)In the above query, “dual” is a dummy table and the above condition false. Therefore, it returns empty set.Let us check with true condition. It will return the selected value. The query is as follows −mysql> select 1 from dual where true;The following is the output −+---+ | 1 | +---+ | 1 | +---+ 1 row in set (0.00 sec)

Is there a difference in using INT(1) vs TINYINT(1) in MySQL?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:24

1K+ Views

The number 1 used in parenthesis is only for width display. The INT(1) and TINYINT(1) does not influence the storage.The TINYINT takes 1 byte that means it has range -128 to +127 while int takes 4 bytes; it has range -2147483648 to +2147483647To understand the width display, let us create a table −mysql> create table intAndTinyint    −> (    −> FirstNumber int(1) zerofill,    −> SecondNumber tinyint(1) zerofill    −> ); Query OK, 0 rows affected (0.52 sec)Now you can insert records in the table. The query is as follows −mysql> insert into intAndTinyint values(1, 1); Query OK, 1 ... Read More

Get the first and last date of next month in MySQL?

Ankith Reddy
Updated on 30-Jul-2019 22:30:24

823 Views

You can get the first and last date of next month using date_add() function from MySQL.The syntax is as follows -select date_sub(    last_day(       date_add(now(), interval anyIntervalTime)    ),    interval day(       last_day(          date_add(now(), interval anyIntervalTime)       )    )-1 DAY ) as anyVariableName, last_day ( date_add(now(), anyIntervalTime) ) as anyVariableName;Implement the above syntax to get the first and last date of next month using interval 1 month in date_add() function. The query is as follows.mysql> select -> date_sub( ->    last_day( ->     ... Read More

MySQL Select Multiple VALUES?

Rishi Rathor
Updated on 29-Jun-2020 09:07:55

19K+ Views

To select multiple values, you can use where clause with OR and IN operator.The syntax is as follows −Case 1 − Using ORselect *from yourTablename where yourColumnName = value1 or yourColumnName = value2 or yourColumnName = value3, .........N;Case 2 − Using INselect *from yourTableName where yourColumnName IN(value1, value2, ....N);To understand the above syntax, let us create a table. The following is the query to create a table −mysql> create table selectMultipleValues −> ( −> BookId int, −> BookName varchar(200) −> ); Query OK, 0 rows affected (1.68 sec)Now you can insert some records in the table with the help of ... Read More

How to insert multiple rows with single MySQL query?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:24

303 Views

You can insert multiple rows with the help of values() separated by comma(, ). The syntax is as follows −insert into yourTableName values(value1, value2, ...N), (value1, value2, ...N), (value1, value2, ...N), (value1, value2, ...N), (value1, value2, ...N), (value1, value2, ...N)................N;To insert multiple rows, let us create a table. The following is the query to create a table −mysql> create table MultipleRowsInsert    −> (    −> UserId int,    −> UserName varchar(200)    −> ); Query OK, 0 rows affected (1.21 sec)Here is the query to insert multiple rows in the table −mysql> insert into MultipleRowsInsert values(100, 'Bob'), (101, 'Smith'), ... Read More

What does DELIMITER // do in a Trigger in MySQL?

George John
Updated on 29-Jun-2020 09:09:05

2K+ Views

The DELIMITER // can be used to change the statement from semicolon (;) to //. Now you can write multiple statements with semi-colon in a trigger.Here is the demo of triggers. In this example whenever you enter the EmployeeSalary less than 1000 then it will by default set to 10000.Firstly, let us create a table. The query to create a table is as follows -mysql> create table EmployeeTable -> ( -> EmployeeId int, -> EmployeeName varchar(100), -> EmployeeSalary float -> ); Query OK, 0 rows affected (0.76 sec)After creating a table, you need to create a trigger on insert command. ... Read More

Setting similar value for a column in a MySQL table?

Anvi Jain
Updated on 30-Jul-2019 22:30:24

54 Views

You can set value for a column of all records with the help of update command.The syntax is as follows if you want set NULL value for all the records in a column −update yourTableName set yourColumnName = NULL;Or if you want to use empty string, the following is the syntax −update yourTableName set yourColumnName = ’’;To understand the above concept, let us create a table. The query to create a table.mysql> create table StudentDemo    −> (    −> Studentid int,    −> StudentName varchar(100),    −> Age int    −> ); Query OK, 0 rows affected (0.64 sec)The ... Read More

int(5) vs. int(10) in MySQL?

Vrundesha Joshi
Updated on 29-Jun-2020 09:11:10

1K+ Views

The value in the parentheses is used to display only the width and sets the zerofill. The width is 5 for int(5), whereas 10 for int(10). Let us see another example with a different width value set for int.Let us first create a table. Here, we have set the int to int(11) and int(13). The following is the query to create a table −mysql> create table intVsIntAnyThingDemo −> ( −> Number1 int(11) unsigned zerofill, −> Number int(13) unsigned zerofill −> ); Query OK, 0 rows affected (1.17 sec)Now you can insert record in the table with the help of insert ... Read More

Set the result of a query to a variable in MySQL?

Chandu yadav
Updated on 29-Jun-2020 09:10:38

326 Views

You can set the result of a query using select into command. The syntax is as follows.select yourColumnName1 into @anyVariableName from yourTableName where yourColumnName2='anyValue';Check the result is present in the variable or not using the select command. The syntax is as follows -select @anyVariableName;To understand the above syntax, let us first create a table. The query to create a table is as follows.mysql> create table StudentInformation -> ( -> StudentId int, -> StudentName varchar(100), -> StudentAge int -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command. The query is as follows.mysql> insert ... Read More

Advertisements