Found 4378 Articles for MySQL

Set Blank spaces in column names with MySQL?

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

819 Views

To set blank spaces in column names with MySQL, you can use the concept of backticks. Let us first create a table. Following is the query −mysql> create table blankSpacesDemo    -> (    -> `Student Id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> `Student Full Name` varchar(100)    -> ); Query OK, 0 rows affected (0.51 sec)Following is the query to insert some records in the table using insert command −mysql> insert into blankSpacesDemo(`Student Full Name`) values('John Smith'); Query OK, 1 row affected (0.16 sec) mysql> insert into blankSpacesDemo(`Student Full Name`) values('Carol Taylor'); Query OK, 1 row ... Read More

What if I forgot to set Auto Increment? Can I set it later in MySQL?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

108 Views

Yes, you can set Auto Increment later with ALTER table. Let us first create a table. Here, as you can see, we haven’t set Auto Increment −mysql> create table forgetToSetAutoIncrementDemo    -> (    -> StudentId int,    -> StudentName varchar(30)    -> ); Query OK, 0 rows affected (1.17 sec)Now check the table description, there is no auto_increment column −mysql> desc forgetToSetAutoIncrementDemo;This will produce the following output −+-------------+-------------+------+-----+---------+-------+ | Field       | Type        | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+-------+ | StudentId   | int(11)     | YES  |   ... Read More

How to search for “ñ” and avoid records that include “n” in MySQL?

Smita Kapse
Updated on 30-Jul-2019 22:30:25

376 Views

If you do not want all records that include “n” when you search for “ñ”, use the following syntax −select *from yourTableName where yourColumnName LIKE '%ñ%' COLLATE utf8_spanish_ci;Let us first create a table. Following is the query −mysql> create table NotIncludenDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> ClientName varchar(20)    -> ); Query OK, 0 rows affected (1.07 sec)Following is the query to insert some records in the table using insert command −mysql> insert into NotIncludenDemo(ClientName) values('John'); Query OK, 1 row affected (0.21 sec) mysql> insert into NotIncludenDemo(ClientName) values('Johñ'); Query OK, ... Read More

Get the returned record set ordered by (ORDER BY) position in MySQL 'IN' clause

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

67 Views

To return record set order, you need to use FIND_IN_SET(). Let us first create a table −mysql> create table recordSetOrderDemo    -> (    -> EmployeeId int,    -> EmployeeName varchar(30)    -> ); Query OK, 0 rows affected (0.63 sec)Following is the query to insert some records in the table using insert command −mysql> insert into recordSetOrderDemo values(20, "John"); Query OK, 1 row affected (0.20 sec) mysql> insert into recordSetOrderDemo values(10, "Larry"); Query OK, 1 row affected (0.14 sec) mysql> insert into recordSetOrderDemo values(100, "Mike"); Query OK, 1 row affected (0.14 sec) mysql> insert into recordSetOrderDemo ... Read More

How to return static strings in MySQL?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

880 Views

In order to return static strings in MySQL, you can use UNION. Following is the syntax −select 'yourStringValue1' as yourAliasName UNION select 'yourStringValue2' as yourAliasName;Let us implement the above syntax to return static strings in MySQL. Following is the query −mysql> select 'HELLO' as staticStringsResult    -> UNION    -> select 'MySQL' as staticStringsResult;This will produce the following output −+---------------------+ | staticStringsResult | +---------------------+ | HELLO             | | MySQL             | +---------------------+ 2 rows in set (0.00 sec)In some MySQL versions, the above syntax does not work, therefore you ... Read More

MySQL SELECT from table A that does not exist in table B using JOINS?

Smita Kapse
Updated on 30-Jul-2019 22:30:25

2K+ Views

To SELECT from table A that does not exist in table B, you can use left join. Following is the syntax −select yourTableNameA.* from yourTableNameA left join yourTableNameB on yourTableNameA.yourColumnName = yourTableNameB.yourColumnName where yourTableNameB.yourColumnName IS NULL;Let us first create a table. Following is the query −mysql> create table table_A    -> (    -> Value int    -> ); Query OK, 0 rows affected (1.10 sec)Following is the query to insert records in the table using insert command −mysql> insert into table_A values(10); Query OK, 1 row affected (0.32 sec) mysql> insert into table_A values(15); Query OK, 1 row ... Read More

How to select or, shift to another database in MySQL using a JDBC API?

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

363 Views

In general, You can change the current database in MySQL using the USE query.SyntaxUse DatabaseName;To change the current database using JDBC API you need to:Register the driver: Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as parameter.Establish a connection: Connect ot the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Create Statement: Create a Statement object using the createStatement() method of the Connection interface.Execute the Query: Execute the query using the execute() method of the Statement interface.ExampleFollowing JDBC ... Read More

How to create a database in MySQL using a JDBC API?

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

2K+ Views

A. In general, you can create a database using the CREATE DATABASE query.SyntaxCREATE DATABASE DatabaseName;To create a Database using JDBC API you need to:Register the driver: Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as parameter.Establish a connection: Connect ot the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Create Statement: Create a Statement object using the createStatement() method of the Connection interface.Execute the Query: Execute the query using the execute() method of the Statement interface.Example:Following JDBC program ... Read More

How do you get the last access (and/or write) time of a MySQL database?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

1K+ Views

To get the last access time, try the following syntax −SELECT update_time FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'yourDatabaseName' AND table_name = 'yourTableName'The above syntax gives the last access information about MyISAM engine type.Here, our database is ‘business’ and we will be using the table with the name ‘twoprimarykeytabledemo'.To get last access time of MySQL database, use the following query.Case 1 − The query is as follows −mysql> SELECT update_time    -> FROM INFORMATION_SCHEMA.TABLES    -> WHERE table_schema = 'business'    -> AND table_name = 'twoprimarykeytabledemo';The output is as follows −+---------------------+ | UPDATE_TIME ... Read More

What is the smallest datatype for one bit in MySQL?

Samual Sam
Updated on 30-Jul-2019 22:30:25

114 Views

The smallest datatype for one bit can be bit(1). The syntax is as follows −yourColumnName bit(1)To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table bitDemo    -> (    -> isValid bit(1)    -> ); Query OK, 0 rows affected (0.49 sec)Now you can check all the details of table with the help of SHOW CREATE command. The query is as follows −mysql> show create table bitDemo;Here is the output −+---------+-----------------------------------------------------------------------------------------------------------------------------+ | Table   | Create Table   ... Read More

Advertisements