Today before proceeding with NULL and DEFAULT keywords as promised in my earlier post, I thought it would be more meaningful to demonstrate the same practically.
Before that let us try inserting some data to our table myAddressBook. Type in the below command to insert a data to our table.
INSERT INTO myAddressBook (firstName, lastName, status, gender, location, birthday, email) VALUES (‘Naveen’, ‘Kumar’, ‘Single’, ‘M’, ‘London’, ‘1982-05-05’, ‘navi@testersdb.com’);
Now compare the above INSERT SQL command with the below standard syntax.
INSERT INTO table_name (columnName1, columnName2….columnNameN) VALUES (‘value1’, ‘value2’,……..’valueN’);
Some important points to be noted here:
Let us now try inserting data to a few selected columns in the same myAddressBook table by typing the below command.
INSERT INTO myAddressBook (firstName, status, gender, location, email) VALUES (‘Stewart’, ‘Single’, ‘M’, ‘Sunnyvale’, ‘steve@atoz1.com’);
You can even insert data without specifying the column names but make sure to enter data in the same order of your columns and should have all the values. Execute the below command to get a clear idea on this.
INSERT INTO myAddressBook VALUES (‘Anna’, ‘Smith’, ‘Married’, ‘F’, ‘London’, ‘1982-04-04’, ‘anna_hun@testersdb.com’);
Above listed INSERT Statements are some of the different ways of inserting data into a TABLE.
Now let us just look into the inserted data, to do that we will be using SELECT keyword. I will not be discussing about SELECT today, we will look into it in detail later. For now just execute the below command.
SELECT * from myAddressBook;
If you look at the myAddressBook table, there is a NULL value in lastName & birthday columns for second row which had on values inserted earlier. I shall write about NULL keyword in my next post. Till then Happy Reading…!!
Before that let us try inserting some data to our table myAddressBook. Type in the below command to insert a data to our table.
INSERT INTO myAddressBook (firstName, lastName, status, gender, location, birthday, email) VALUES (‘Naveen’, ‘Kumar’, ‘Single’, ‘M’, ‘London’, ‘1982-05-05’, ‘navi@testersdb.com’);
Now compare the above INSERT SQL command with the below standard syntax.
INSERT INTO table_name (columnName1, columnName2….columnNameN) VALUES (‘value1’, ‘value2’,……..’valueN’);
Some important points to be noted here:
- INSERT INTO, VALUES are the keywords.
- table_name : Provide the table name to which you want to insert data
- columnName1… : provide the column names for which you want to enter data, column name can be one or multiple.
- value1… : Based on the column details provided, enter their respective values. Also make sure to enter it in the same order as the column names.
Let us now try inserting data to a few selected columns in the same myAddressBook table by typing the below command.
INSERT INTO myAddressBook (firstName, status, gender, location, email) VALUES (‘Stewart’, ‘Single’, ‘M’, ‘Sunnyvale’, ‘steve@atoz1.com’);
You can even insert data without specifying the column names but make sure to enter data in the same order of your columns and should have all the values. Execute the below command to get a clear idea on this.
INSERT INTO myAddressBook VALUES (‘Anna’, ‘Smith’, ‘Married’, ‘F’, ‘London’, ‘1982-04-04’, ‘anna_hun@testersdb.com’);
Above listed INSERT Statements are some of the different ways of inserting data into a TABLE.
Now let us just look into the inserted data, to do that we will be using SELECT keyword. I will not be discussing about SELECT today, we will look into it in detail later. For now just execute the below command.
SELECT * from myAddressBook;
If you look at the myAddressBook table, there is a NULL value in lastName & birthday columns for second row which had on values inserted earlier. I shall write about NULL keyword in my next post. Till then Happy Reading…!!
Insert data into Table
Reviewed by Suntaragali The Smart Techie
on
December 20, 2012
Rating:
No comments: