Why Not to Use ++ Operators in JavaScript

Priya Pallavi
Updated on 19-Jun-2020 13:37:49

251 Views

The increment (++) and decrement (---) operators should be avoided since it can lead to unexpected results. Here are some of the conditions −ExampleIn an assignment statement, it can lead to unfavorable results −Live Demo                                        var a = 5;                    var b = ++a;                    var c = a++;                    var d = ++c;                        document.write(a);                    document.write("\r"+b);                    document.write("\r"+c);                    document.write("\r"+d);                           OutputWhitespace between the operator and variable can also lead to unexpected results −a = b = c = 1; ++a ; b -- ; c;

Assign FOREIGN KEY Constraint on Multiple Columns

Monica Mona
Updated on 19-Jun-2020 13:37:15

5K+ Views

MySQL allows us to add a FOREIGN KEY constraint on multiple columns in a table. The condition is that each Foreign Key in the child table must refer to the different parent table.ExampleSuppose we have a table ‘customer2’ which have a Primary Key constraint on the field ‘cust_unq_id’ as follows −mysql> describe customer2; +-------------+-------------+------+-----+---------+-------+ | Field       | Type        | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+-------+ | cust_id     | int(11)     | YES  |     | NULL    |       | | First_name  | varchar(20) | ... Read More

Difference Between MySQL DATETIME and TIMESTAMP Data Type

Nancy Den
Updated on 19-Jun-2020 13:33:54

11K+ Views

Both the data types store data in “YYYY-MM-DD HH:MM:SS” format and include date as well as time. In spite of these similarities they are having the following differences −Range − Datetime data type supports a date along with time in the range between 1000-01-01 00:00:00 and 9999-12-31 23:59:59. But timestamp data type supports a date along with time in the range between ‘1970-01-01 00:00:01’ to ‘2038-01-19 08:44:07’.Size − Datetime requires 5 bytes along with 3 additional bytes for fractional seconds’ data storing. On the other hand, timestamp datatype requires 4 bytes along with 3 additional bytes for fractional seconds’ data ... Read More

View Constraints on a Table in Another Database

Sai Nath
Updated on 19-Jun-2020 13:32:38

107 Views

MySQL SHOW CREATE TABLE statement will provide us the constraints applied to a particular table along with some other details about that table stored in another database then I am currently using. Its syntax would be as follows −SyntaxSHOW CREATE TABLE db_name.table_name;Here table_name is the name of the table on which we want to see the constraints.Db_name is the name of the database name in which table is stored.ExampleIn this example we are getting the detail of the table named ‘arena’ stored in MySQL database −mysql> Show Create table mysql.arena\G *************************** 1. row *************************** Table: arena Create Table: CREATE TABLE ... Read More

MySQL DATE Data Types Overview

Daniol Thomas
Updated on 19-Jun-2020 13:32:12

171 Views

MySQL supports following 5 types of DATE data type −DATE - A date is in the range between 1000-01-01 and 9999-12-31. “YYYY-MM-DD” is the default DATE format. For example, January 17th, 1984 would be stored as 1984-01-17.DATETIME − This data type supports a date along with time in the range between 1000-01-01 00:00:00 and 9999-12-31 23:59:59. “YYYY-MM-DD HH:MM:SS” is the default DATETIME format. For example, 2:20 in the afternoon on January 17th, 1984 would be stored as 1984-01-17 14:20:00.TIMESTAMP − A timestamp data type supports a date along with time in the range between ‘1970-01-01 00:00:01’ to ‘2038-01-19 08:44:07’. It ... Read More

Difference Between MySQL PRIMARY KEY and UNIQUE Constraint

Arushi
Updated on 19-Jun-2020 13:31:07

674 Views

The following table will provide us the differences between PRIMARY KEY and UNIQUE constraint −PRIMARY KEYUNIQUE Constraint1. Only one Primary key can be created on a table.1. More than one UNIQUE Constraints can be added to a table.2. Primary key creates clustered index by default.2. UNIQUE Constraint creates a non-clustered index by default.3. We cannot insert null values in the column which is defined as PRIMARY KEY.3. We can insert null values in the column having a UNIQUE constraint.

View Constraints Applied to a Database Table

Samual Sam
Updated on 19-Jun-2020 13:30:26

125 Views

MySQL SHOW CREATE TABLE statement will provide us the constraints applied to a particular table along with some other details about that table. Its syntax would be as follows −SyntaxSHOW CREATE TABLE table_name;Here table_name is the name of the table on which we want to see the constraints.ExampleIn this example we are getting the detail of the table named ‘employees’ −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 ... Read More

CHAR vs VARCHAR Data Types in MySQL

Krantik Chavan
Updated on 19-Jun-2020 13:29:53

390 Views

Actually, both of these data types in MySQL store strings and can be set with a maximum length. The use of these data types purely depends on the need. Followings are some points which will make us clear that when one should CHAR and when VARCHAR −Suppose if we have fixed size of data, such as flags of “Y” and “N” then it is better to use CHAR rather than VARCHAR. It is because 1 byte of length prefix also used with VARCHAR. In other words, for the above kind of data, CHAR will store the only 1byte which is ... Read More

Difference Between CHAR and VARCHAR in MySQL

radhakrishna
Updated on 19-Jun-2020 13:27:55

5K+ Views

CHAR and VARCHAR are both ASCII character data types and almost same but they are different at the stage of storing and retrieving the data from the database. Following are some important differences between CHAR and VARCHAR in MySQL −CHAR Data TypeVARCHAR Data TypeIts full name is CHARACTERIts full name is VARIABLE CHARACTERIt stores values in fixed lengths and are padded with space characters to match the specified lengthVARCHAR stores values in variable length along with 1-byte or 2-byte length prefix and are not padded with any charactersIt can hold a maximum of 255 characters.It can hold a maximum of 65, ... Read More

Disable MySQL Foreign Key Checks and Their Benefits

Rama Giri
Updated on 19-Jun-2020 13:27:24

319 Views

We can disable foreign key checks with the help of the following statement −mysql> Set foreign_key_checks = 0; Query OK, 0 rows affected (0.00 sec)And we can enable it with the help of the following statement −mysql> Set foreign_key_checks = 1; Query OK, 0 rows affected (0.00 sec)Some benefits of disabling foreign key checks are as follows −After disabling foreign key checks we can load data into parent and child table in any order. Otherwise, we must have to load the data first in the parent table and then in the child table.Without disabling foreign key checks we cannot drop ... Read More

Advertisements