MySQL CAST as DATE?

George John
Updated on 30-Jul-2019 22:30:24

625 Views

There is no difference between cast as Date and date() function in MySQL.The syntax of both cast() and date() is as follows −cast(yourDateTimeColumnName as Date) date(yourDateTimeColumnName)Both functions internally call Item_date_typecast. To check both the functions, let us create a table. The query to create a table is as follows −mysql> create table CastAsDateDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> ArrivalTime datetime,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.71 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into ... Read More

What would you do if you were made a superhero for a day?

Ridhi Arora
Updated on 30-Jul-2019 22:30:24

7K+ Views

A superhero is a person who does heroic deeds. So, in order to be a superhero, you need the power to accomplish good deeds.My WishFirstly, One of my superpowers would be to have the ability to fly. I would want to fly because that way I could fly over the town and see if people need help or not. I will also see whether they are happy or not so that I can make them happy in some manner.Secondly, I would want to be able to have super strength. By super strength I mean, to do anything and everything.Lastly, I ... Read More

Should I store a field PRICE as an int or as a float in the database?

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

954 Views

You do not need to store a field PRICE as an int or as float in the database. For this, you can set the DECIMAL()..Most of the time integers can be used to represent the float point numbers and these integers are internally cast into DECIMAL() data type. Therefore, if you have field PRICE then always use DECIMAL() data type. The syntax is as follows −DECIMAL(M, D);Here, M represents the ‘TotalNumberOfDigit’ and D represents the ‘Number OfDigitAfterDecimalPoint’.To understand the above concept, let us create a table with field PRICE as DECIMAL data type. The query is as follows −mysql> create ... Read More

Inserting multiple rows in MySQL?

Chandu yadav
Updated on 30-Jul-2019 22:30:24

7K+ Views

Insert multiple rows in MySQL with the help of “values”. You can enclose the values with parentheses set with comma separation. The syntax is as follows to insert multiple rows in MySQL.insert into yourTableName(yourColumnName1, yourColumnName2, ..............yourColumnNameN) values(value1, value2, ...valueN), (value1, value2, ...valueN), (value1, value2, ...valueN), ...........((value1, value2, ...valueN);Let us now first create a table in MySQL −mysql> create table InsertMultipleRowsDemo -> ( -> Id int, -> Name varchar(200), -> Age int -> ); Query OK, 0 rows affected (0.45 sec)Apply the above syntax to insert ... Read More

Selecting a single row in MySQL?

Chandu yadav
Updated on 30-Jul-2019 22:30:24

2K+ Views

If you want to select a single row on the basis of primary key, use the WHERE clause. The syntax is as follows −SELECT * FROM yourTableName WHERE yourPrimaryKeyColumnName = someValue;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table selectWithPrimaryKey    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> Name varchar(20),    -> Age int,    -> Marks int,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command. The query is ... Read More

What are some unique ways to build your network if you work remotely?

Ridhi Arora
Updated on 30-Jul-2019 22:30:24

161 Views

Earlier, it was tough that the person who works remotely cannot socialize at all! Neither would his network be broad. It would actually be in the limited domain. However, a person who does not work as a permanent employee does not mean can not have a wide network of acquaintance. He too can have a lot of connections if he takes care of the followings:Make Less But Real RelationshipIn a remote working situation, the interactions require greater effort than the employees who are not the virtual employees. In such circumstances, it is important to make real and genuine relationships. This ... Read More

Resolve usage of quotes ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use?

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

13K+ Views

In MySQL, you can use two different types of quotation marks which is backtick and another is single quotes or double quotes. In this case, maybe you are using single quotes to the column name that’s why you are getting error. You need to use the backtick symbol (` `) instead of single quotes. Backtick can be used with column names while single quotes can be used for strings.To understand the above error, let us create a table. The query to create a table is as follows −mysql> create table Backtick_SymbolDemo    -> (    -> Id int NOT NULL ... Read More

How to select an empty result set in MySQL?

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

1K+ 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)

How to run SQL script in MySQL?

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

25K+ Views

To run SQL script in MySQL, use the MySQL workbench. First, you need to open MySQL workbench.The snapshot is as follows −Now, File -> Open SQL Script to open the SQL script.Alternatively, use the following shortcut key −Ctrl+Shift+OAfter that an option would be visible for you to choose your .sql file from the disk. In my system, the file is located on the Desktop. I will select the same “tblstudent” SQL file as shown in the following screenshot −After browsing .sql files, you need to select the option “Reconnect to database” as shown in the following screenshot −Now, it will ... Read More

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

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

2K+ 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

Advertisements