MySQL Database and Table Creation Guide
MySQL Database and Table Creation Guide
The SQL command to find teachers with first names starting with 'A' in the 'Teacher' table is: SELECT * FROM TEACHER WHERE FIRST_NAME LIKE 'A%';
To retrieve names and department numbers of all teachers ordered by department number and then by teacher names in descending order, use: SELECT FIRST_NAME, LAST_NAME, DEPT_NO FROM TEACHER ORDER BY DEPT_NO, FIRST_NAME DESC, LAST_NAME DESC;
You can count the number of teachers earning more than Rs 40,000 using the query: SELECT COUNT(*) FROM TEACHER WHERE SALARY > 40000;
To retrieve all entries of employees whose last names are not specified, you would use: SELECT * FROM TEACHER WHERE LAST_NAME IS NULL;
The query to find the maximum and minimum salary from the 'Teacher' table is: SELECT MAX(SALARY), MIN(SALARY) FROM TEACHER;
To update the salary of a specific teacher in the 'Teacher' table based on their Teacher_ID, you can use the SQL command: UPDATE table_name SET column1 = value1 WHERE condition. Specifically for updating salary: mysql> UPDATE TEACHER SET SALARY=55000 WHERE TEACHER_ID=101;
The SQL command to create a table in a MySQL database is 'CREATE TABLE table_name (column1 datatype, column2 datatype, ...)'. To create a 'Teacher' table, the command would be: mysql> CREATE TABLE TEACHER (TEACHER_ID INT(3), FIRST_NAME VARCHAR(30), LAST_NAME VARCHAR(30), GENDER VARCHAR(1), SALARY INT(6), DATE_OF_BIRTH DATE, DEPT_NO INT(2), PRIMARY KEY (TEACHER_ID))
To increase the salary by 10% for teachers in Department number 4, use: UPDATE TEACHER SET SALARY = SALARY * 1.10 WHERE DEPT_NO = 4;
To insert a new entry into the 'Department' table, use the INSERT INTO command: INSERT INTO DEPARTMENT (DEPT_ID, DEPT_NAME) VALUES (value1, value2); For example: INSERT INTO DEPARTMENT (DEPT_ID, DEPT_NAME) VALUES (10, 'Mathematics')
To list all the Department numbers with male teachers and ensure no repetitions, you can use a SELECT query with DISTINCT: SELECT DISTINCT DEPT_NO FROM TEACHER WHERE GENDER='M';