0% found this document useful (0 votes)
5 views5 pages

Crud

The document provides a SQL script for creating a 'salary' database and a 'students' table with columns for id, name, age, and course. It includes commands for inserting, updating, and deleting student records. The script demonstrates basic database operations such as creating a database, using it, and managing student data through SQL queries.

Uploaded by

venkat1238c
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)
5 views5 pages

Crud

The document provides a SQL script for creating a 'salary' database and a 'students' table with columns for id, name, age, and course. It includes commands for inserting, updating, and deleting student records. The script demonstrates basic database operations such as creating a database, using it, and managing student data through SQL queries.

Uploaded by

venkat1238c
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
You are on page 1/ 5

SQL Script for Creating a Students Table in the Salary

Database

Step 1: Create the Database


First, we create a new database named salary:

SQL Query :- CREATE DATABASE salary;

Step 2: Use the Salary Database


Switch to the newly created salary database to perform subsequent operations:

SQL Query :- use salary;

Step 3: Create the Students Table


Next, we create a table named students with the following columns:
 id: Unique identifier for each student.
 name: Name of the student.
 age: Age of the student.
 course: Course enrolled by the student.
Here is the SQL code to create the table with descriptions for each column:

Create a table:

CREATE TABLE students (


id INT PRIMARY KEY,
name VARCHAR(100),
age INT,
course VARCHAR(100)
);
After inserting a values in a table:

Inserting rows and columns to a table

INSERT INTO students (id, name, age, course) VALUES (1, 'John Doe', 20, 'Computer
Science');
INSERT INTO students (id, name, age, course) VALUES (2, 'Jane Smith', 22, 'Mathematics');
INSERT INTO students (id, name, age, course) VALUES (3, 'Mike Johnson', 21, 'Physics');

See the rows and col in a table:

select * from students;


Update:

Updating the course to data science where id =1

-- Update a student's course


UPDATE students
SET course = 'Data Science'
WHERE id = 1;

Updating the age to 23 where id =2


-- Update a student's age
UPDATE students
SET age = 23
WHERE id = 2;
Delete

-- Delete a student by id
DELETE FROM students
WHERE id = 3;

-- Delete all students older than 21


DELETE FROM students
WHERE age > 21;

You might also like