SQL Without Query AI Template
SQL Without Query AI Template
Structure Query Language(SQL) is a programming language used for storing and managing data in
RDBMS. SQL was the first commercial language introduced for E.F Codd's Relational model. Today
almost all RDBMS(MySql, Oracle, Infomix, Sybase, MS Access) uses SQL as the standard
database language. SQL is used to perform all type of data operations in RDBMS.
SQL Command
SQL defines following data languages to manipulate data of RDBMS.
Command Description
Command Description
Command Description
grant grant permission of right
Command Description
create command
create is a DDL command used to create a table or a database.
Creating a Database
To create a database in RDBMS, create command is uses. Following is the Syntax,
create database database-name;
Creating a Table
create command is also used to create a table. We can specify names and datatypes of various
columns along.Following is the Syntax,
create table table-name
column-name1 datatype1,
column-name2 datatype2,
column-name3 datatype3,
column-name4 datatype4
};
create table command will tell the database system to create a new table with given table name
and column information.
The above command will create a new table Student in database system with 3 columns, namely
id, name and age.
alter command
alter command is used for alteration of table structures. There are various uses of alter command,
such as,
The above command will add a new column with default value to the Student table
To Rename a column
Using alter command you can rename an existing column. Following is the Syntax,
alter table table-name rename old-column-name to column-name;
To Drop a Column
alter command is also used to drop columns also. Following is the Syntax,
alter table table-name drop(column-name);
DML command
Data Manipulation Language (DML) statements are used for managing data in database. DML
commands are not auto-committed. It means changes made by DML command are not permanent
to database, it can be rolled back.
1) INSERT command
Insert command is used to insert data into a table. Following is its general syntax,
INSERT into table-name values(data1,data2,..)
101 Adam 15
Or,
INSERT into Student values(102,'Alex',null);
The above command will insert only two column value other column is set to null.
S_id S_Name age
101 Adam 15
102 Alex
101 Adam 15
102 Alex
103 chris 14
2) UPDATE command
Update command is used to update a row of a table. Following is its general syntax,
UPDATE table-name set column-name = value where condition;
102 Alex 18
103 chris 14
101 Adam 15
102 Alex 18
103 Abhi 17
3) Delete command
Delete command is used to delete data from a table. Delete command can also be used with
condition to delete a particular row. Following is its general syntax,
DELETE from table-name;
101 Adam 15
102 Alex 18
103 Abhi 17
The above command will delete the record where s_id is 103 from Student table.
101 Adam 15
102 Alex 18
SELECT Query
Select query is used to retrieve data from a tables. It is the most used SQL query. We can retrieve
complete tables, or partial by mentioning conditions using WHERE clause.
The above query will fetch information of s_id, s_name and age column from Student table
101 Adam 15
102 Alex 18
103 Abhi 17
104 Ankit 22
The above query will show all the records of Student table, that means it will show complete Student
table as result.