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-7 with Solution
7. 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 , 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 'JOB_ID'
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous:Write a SQL statement insert rows from country_new table to countries table.
Next: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.
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