MySQL Create Table Exercises: Create a table jobs, and check one of it column max_salary amount exceeding the upper limit 25000
MySQL Create Tables: Exercise-6 with Solution
6. Write a SQL statement to create a table named jobs including columns job_id, job_title, min_salary, max_salary and check whether the max_salary amount exceeding the upper limit 25000.
Sample Solution:
CREATE TABLE IF NOT EXISTS jobs (
JOB_ID varchar(10) NOT NULL ,
JOB_TITLE varchar(35) NOT NULL,
MIN_SALARY decimal(6,0),
MAX_SALARY decimal(6,0)
CHECK(MAX_SALARY<=25000)
);
Let execute the above code in MySQL 5.6 command prompt
Here is the structure of the table:
mysql> DESC jobs; +------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+--------------+------+-----+---------+-------+ | JOB_ID | varchar(10) | NO | | NULL | | | JOB_TITLE | varchar(35) | NO | | NULL | | | MIN_SALARY | decimal(6,0) | YES | | NULL | | | MAX_SALARY | decimal(6,0) | YES | | NULL | | +------------+--------------+------+-----+---------+-------+ 4 rows in set (0.16 sec)
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a SQL statement to create a table countries set a constraint NULL.
Next: Write a SQL statement to create a table named countries including columns country_id, country_name and region_id and make sure that no countries except Italy, India and China will be entered 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