- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Will MySQL work if we won’t include the size of VARCHAR while creating a new table?
No, the query won’t work. Let’s create the same scenario and check the error −
mysql> create table DemoTable1821 ( Id int, FirstName varchar, LastName varchar ); 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 near ', LastName varchar )' at line 4
To remove the above error, you need to give the size of varchar(10). Let us first create a table −
mysql> create table DemoTable1821 ( Id int, FirstName varchar(10), LastName varchar(10) ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1821 values(1,'John','Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1821 values(2,'John','Doe'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1821 values(3,'Adam','Smith'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1821;
This will produce the following output −
+------+-----------+----------+ | Id | FirstName | LastName | +------+-----------+----------+ | 1 | John | Smith | | 2 | John | Doe| | 3 | Adam | Smith | +------+-----------+----------+ 3 rows in set (0.00 sec)
Advertisements