Curriculum
Course: Data Analysis 2024 (Batch B)
Login

Curriculum

Data Analysis 2024 (Batch B)

Week 10

0/36
Text lesson

Class Twelve; Text (Modify data within a database using SQL)

UPDATE Statement:

 

Modifies existing data in a table.

UPDATE [table name ]

SET [column name ]

= CASE

 WHERE condition;

Example:

UPDATE [employees]

 SET [department ]

=Case

WHERE last name = ‘James’ THEN ‘Data Analytics’

 

HOW TO UPDAT SINGLE INFO FROM A COLUMN IN A TABLE WITHOUT AFFECTING OTHER INFO

UPDATE [table name]

SET [table name].the Header of the line you want to replace = new info

WHERE [table name].header = ‘Unique identifier’

 

Example

UPDATE [dbo].[Pupils_information]

SET [dbo].[Pupils_information].Age = 11

WHERE [dbo].[Pupils_information].Name = ‘Martins Ogbodo’

 

DELETE Statement:

Deleting a column in SQL is one of the most common operations when dealing with a database. For this reason, knowing how to properly delete a column in SQL is critical. Without the right procedures and precautions, you could run into data integrity and data loss issues.

What Does it Mean to Delete a Column in SQL?In SQL, deleting a column refers to the process of permanently removing a specific column from a table. All data associated with the column will be removed from the disk. Similarly, the column’s metadata will be removed from the table’s schema. When you delete a column, you essentially eliminate its existence within the table structure. The column will be no longer available for queries and its data will be lost.

Removes rows from a table based on a condition.

DELETE FROM [table name] WHERE condition;

Example:

DELETE FROM [employees]

WHERE last name = ‘Paul’;

 

To delete a column

Alter Table[Table Name]

Drop column[column name]

 

•Ensure caution when performing UPDATE and DELETE operations to avoid unintended consequences.
 
 
HOW TO BRING DATA BASE FILE INTO DATA BASE IN SQL
 
Open your SQL Server and right click Database and click restore database, it will bring a dialog box, choose device and click 3 dots at the right side of device to add file and browse to the location of the file. Then select the file name and click Ok.

Note the file must be .bak extension also saved on your local disk(c) inside user’s folder.