SQL Structured query language
ALERT: The general syntax is in BLUE and the example syntax is in ORANGE
1.)First, we will create a database
CREATE DATABASE database_name
CREATE DATABASE student_database
2.)Then we will use that database,
USE database_name
USE student_database
3.)Then we will create a table and assign the names of the columns which we want to add in our table.
CREATE TABLE table_name (column1,column2,column3...)
CREATE TABLE student_table (first_name VARCHAR(400), last_nameVARCHAR(400), class INT, section VARCHAR(400), address_city VARCHAR(400) )
ALERT: while specifying the column name, we also have to specify its data type. Like the character in first_name, last_name, section, address_city, and an integer for class columns.
In order to print the column name, this syntax will be used
Select * from table_name
Select * from student_table
4.)Now our table and the columns we want in it are ready. Finally, we can insert the student info in it.
INSERT INTO table_name
values(first name, last name, class, section, city)
INSERT INTO student_table
values('Vikas', 'Singh', 14, 'A', 'Delhi')
In order to print the this info, this syntax will be used
Select * from table_name
Select * from student_table
This way, we can add all the student info in our student_table.
5.)UPDATE EXISTING INFO
Let's suppose, Vikas Singh is shifted from section A to B. Now you have to update this info. So this syntax will be used.
UPDATE table_name
SET section= 'B' where first_name= 'Vikas'
Select * from the table_name
UPDATE student_table
SET section= 'B' where first_name= 'Vikas'
Select * from the student_table
6.)Print top 3 entries of the table
Select top 3 * from the student_table
7.)Print top 50% of the table
Select top 50% * from the student_table
8.)Print desired columns from the table
SELECT class, section from the table_name
9.)Print distinct columns from the table
SELECT DISTINCT column1, column2 from the table_name
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home