

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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)
- Related Questions & Answers
- Can we use {} while creating a MySQL table?
- MySQL Stored procedure won't fetch the whole table?
- Will extending the size of a varchar field in MySQL affect the data inside it?
- Why do backticks won’t work in the SET part of an UPDATE query (for MySQL)?
- Set special characters for password while creating a new MySQL user?
- Set AUTO_INCREMENT in a table while creating it in MySQL?
- While creating a MySQL table use the reserved keyword ‘Key’
- Will “create table table” work in MySQL since we cannot use reserved words as table name?
- Set DEFAULT values for columns while creating a table in MySQL
- Creating a new table in SAP HANA
- What is the MySQL VARCHAR max size?
- Set options while creating a MySQL table. Display the same options as well
- How can we use a combination of logical operators while creating MySQL views?
- How can we use logical operators while creating MySQL views?
- What is MySQL NOT NULL constraint and how can we declare a field NOT NULL while creating a table?
Advertisements