This article will show you the most common or important or
most common sql command. This will be helpful for the beginners sql developers.
So in this we will cover following points:
- Create New Database
- Alter Database
- Create New Table
- Insert Record
- Select Record
- Update Record
- Delete Record
- Truncate Record
• Create New Database: In this will see how we can
create a new data base by using sql query.
Syntax:
Create database <databasename>;
|
Create database TestDataBase;
|
• Alter Database: In this we ill check how we can
alter the database name in sql.
Syntax:
ALTER DATABASE <OldDataBaseName>
Modify Name = <NewDataBaseName> ;
|
Example:
ALTER DATABASE TestDataBase
Modify Name = TestDataBaseModified ;
|
Finally, here is the output with modified data base name.
• Create New Table: In this section we will see how
we can create a table in sql server.
Syntax:
CREATE TABLE tablename (
Column1 datatype,
Column2 datatype,
Column3 datatype,
.
.
Columnn datatype
);
|
Example:
CREATE TABLE TestTable (
Id int,
Name varchar(50),
Address varchar(100)
);
|
Now run the query and check
Now check the database weather the table is created or not.
• Insert Record: In this we ill check how we can
insert data int table.
Syntax:
INSERT INTO tablename
VALUES (value1, value2, value3, ...,valueN);
|
Example:
INSERT INTO TestTable
(Id
,Name
,Address)
VALUES
(1,
'aspdotnetpoolss.com',
'internaet');
|
Now check the table for output.
• Select Record: In this we will cover how we can access
the data present into the database table.
Syntax:
SELECT Coumn1,
,Colum2
,Cloumn3
.
.
.
ColumnN
FROM TestTable
|
Example:
SELECT Id
,Name
,Address
FROM TestTable
|
Now run the query and check the output.
• Update Record: In this we learn how we can update the
record of a table.
Syntax:
Update TableName Set Column1=value1, Column2=value2,....ColumnN=valueN Where condation=Value;
|
Example:
UPDATE TestTable
SET Address = 'InterNetAddress'
WHERE Id=1;
|
Now run and check the output.
• Delete Record: In this we will check how we can delete
the record from the database
Syntax:
Delete from TableName Where Condation=value;
|
Example:
Delete All
Delete from TestTable
|
Conditional delete
Delete from TestTable Where Id=1
|
Run the above query and check the output.
• Truncate
Record: Truncate table us used for removing all the detail from the database
table.
Syntax:
Truncate Table TableName;
|
Example:
Truncate Table TestTable;
|
Run the
above query and check the query.
0 comments:
Please let me know your view