0% found this document useful (0 votes)
143 views3 pages

SQL Commands Assignment Overview

This document provides instructions for an assignment on SQL and SQL commands. It includes directions to create a database and table, insert data, perform select queries with where clauses, update a record, delete a record, and rename a column. The student is asked to submit their responses and any applicable code.

Uploaded by

pokegex798
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
143 views3 pages

SQL Commands Assignment Overview

This document provides instructions for an assignment on SQL and SQL commands. It includes directions to create a database and table, insert data, perform select queries with where clauses, update a record, delete a record, and rename a column. The student is asked to submit their responses and any applicable code.

Uploaded by

pokegex798
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Assignment:-03

Introduction to sql and sql commands


Instructions:
Please share your answers filled in line in the Word document. Submit code
separately wherever applicable.

Please ensure you update all the details:


Name: Tejas S Nichat ,Batch ID: _11092023__________
Topic: Introduction to sql and sql commands

1) What is SQL, and what are some common uses for it in database management?
2) What is a foreign key in SQL, and how is it used to establish relationships
between tables?
DATABASE CREATE:-
1. Create a database ‘classroom’
2. Create a table named ‘science_class’ with the following properties
3 columns(enrollment_no int, name varchar, science_marks int)

INSERTING & IMPORTING:-


1. Insert the following data into science_class using insert into command
1 popeye 33
2 olive 54
3 brutus 98

2. Import data from CSV file ‘[Link]’ attached in resources to


science_class to insert data of next 8 students
SELECT & WHERE:-
1. Retrieve all data from the table ‘Science_Class’
2. Retrieve the name of students who have scored more than 60 marks

© 360DigiTMG. All Rights Reserved.


Assignment:-03
Introduction to sql and sql commands
3. Retrieve all data of students who have scored more than 35 but less than
60 marks
4. Retrieve all other students i.e. who have scored less than or equal to 35
or more than or equal to 60.

UPDATING TABLES:-
1. Update the marks of popeye to 45
2. Delete the row containing details of the student named ‘robb’
3. Rename column ‘name’ to ‘student_name’

© 360DigiTMG. All Rights Reserved.


Assignment:-03
Introduction to sql and sql commands
create database class_room;
use class_room;
create table science_class(enrollment_id int,name
varchar(20),science_mark int(10));
insert into science_class values(1,'popeye',33),(2,'olive',54),
(3,'brutus',98);
select *from science_class;
select *from science_class where science_mark > 60;
select *from science_class where science_mark > 35 and science_mark <
60;
select *from science_class where science_mark <=35 or science_mark >=
60;
update science_class
set science_mark=45
where enrollment_id=1 limit 1;
select *from science_class;
delete from science_class where name="Robb" limit 1;
select *from science_class;
alter table science_class change column name student_name varchar(20);
select *from science_class;

© 360DigiTMG. All Rights Reserved.

Common questions

Powered by AI

Creating a table in SQL involves defining the table structure with appropriate column names and data types. For example, creating a table `science_class` requires specifying columns such as `enrollment_no` (INT), `name` (VARCHAR), and `science_marks` (INT), which are suitable for holding unique identifiers, character strings, and numerical marks respectively. Populating the table involves using the `INSERT INTO` command to add records, specifying values for each column. Data can also be imported from external sources such as CSV files to populate the table efficiently, facilitating bulk data operations .

A foreign key in SQL is a field or a collection of fields in one table that uniquely identifies a row of another table or the same table. It establishes and enforces a link between the data in the two tables, ensuring referential integrity. This relationship between tables allows for the establishment of a parent-child relationship, where the foreign key references the primary key of the parent table, thus connecting the two datasets. This is crucial for normalizing databases and organizing data efficiently .

The `SELECT` statement in SQL can be utilized not only to retrieve data but also to transform and organize it. For example, using functions such as `AVG`, `SUM`, `COUNT`, data can be aggregated for analysis. Aliasing with `AS` can rename column headings for clarity, and sorting with `ORDER BY` organizes the result set. Additionally, conditional transformations with cases can modify data output upon retrieval, such as classifying scores into categories. These capabilities allow SQL to process complex queries that prepare data directly for analysis .

SQL (Structured Query Language) is a standardized language used to manage and manipulate relational databases. Its key characteristics include the ability to execute queries against a database, retrieve data, insert new records, update existing records, and delete records. SQL also provides mechanisms for creating, modifying, and managing database structures, such as tables, indexes, views, and more. It is essential for database management due to its versatility, performance, and widespread industry adoption, facilitating cross-platform integration and data manipulation .

To manipulate existing data in a SQL table, commands such as `UPDATE`, `DELETE`, and `ALTER` are used. The `UPDATE` command modifies the data in one or more rows, often filtered by a condition (e.g., changing 'popeye' marks from 33 to 45). The `DELETE` command removes rows matching specific criteria (e.g., removing 'robb'). The `ALTER TABLE` command modifies the table structure, such as renaming columns (`ALTER TABLE science_class CHANGE name student_name`). These operations allow dynamic data management and structure adaptation as business needs evolve .

SQL operations such as `ALTER TABLE`, `ADD COLUMN`, and `DROP COLUMN` perform transformations on data structures, facilitating schema evolution. `ALTER TABLE` modifies existing structures, supporting changes in business requirements without complete redesigns. Adding or dropping columns allows attributes to be introduced or removed, reflecting changes in data collection needs. These transformations enable databases to adapt over time, ensuring alignment with dynamic data models and operational practices, though they require careful planning to uphold data integrity and performance .

In SQL, to retrieve specific data based on conditions, the `SELECT` command is used in conjunction with `WHERE` clause to filter rows. For instance, `SELECT * FROM science_class WHERE science_mark > 60` retrieves all students scoring above 60 marks. This method effectively narrows down data in large datasets to match specific criteria, providing focused results from the database .

SQL supports efficient data retrieval in complex queries using indexing, joins, subqueries, and optimization techniques. Indexing accelerates data retrieval by providing rapid access to records. Joins allow combining data across tables, essential for comprehensive queries, and subqueries provide a means to encapsulate queries within queries. Optimization techniques such as query rewriting and execution planning enhance performance by minimizing resource use. These features enable handling voluminous data and complex queries, though they must be carefully managed to prevent performance bottlenecks .

Using SQL to manage database relationships has a profound impact on maintaining data integrity. It involves defining primary and foreign keys, which enforce data consistency across related tables through referential integrity. By using constraints, SQL ensures that only valid data is entered, preventing orphan records in child tables that aren't linked to parent records. This framework prevents anomalies and redundancies, ensures accurate, reliable data, and supports complex transactions and data integrity even in large-scale applications .

Maintaining data accuracy and consistency during SQL manipulation involves challenges such as data anomalies from incorrect operations and concurrency issues in multi-user environments. Solutions include using SQL constraints like `PRIMARY KEY` and `FOREIGN KEY` to enforce data integrity, employing transactions with `BEGIN` and `COMMIT` to ensure atomic operations, and utilizing isolation levels like `SERIALIZABLE` to manage concurrency. Regular audits and validations further help to identify and correct inconsistencies, thereby preserving data reliability in SQL databases .

You might also like