0% found this document useful (0 votes)
199 views

Assignment 03

Uploaded by

Ritika Awasthi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
199 views

Assignment 03

Uploaded by

Ritika Awasthi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

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: _Ritika Awasthi____________ Batch ID: ___________
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 ‘student.csv’ 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’

SQL (Structured Query Language) is a programming language used for managing and
manipulating relational databases. It is the standard language for relational database
management systems (RDBMS) such as MySQL, PostgreSQL, SQL Server, Oracle, and SQLite.
SQL provides a standardized way to interact with databases, allowing users to perform
various operations like querying, inserting, updating, deleting, and managing database
structures.Here are some common uses of SQL in database management:
1. Querying Data: SQL allows users to retrieve data from databases using the SELECT
statement. Users can specify criteria to filter data, sort results, and perform calculations on
retrieved data.
2. Modifying Data: SQL provides commands such as INSERT, UPDATE, and DELETE to add,
modify, and remove data from database tables.
3. Creating and Modifying Database Structures: SQL allows users to define the structure of
databases and database objects such as tables, indexes, views, and stored procedures using
commands like CREATE, ALTER, and DROP.
4. Data Integrity and Constraints: SQL supports the definition of constraints such as primary
keys, foreign keys, unique constraints, and check constraints to ensure data integrity and
enforce business rules.
5. Data Manipulation and Transformation: SQL provides functions and operators for
manipulating and transforming data, such as arithmetic operations, string functions, date
and time functions, and aggregate functions like SUM, AVG, COUNT, MIN, and MAX.
6. Data Security: SQL allows users to manage database security by defining user permissions
and roles to control access to data and database objects.
7. Data Backup and Recovery

© 360DigiTMG. All Rights Reserved.


Assignment:-03
Introduction to sql and sql commands
In SQL, a foreign key is a column or a set of columns in a table that establishes a relationship
with another table's primary key or a unique key constraint. It ensures referential integrity
between the data in the two related tables. The foreign key constraint enforces that the
values in the foreign key column(s) of one table must match the values in the primary key
column(s) of another table or a unique key constraint.

CREATE TABLE Orders (

OrderID INT PRIMARY KEY,

CustomerID INT,

OrderDate DATE,

FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)

);
In the above example, the CustomerID column in the Orders table is a foreign key that
references the CustomerID column in the Customers table. This establishes a relationship
between the Orders table and the Customers table, indicating that each order must be
associated with an existing customer.

1. Create database classroom;

Use database;

2.CREATE TABLE science_class (

enrollment_no INT PRIMARY KEY,

name VARCHAR(255),

science_marks INT

);

1.INSERT INTO science_class (enrollment_no, name, science_marks) VALUES

(1, 'popeye', 33),

(2, 'olive', 54),

(3, 'brutus', 98);

© 360DigiTMG. All Rights Reserved.


Assignment:-03
Introduction to sql and sql commands
2.LOAD DATA INFILE 'path_to_your_file/student.csv'

INTO TABLE science_class

FIELDS TERMINATED BY ','

ENCLOSED BY '"'

LINES TERMINATED BY '\n'

IGNORE 1 LINES;

1. SELECT * FROM science_class;

2.SELECT name FROM science_class WHERE science_marks > 60;

3.SELECT * FROM science_class WHERE science_marks > 35 AND science_marks < 60;

4.SELECT * FROM science_class WHERE science_marks <= 35 OR science_marks >= 60;

1.UPDATE science_class SET science_marks = 45 WHERE name = 'popeye';

2.DELETE FROM science_class WHERE name = 'robb';

3.ALTER TABLE science_class CHANGE COLUMN name student_name VARCHAR(255);

© 360DigiTMG. All Rights Reserved.

You might also like