MySQL insert into Statement Exercises: Insert one row in jobs table to ensure that no duplicate value will be entered in the job_id column
MySQL insert into Statement: Exercise-8 with Solution
8. Write a SQL statement to insert one row in jobs table to ensure that no duplicate value will be entered in the job_id column.
Create the table jobs. CREATE TABLE IF NOT EXISTS jobs ( JOB_ID integer NOT NULL UNIQUE PRIMARY KEY, JOB_TITLE varchar(35) NOT NULL, MIN_SALARY decimal(6,0) ); INSERT INTO jobs VALUES(1001,'OFFICER',8000); mysql> SELECT * FROM jobs; +--------+-----------+------------+ | JOB_ID | JOB_TITLE | MIN_SALARY | +--------+-----------+------------+ | 1001 | OFFICER | 8000 | +--------+-----------+------------+
Sample Solution:
INSERT INTO jobs VALUES(1001,'OFFICER',8000);
Let execute the above code in MySQL 5.6 command prompt.
mysql> INSERT INTO jobs VALUES(1001,'OFFICER',8000); ERROR 1062 (23000): Duplicate entry '1001' for key 'PRIMARY'
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous:Write a SQL statement to insert one row in jobs table to ensure that no duplicate value will be entered in the job_id column.
Next:Write a SQL statement to insert a record into the table countries to ensure that, a country_id and region_id combination will be entered once in the table.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework