MySQLi Articles

Page 46 of 341

Show constraints on table command in MySQL?

Arjun Thakur
Arjun Thakur
Updated on 26-Jun-2020 3K+ Views

You can show constraints on tables with the help of SHOW command. The syntax is as follows −show create table yourTableName;The above command will show all constraints with table ENGINE. Using this, you can even see all the column names and corresponding data types.To understand the above MySQL statement, let us first create a table −mysql> create table ShowConstraintsDemo    -> (    -> BookId int not null, -> BookName varchar(200) not null, -> BookAuthor varchar(200) Unique not null, -> Primary key(BookId, BookName) -> ); Query OK, 0 rows affected (1.04 sec)Now you can apply the above syntax in order ...

Read More

What do column flags mean in MySQL Workbench?

Ankith Reddy
Ankith Reddy
Updated on 26-Jun-2020 5K+ Views

In MySQL Workbench, column flags can be used with a column to maintain integrity. The column flags are as follows −PK − Primary KeyNN − NOT NULLBIN − BinaryUN − UnsignedUQ − UniqueZF − Zero FilledG − Generate ColumnAI − Auto IncrementLet us learn about them one by one −PKThis stands for the primary key. It can be used to make the column as a primary key.NNIt is for NOT NULL. Used to enforce the column that it will not insert a NULL value.BINThis stands for Binary. This can be used to store data as a binary string.UNIt is for ...

Read More

Does MySQL foreign_key_checks affect the entire database?

Arjun Thakur
Arjun Thakur
Updated on 26-Jun-2020 5K+ Views

The foreign_key_checks are session based. Now, we can say that they are for scope i.e. local or global. Here is an example demo of local or global. Both are scopes and we can set this for session.Let us set the scope −mysql> set foreign_key_checks = 0; Query OK, 0 rows affected (0.00 sec) mysql> set global foreign_key_checks = 0; Query OK, 0 rows affected (0.05 sec)The foreign_key_checks variables are server system variables. Here are some more details −PropertyValueSystem Variableforeign_key_checksScopeGlobal, SessionDynamicYesTypeBooleanDefault ValueONSetting foreign_key_checks to 0It affects data definition statements: DROP SCHEMA drops a schema even if it contains tables that have ...

Read More

Is it possible to use UPDATE query with LIMIT in MySQL?

Chandu yadav
Chandu yadav
Updated on 26-Jun-2020 11K+ Views

Yes, it is possible to use UPDATE query with LIMIT in MySQL. Let us see how.For our example, we will first create a table. The CREATE command is used to create a table.mysql>CREATE table tblUpdateLimit -> ( -> id int, -> name varchar(100) -> ); Query OK, 0 rows affected (0.53 sec)Records are inserted with the help of INSERT command.mysql>INSERT into tblUpdateLimit values(1, 'John'); Query OK, 1 row affected (0.54 sec) mysql>INSERT into tblUpdateLimit values(2, 'Carol'); Query OK, 1 row affected (0.12 sec) mysql>INSERT into tblUpdateLimit values(3, 'Smith'); Query OK, 1 row affected (0.10 sec) mysql>INSERT into ...

Read More

How to check similarity between two strings in MySQL?

Arjun Thakur
Arjun Thakur
Updated on 26-Jun-2020 2K+ Views

Similarity between two strings can be checked with the help of ‘strcmp()’ function. Here are the conditions.If both strings are equal, then it returns 0.If first string is less than the second string, it returns -1.If first string is greater than the second string, it returns 1.Here is an example.Case 1 − If both strings are equal.The following is the query.mysql > SELECT STRCMP("demo", "demo");The following is the output of the above query.+------------------------+ | STRCMP("demo", "demo") | +------------------------+ | 0 ...

Read More

How to escape single quotes in MySQL?

Chandu yadav
Chandu yadav
Updated on 26-Jun-2020 590 Views

We can escape single quotes with the help of the SELECT statement. For instance, when single quotes are encountered in a name, eg. “Carol’s”.Let us see the syntax.SELECT ‘SomeValue’;Here is an example that display how to include text with single quotes.mysql> SELECT 'Carol\'s Taylor.'; The following is the output.+-------------------+ | Carol's Taylor | +-------------------+ | Carol's Taylor | +-------------------+ 1 row in set (0.00 sec)

Read More

Which one is better in MySQL - NULL or empty string?

Arjun Thakur
Arjun Thakur
Updated on 26-Jun-2020 481 Views

The choice depends upon the database. In ORACLE database, an empty string is converted to NULL.In MySQL, the usage of an empty string is better as compared to NULL. It is easy to check for an empty string with some boundary conditions, while this cannot be done with NULL. To find NULL, we need to add an extra condition i.e. ‘IS NULL’We can check that the length of NULL is 0 while length of empty string is 1.To check the length of NULL.mysql>SELECT count(NULL);The following is the output of the above query.+-----------------+ | count(NULL) | +-----------------+ ...

Read More

Fetch rows where a field value is less than 5 chars in MySQL?

Samual Sam
Samual Sam
Updated on 26-Jun-2020 820 Views

To fetch rows where a field value is less than 5 chars, you need to use LENGTH() function. The syntax is as follows −SELECT *FROM yourTableName WHERE LENGTH(yourColumnName) < 5;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table fieldLessThan5Chars    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> yourZipCode varchar(10)    -> ); Query OK, 0 rows affected (0.52 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into fieldLessThan5Chars(yourZipCode) values('35801'); Query ...

Read More

MySQL query to include more than one column in a table that doesn&#039;t already exist

Samual Sam
Samual Sam
Updated on 26-Jun-2020 214 Views

You can easily add more than one column that does not exist in a query using multiple AS keywords.Let us first create a table. The query to create a table is as follows −mysql> create table ColumnDoesNotExists    -> (    -> UserId int,    -> UserName varchar(20)    -> ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into ColumnDoesNotExists(UserId, UserName) values(100, 'Larry'); Query OK, 1 row affected (0.14 sec) mysql> insert into ColumnDoesNotExists(UserId, UserName) values(101, 'Sam'); Query OK, 1 row affected (0.22 sec) mysql> ...

Read More

Adding a column that doesn&#039;t exist in a query?

karthikeya Boyini
karthikeya Boyini
Updated on 26-Jun-2020 1K+ Views

Add a column that does not exist in a query, with the help of AS keyword. The syntax is as follows −SELECT yourColumnName1, yourColumnName2, ....N, yourValue AS yourColumnName, ....N' FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table ColumnDoesNotExists     -> (     -> UserId int,     -> UserName varchar(20)     -> ); Query OK, 0 rows affected (0.67 sec)ExampleInsert some records in the table using insert command. The query is as follows −mysql> insert into ColumnDoesNotExists(UserId, UserName) values(100, 'Larry'); Query OK, ...

Read More
Showing 451–460 of 3,404 articles
« Prev 1 44 45 46 47 48 341 Next »
Advertisements