MySQL Articles - Page 428 of 439

How to get last day of the current month in MySQL?

Sravani S
Updated on 29-Jan-2020 05:17:54

465 Views

With the help of following MySQL query, we can get the last day of the current month −mysql> SELECT LAST_DAY(now()) AS 'LAST DAY OF CURRENT MONTH'; +---------------------------+ | LAST DAY OF CURRENT MONTH | +---------------------------+ | 2017-10-31                | +---------------------------+ 1 row in set (0.00 sec)

How to get the first day of next month in MySQL?

V Jyothi
Updated on 29-Jan-2020 05:18:35

1K+ Views

With the help of following MySQL query, we can get the first day of next month −mysql> SELECT DATE_FORMAT(CURDATE() + INTERVAL 1 MONTH,'%Y-%m-01') AS 'FIRST DAY OF NEXT MONTH'; +-------------------------+ | FIRST DAY OF NEXT MONTH | +-------------------------+ | 2017-11-01              | +-------------------------+ 1 row in set (0.00 sec)

How to get the first day of the previous month in MySQL?

Sreemaha
Updated on 29-Jan-2020 05:19:15

3K+ Views

With the help of following MySQL query, we can get the first day of previous month −mysql> SELECT DATE_FORMAT(CURDATE() - INTERVAL 1 MONTH,'%Y-%m-01') AS 'FIRST DAY OF PREVOIUS MONTH'; +-----------------------------+ | FIRST DAY OF PREVOIUS MONTH | +-----------------------------+ | 2017-09-01                  | +-----------------------------+ 1 row in set (0.00 sec)

How to get the first day of the current month in MySQL?

Priya Pallavi
Updated on 28-Jan-2020 12:19:18

2K+ Views

With the help of following MySQL query, we can get the first day of the current month −mysql> SELECT DATE_SUB(LAST_DAY(NOW()),INTERVAL DAY(LAST_DAY(NOW()))- 1 DAY) AS 'FIRST DAY OF CURRENT MONTH'; +----------------------------+ | FIRST DAY OF CURRENT MONTH | +----------------------------+ | 2017-10-01                 | +----------------------------+ 1 row in set (0.00 sec)

How can we create a table from an existing MySQL table in the database?

Swarali Sree
Updated on 28-Jan-2020 12:20:27

231 Views

With the help of CTAS i.e. “Create Table AS Select” script we can create a table from an existing table. It copies the table structure as well as data from the existing table. Consider the following example in which we have created a table named EMP_BACKUP from already existing table named ‘Employee’ −mysql> Select * from Employee; +------+--------+ | Id   | Name   | +------+--------+ | 100  | Ram    | | 200  | Gaurav | | 300  | Mohan  | +------+--------+ 3 rows in set (0.00 sec)The query above shows the data in table ’Employee’ and the query ... Read More

What is MySQL CREATE command? How can we create both database and table with this command?

Arushi
Updated on 19-Jun-2020 13:50:23

270 Views

CREATE command is a DDL command which is used to create a table or a database. The syntax for creating table and database with CREATE command is as follows −The syntax for creating a database −Create database database-name;Examplemysql> Create database query; Query OK, 1 row affected (0.04 sec)In the example above we have created a database named ‘query’.The syntax for creating a table −Create table table-name(    column-name1 datatype1,    column-name2 datatype2,    column-name3 datatype3,    column-name4 datatype4    ------------------------------);Examplemysql> Create table Employee(Id INT, Name Varchar(20)); Query OK, 0 rows affected (0.19 sec)In the example above, we have created a ... Read More

Is there a naming convention for tables in MySQL?

Rama Giri
Updated on 28-Jan-2020 12:22:05

561 Views

No, MySQL does not have a preferred naming convention standard. If the name we have chosen is logical and consistent then it would be ok.Two major points need to be remembered, one is that no two tales/databases can have the same name and second we can choose any of the reserved words as the name of table/database.

How can we insert current year automatically in a YEAR type column of MySQL table?

Nikitha N
Updated on 28-Jan-2020 12:23:05

568 Views

It can be done by using either CURDATE() or NOW() in MySQL query as follows −mysql> Insert into year1(Year_Copyright) values (CURDATE()); Query OK, 1 row affected, 1 warning (0.06 sec) mysql> Select * from year1; +----------------+ | Year_Copyright | +----------------+ |           2017 | |           2017 | +----------------+ 2 rows in set (0.00 sec) mysql> Insert into year1(Year_Copyright) values (NOW()); Query OK, 1 row affected, 1 warning (0.06 sec) mysql> Select * from year1; +----------------+ | Year_Copyright | +----------------+ |           2017 | |           2017 | |           2017 | +----------------+ 1 rows in set (0.00 sec)

How MySQL use YEAR data type to store year value in a table?

varma
Updated on 28-Jan-2020 12:24:02

536 Views

MySQL permits to declare a column YEAR type, with the help of which we can store year values in that column.mysql> Create table year1 (Year_Copyright YEAR); Query OK, 0 rows affected (0.21 sec) mysql> Insert into year1(Year_Copyright) values (2017); Query OK, 1 row affected (0.08 sec) mysql> Select * from year1; +----------------+ | Year_Copyright | +----------------+ |          2017  | +----------------+ 1 row in set (0.00 sec)

What are the different commands used in MySQL?

Chandu yadav
Updated on 19-Jun-2020 13:52:18

4K+ Views

SQL language is divided into four types of primary language statements: DML, DDL, DCL and TCL. Using these statements, we can define the structure of a database by creating and altering database objects and we can manipulate data in a table through updates or deletions. We also can control which user can read/write data or manage transactions to create a single unit of work.The four main categories of SQL statements are as follows −DML (Data Manipulation Language)DML statements affect records in a table. These are basic operations we perform on data such as selecting a few records from a table, ... Read More

Advertisements