Here is a SQL query to create a table to store student information:
```
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
FirstName VARCHAR(50) NOT NULL,
LastName VARCHAR(50) NOT NULL,
DateOfBirth DATE,
Email VARCHAR(100) UNIQUE,
Phone VARCHAR(20),
Address VARCHAR(200),
City VARCHAR(50),
State VARCHAR(50),
Country VARCHAR(50),
PostalCode VARCHAR(10),
Course VARCHAR(50),
Department VARCHAR(50)
);
```
Here's a brief explanation of each column:
- `StudentID`: Unique identifier for each student.
- `FirstName` and `LastName`: Student's name.
- `DateOfBirth`: Student's date of birth.
- `Email`: Student's email address (unique).
- `Phone`: Student's phone number.
- `Address`, `City`, `State`, `Country`, and `PostalCode`: Student's address.
- `Course` and `Department`: Student's course and department.
To insert data into the table:
```
INSERT INTO Students (
StudentID,
FirstName,
LastName,
DateOfBirth,
Email,
Phone,
Address,
City,
State,
Country,
PostalCode,
Course,
Department
)
VALUES (
1,
'John',
'Doe',
'1990-01-01',
'john.doe@example.com',
'123-456-7890',
'123 Main St',
'Anytown',
'CA',
'USA',
'12345',
'Computer Science',
'Engineering'
);
```
To retrieve data from the table:
```
SELECT * FROM Students;
```
To update data in the table:
```
UPDATE Students
SET FirstName = 'Jane'
WHERE StudentID = 1;
```
To
delete data from the table:
```
DELETE FROM Students
WHERE StudentID = 1;
```
No comments:
Post a Comment