slide môn học MySQL bài 3 implementing the SQL queries using MySQL i

48 4 0
  • Loading ...
1/48 trang

Thông tin tài liệu

Ngày đăng: 30/11/2016, 22:11

Implementing the SQL queries using MySQL-I Session Review       Databases are used to store information Relational Databases consists of several tables Data types are classified as numeric, String, Date and Complex Normalization is the process in which the redundancies in the database are removed A Primary key is a field in the table which is used as the unique identifier An entity is said to be in the first normal form if all the attributes are single valued Indexing a database facilitates a faster find and sort operations in the database MySQL Database / Session / Slide of 48 Objectives  View and Alter the database  Select and Display the data from a table  Change the table definition  Delete a table along with its table definition MySQL Database / Session / Slide of 48 View Database  SHOW command is used for viewing list of databases present in the server SHOW DATABASES; MySQL Database / Session / Slide of 48 View Database with LIKE clause-I  To view the list of databases that begin or contain the specified character in the database name, the syntax is: SHOW DATABASES [LIKE clause]; MySQL Database / Session / Slide of 48 View Database with LIKE clause-II  Show all databases that begin with the letter ‘E’ SHOW DATABASES LIKE ‘E%’; MySQL Database / Session / Slide of 48 View Tables- I  To view a list of tables of a database, the syntax is: SHOW TABLES [FROM database_name] [LIKE clause]; MySQL Database / Session / Slide of 48 View Tables-II  Show the tables of the Employee database where the database is first activated with USE command SHOW TABLES; MySQL Database / Session / Slide of 48 View Tables using FROM clause  Show the tables of the EMPLOYEE database SHOW TABLES FROM EMPLOYEE; MySQL Database / Session / Slide of 48 View Tables using LIKE clause  Show tables that begin with the letter ‘E’ from the EMPLOYEE database SHOW TABLES FROM EMPLOYEE LIKE ‘E %’; MySQL Database / Session / Slide 10 of 48 Display records using Comparison Operator-II  Show the records of the EMP_DETAILS table where the last name is Norton SELECT * FROM EMP_DETAILS WHERE E_LNAME = ‘NORTON’; MySQL Database / Session / Slide 34 of 48 Display records using Logical Operator  Show the details of the EMP_DETAILS table, where the address of the employee is Troy or the address of employee is New Jersey SELECT * FROM EMP_DETAILS WHERE E_ADDRESS = ‘TROY’ OR E_ADDRESS = ‘NEW JERSEY’; MySQL Database / Session / Slide 35 of 48 Altering the table definition      The ALTER TABLE command is used to modify the structure of a table The syntax for altering a table is: ALTER [IGNORE] TABLE table_name alter_spec[, alter_spec ] MySQL Database / Session / Slide 36 of 48 Alter table by adding column-I    To add a column in the existing table, the syntax is: ALTER TABLE table_name ADD [COLUMN] create_definition [FIRST | AFTER column_name] MySQL Database / Session / Slide 37 of 48 Alter table by adding column-II    Add a column CITY to the EMP_DETAILS table for entering the name of the city of all employees ALTER TABLE EMP_DETAILS ADD (CITY CHAR (10)); MySQL Database / Session / Slide 38 of 48 Alter table by adding Index key-I    To add an index key to a column of a table, the syntax is: ALTER TABLE table_name ADD INDEX [index_name] (index_column_name ) MySQL Database / Session / Slide 39 of 48 Alter table by adding Index key-II    Add an index on column E_ID on EMP_DETAILS table ALTER TABLE EMP_DETAILS ADD (INDEX (E_ID)); MySQL Database / Session / Slide 40 of 48 Alter table by adding Primary key-I    To add a primary key to the column of a table, the syntax is: ALTER TABLE table_name ADD PRIMARY KEY (index_column_name ) MySQL Database / Session / Slide 41 of 48 Alter table by adding Primary key-II    Add a primary key on column E_ID on EMP_DETAILS table ALTER TABLE EMP_DETAILS ADD (PRIMARY KEY (E_ID)); MySQL Database / Session / Slide 42 of 48 Alter table by renaming the table name-I  To rename a table from an old table name to new table name, the syntax is: ALTER TABLE table_name RENAME [AS] new_table_name   MySQL Database / Session / Slide 43 of 48 Alter table by renaming the table name-II  Rename the table name from SALARY_DETAILS to EMP_SALARY ALTER TABLE SALARY_DETAILS RENAME EMP_SALARY;   MySQL Database / Session / Slide 44 of 48 Delete a table along with its table definition-I  The DROP TABLE command is used to remove or delete tables from a database This command removes table definition, all data, indexes, triggers, constraints, and permission specification for that table MySQL Database / Session / Slide 45 of 48 Delete a table along with its table definition-II  To delete a table with its definitions, the syntax is: DROP TABLE [IF EXIST] table_name[table_name1,…][RESTRICT | CASCADE]; MySQL Database / Session / Slide 46 of 48 Delete a table along with its table definition-III  Remove SAMPLE table from EMPLOYEE database DROP TABLE SAMPLE; MySQL Database / Session / Slide 47 of 48 Summary     In MySQL, we can see the list of databases in the server with the help of SHOW command The ALTER command is used to modify the characteristics or attributes of a table or a database For retrieving data from a table, the SELECT command is used The DROP command is used to remove or delete a table with its definitions from a database MySQL Database / Session / Slide 48 of 48 [...]... Session 6 / Slide 27 of 48 Using SELECT with DISTINCT clause -I  To view distinct records of a table, the syntax is: SELECT DISTINCT column_name1, column_name2 FROM table_name; MySQL Database / Session 6 / Slide 28 of 48 Using SELECT with DISTINCT clause-II  Show only the department names distinctly from the EMP_DEPARTMENT SELECT DISTINCT D_NAME FROM EMP_DEPARTMENT; MySQL Database / Session 6 / Slide. .. SHOW INDEX FROM EMP_DETAILS FROM EMPLOYEE; MySQL Database / Session 6 / Slide 15 of 48 View Default Variables  Show the values of the system variables SHOW VARIABLES; MySQL Database / Session 6 / Slide 16 of 48 View Default Variables using LIKE clause -I  To view only those variables that match the specified pattern, the syntax is: SHOW VARIABLES [LIKE clause]; MySQL Database / Session 6 / Slide 17... / Session 6 / Slide 33 of 48 Display records using Comparison Operator-II  Show the records of the EMP_DETAILS table where the last name is Norton SELECT * FROM EMP_DETAILS WHERE E_LNAME = ‘NORTON’; MySQL Database / Session 6 / Slide 34 of 48 Display records using Logical Operator  Show the details of the EMP_DETAILS table, where the address of the employee is Troy or the address of employee is New... with the letter ‘H’ of the SALARY_DETAILS table from EMPLOYEE database SHOW COLUMNS FROM SALARY_DETAILS LIKE ‘H%’; MySQL Database / Session 6 / Slide 13 of 48 View Index keys -I  To view the index of a table from a database, the syntax is: SHOW INDEX FROM table_name [FROM database_name]; MySQL Database / Session 6 / Slide 14 of 48 View Index Keys-II  Show the index from the EMP_DETAILS table of the. ..View Columns -I  To view the column structure of the specified table from the specified database, the syntax is: SHOW COLUMNS FROM table_name [FROM database_name] [LIKE clauses]; MySQL Database / Session 6 / Slide 11 of 48 View Columns-II  Show the column structure of the EMP_DETAILS table SHOW COLUMNS FROM EMP_DETAILS; MySQL Database / Session 6 / Slide 12 of 48 View Columns using LIKE clause... of 48 View Default Variables using LIKE clause-II  Show variables that matches with the pattern ‘HAVE’ SHOW VARIABLES LIKE ‘HAVE%’; MySQL Database / Session 6 / Slide 18 of 48 View Server Status  Show the server status SHOW STATUS; MySQL Database / Session 6 / Slide 19 of 48 View Table Status -I  To display more information about tables, the syntax is: SHOW TABLE STATUS [FROM database_name] [LIKE clauses];... clauses]; MySQL Database / Session 6 / Slide 20 of 48 View Table Status-II  Show the status of all the tables of the EMPLOYEE database SHOW TABLE STATUS FROM EMPLOYEE; MySQL Database / Session 6 / Slide 21 of 48 View rights of a user -I  To view a list of grants that can be issued to duplicate grants for a user, the syntax is: SHOW GRANTS FOR user; MySQL Database / Session 6 / Slide 22 of 48 View rights... user-II  Show the list of grants that are issued to root user SHOW GRANTS FOR root@localhost; MySQL Database / Session 6 / Slide 23 of 48 Altering Database on the file system -I  To modify the character set of a database, the syntax is: ALTER DATABASE database_name DEFAULT CHARACTER SET charset_name; MySQL Database / Session 6 / Slide 24 of 48 Altering Database on the file system-II  To modify the. .. SET swe7; MySQL Database / Session 6 / Slide 25 of 48 Display the data from a table -I  The SELECT command is used to retrieve data from one or more tables To retrieve all the records of a table, the syntax is: SELECT [*] FROM table_name; MySQL Database / Session 6 / Slide 26 of 48 Display the data from a table-II  Display all records of the EMP_DETAILS table SELECT * FROM EMP_DETAILS; MySQL Database... Arithmetic Operator  Calculate GROSS_SAL with 1000 and display the corresponding records from the SALARY_DETAILS table SELECT GROSS_SAL + 1000 FROM SALARY_DETAILS ; MySQL Database / Session 6 / Slide 32 of 48 Display records using Comparison Operator -I  Display the records of EMP_SALARY table, where the basic salary is greater than 2500 SELECT * FROM EMP_SALARY WHERE BASIC_SALARY > 2500; MySQL Database
- Xem thêm -

Xem thêm: slide môn học MySQL bài 3 implementing the SQL queries using MySQL i , slide môn học MySQL bài 3 implementing the SQL queries using MySQL i , slide môn học MySQL bài 3 implementing the SQL queries using MySQL i

Gợi ý tài liệu liên quan cho bạn

Nạp tiền Tải lên
Đăng ký
Đăng nhập