SQL_Statements_To_Insert - SQL Statements to Insert,...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: SQL Statements to Insert, Delete, and Update the Data For this exercise, create the following tables create table Instructor ( InstructorID Number PRIMARY KEY, FirstName Varchar (10), LastName Varchar (20) ); create table DBST651_Students ( StudentID Number PRIMARY KEY, FirstName varchar (10), LastName varchar (20), Birthday Date, Grade char(1), instructorId number, constraint fk_instructorID FOREIGN KEY (instructorID) REFERENCES Instructor (InstructorID) ); How to insert data into the table Insert into keyword is followed by the table name. In the first parenthesis you list the names of the table columns, and in the second parenthesis you list the values for each corresponding column. The columns don’t have to be listed in the same order as in the table definition. However, the corresponding values need to be in the same order as the columns. For instance, in the statement below, I could have Grade column first. Then, value ‘A’ would need to be before the rest of the values. As an exercise, try to insert a record into DBST651_Students first. Insert into DBST651_Students (StudentID, FirstName, LastName, Birthday, Grade, InstructorID) Values (1, 'Mary', 'Artis', To_Date('11/12/1979', 'mm/dd/yyyy'), 'A', 2); Expect to get an error because instructorID is a foreign key in DBST651_Students, and the Instructor table doesn’t have a record for instructor with the instructorID=2 Hence, we need to populate the instructor table first. Run the following code to insert data in both tables. Insert into table_name (Column names) values (column values); Insert into instructor (InstructorID, FirstName, LastName) Values (1, 'James','Greene'); Insert into instructor (InstructorID, FirstName, LastName)...
View Full Document

This note was uploaded on 12/22/2009 for the course DBST DBST 651 taught by Professor Yelena - ta during the Spring '09 term at MD University College.

Page1 / 9

SQL_Statements_To_Insert - SQL Statements to Insert,...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online