Can we use {} while creating a MySQL table?


No, you need to use open and close parenthesis like this ( ) while creating a table. Use the below syntax −

CREATE TABLE IF NOT EXISTS yourTableName
(
   yourColumnName1 dataType1,
   .
   .
   .
   .
   .
   N
);

Let us first create a table −

mysql> CREATE TABLE IF NOT EXISTS DemoTable
   (
   CustomerId int,
   CustomerName varchar(20),
   CustomerAge int
   ,
   PRIMARY KEY(CustomerId)
   );
Query OK, 0 rows affected (0.58 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values(1,'Chris',25);
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable values(2,'Robert',34);
Query OK, 1 row affected (0.15 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

Output

+------------+--------------+-------------+
| CustomerId | CustomerName | CustomerAge |
+------------+--------------+-------------+
| 1          | Chris        | 25          |
| 2          | Robert       | 34          |
+------------+--------------+-------------+
2 rows in set (0.00 sec)
raja
Published on 14-Jun-2019 11:11:40
Advertisements