
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Creating a MySQL Table with Constraints
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)
Advertisements