MySql 1 Create a database in MySQL using 4 or more tables 2
MySql:
1 Create a database in MySQL using 4 or more tables.
2. Use primary, foreign or composite keys for the tables.
3. Use the command to view your table structure.
4. Use the INSERT command to load information into all of the tables.
5. Use the ALTER command to add a column to a table or modify a column of data in a table.
6. Use the DELETE command to delete a row from one of the tables.
7. Use the UPDATE common to change a value of information in a table that has a added column.
8. Use the reserve word Distinct in a SQL statement.
9. to see 2 fields in two tables.
10. RENAME one of the tables.
11. Use the command to save the information from all of the tables.
12. Use the the command to count all the rows in one of your tables.
13. Use the commands to see all the information in your tablels with no duplicates.
14. Add a row with your first: last name and the other necded information required in one of the rows of your table.
15. Use SQL and the commands to see all the information that was revised in the table/tables using MySQL.
16. Join all tables and select a field of information from each table in a report using SQL/MySQL.
17. Create a new table from one of your existing tables.
18. Use the SHOW COLUMNS command to display the structure of the table.
Please answer all these 18 questions clearly . thanks
Solution
1 Ans) To create a table in a database use the following syntax:-
CREATE TABLE table_name (column_name1 datatype,column_name2 datatype);
Example:- The below statement creates a table \"Employee\" with columns employee_id, employee_name, department_id;
CREATE TABLE Employee (employee_id NUMBER(6), employee_name VARCHAR(25), department_id NUMBER(6))
2 Ans) To add a primary key to already existing table use below syntax:-
ALTER TABLE table_name ADD PRIMARY KEY (primary_key_column);
Example:- To add employee_id as a primary key for the table created in above example use below SQL statement
ALTER TABLE Employee ADD PRIMARY KEY (employee_id);
To add a foreign key to already existing table use below syntax:-
ALTER TABLE table_name ADD FOREIGN KEY(foreign_key_column) REFERENCES table_name2(column_referenced);
To add a composite key to already existing table use below syntax:-
ALTER TABLE table_name ADD COMPOSITE KEY(column1,column2);
3 Ans) To view the the table structure use the below command:-
DESC table_name;
Example:- DESC Employee;
4 Ans) To insert rows into table use below syntax:-
INSERT INTO table_name VALUES (value1,value2,....);
Example:- INSERT INTO Employee VALUES(956638,Ramesh,10000);
