MySQL Articles

Page 352 of 355

What will happen if the MySQL AUTO_INCREMENT column reaches the upper limit of the data type?

vanithasree
vanithasree
Updated on 30-Jul-2019 854 Views

When the AUTO_INCREMENT column reaches the upper limit of data type then the subsequent effort to generate the sequence number fails. That is why it is advised to use a large enough integer data type for the AUTO_INCREMENT column to hold the maximum sequence value required by us. For example, if we will use TINYINT then AUTO_INCREMENT would be able to generate only 127 sequence numbers and in case of UNSIGNED TINYINT, this value can be extended up to 255.

Read More

How can we add a FOREIGN KEY constraint to the field of an existing MySQL table?

Ankitha Reddy
Ankitha Reddy
Updated on 30-Jul-2019 2K+ Views

We can add a FOREIGN KEY constraint to a column of an existing MySQL table with the help of ALTER TABLE statement. Syntax ALTER TABLE table_name ADD FOREIGN KEY (colum_name) REFERENCES table having Primary Key(column_name); Example Suppose we want to add a FOREIGN KEY constraint on the table ‘Orders1’ referencing to the table ‘Customer’ which have column ‘Cust_Id’ as the Primary Key. It can be done with the help of the following query − mysql> Alter table orders1 add FOREIGN KEY(Cust_id) REFERENCES Customer(Cust_id); Query OK, 0 rows affected (0.21 sec) Records: 0  Duplicates: 0  Warnings: 0   mysql> ...

Read More

In MySQL, why a client cannot use a user-defined variable defined by another client?

Sreemaha
Sreemaha
Updated on 30-Jul-2019 325 Views

In MySQL, a user-defined variable defined by one client cannot be seen or used by another client because user-defined variables are connection-specific. It means that all variables for a given client connection are automatically freed when that client exits

Read More

How Can we permanently define user-defined variable for a client in MySQL?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 345 Views

In MySQL, it is not possible that a client can hold user variable permanently. It is because all the variables for a given client connection are automatically freed when that client exits.

Read More

How can we remove FOREIGN KEY constraint from a column of an existing MySQL table?

George John
George John
Updated on 30-Jul-2019 11K+ Views

We can remove FOREIGN KEY constraint from a column of an existing table by using DROP keyword along with ALTER TABLE statement. Syntax ALTER TABLE table_name DROP FOREIGN KEY constraint_name Here constraint name is the name of foreign key constraint which we applied while creating the table. If no constraint name is specified then MySQL will provide constraint name which can be checked by SHOW CREATE TABLE statement. Example The following query will delete the FOREIGN KEY constraint from ‘orders’ table − mysql> Alter table orders DROP FOREIGN KEY orders_ibfk_1; Query OK, 0 rows affected (0.22 sec) ...

Read More

How MySQL LOCATE() function is different from its synonym functions i.e. POSITION() and INSTR() functions?

Rama Giri
Rama Giri
Updated on 30-Jul-2019 624 Views

As all of these functions are used to return the position of a substring within a string but LOCATE() function is a bit different from POSITION() and INSTR() function. In both POSITION() AND INSTR() functions, we cannot manage the starting position of search with the help of argument as position argument in LOCATE() function. All of these functions are having a difference in syntax also.

Read More

How can we apply AUTO_INCREMENT to a column?

George John
George John
Updated on 30-Jul-2019 207 Views

AUTO_INCREMENT means that the column will get the value automatically. To illustrate it we have created a table ‘employees’ as follows − mysql> Show Create Table employees\G *************************** 1. row *************************** Table: employees Create Table: CREATE TABLE `employees` ( `Id` int(11) NOT NULL AUTO_INCREMENT, `Name` varchar(35) DEFAULT NULL, PRIMARY KEY (`Id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 1 row in set (0.00 sec) From the above result set, we can see that column id is given the auto-increment option. Now, when we will insert the value in Name ...

Read More

How can we check that by default MySQL CHAR() function returns a binary string?

Sai Subramanyam
Sai Subramanyam
Updated on 30-Jul-2019 152 Views

With the help of CHARSET() function, we can check which string is returned by MySQL CHAR() function. Following result set will demonstrate it − mysql> Select CHARSET(CHAR(85)); +-------------------+ | CHARSET(CHAR(85)) | +-------------------+ | binary | +-------------------+ 1 row in set (0.00 sec)

Read More

How does the value of system variable max_allowed_packet affect the result of a string-valued function?

Rishi Raj
Rishi Raj
Updated on 30-Jul-2019 267 Views

String-valued functions return NULL if the length of the result would be greater than the value of the max_allowed_packet system variable. Actually, max_allowed_packet is a dynamic global variable which can accept the integer type values. These values can be set for a session only. It can accept 1024 as the minimum value and 1073741824 as the maximum value. The by the default value of this system variable is 1048576.

Read More

What are the drawbacks of using test database?

Sai Subramanyam
Sai Subramanyam
Updated on 30-Jul-2019 250 Views

There is a database named test in the list of databases displayed by the statement SHOW DATABASES. We can use test database but the main disadvantage is that anything created in this database can be removed/changed by anyone else with access to it. To avoid this we should take permission from MySQL administrator to use a database of our own. For taking permission following command must be run − mysql> grant all on tutorial.* to root@localhost; Query OK, 0 rows affected (0.10 sec) In the above command, I am taking permission for the tutorial database. Root is the ...

Read More
Showing 3511–3520 of 3,543 articles
Advertisements