
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- Can we use {} while creating a MySQL table?
- MySQL Stored procedure won't fetch the whole table?
- While creating a MySQL table use the reserved keyword ‘Key’
- Set special characters for password while creating a new MySQL user?
- Will extending the size of a varchar field in MySQL affect the data inside it?
- Set AUTO_INCREMENT in a table while creating it in MySQL?
- 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
- 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?
- Creating a new table in SAP HANA
- What is the MySQL VARCHAR max size?
- What is MySQL NOT NULL constraint and how can we declare a field NOT NULL while creating a table?
- How can we use logical operators while creating MySQL views?
- Fix Error in MySQL syntax while creating a table column with name “index”?

Advertisements