Session 7
CREATE Table | INSERT Data | SELECT Data
Click here for you tube video
Below are the scripts used for this session.
--> 1. Creation of database using SQL
------------------------------------------
--Syntax:
CREATE DATABASE <Database Name>
--> Creating database "SQL_Demo" Using SQL
CREATE DATABASE SQL_Demo
--> 2. Creation of Table in SQL (DDL)
------------------------------------------
--Syntax:
CREATE TABLE <Table Name> (
Col1 <COlumnDatatype> <Nullability>,
Col2 <COlumnDatatype> <Nullability>,
Col3 <COlumnDatatype> <Nullability>,
Col4 <COlumnDatatype> <Nullability>,
Col5 <COlumnDatatype> <Nullability>)
USE SQL_Demo
-- tblEmployee
CREATE TABLE tblEmployee (
Empid INT NOT NULL,
EmpName Varchar(20) NULL,
EmpLocation Varchar(20),
DOJ DATE,
Salary INT)
--> NULL is the deafult Nullability
--> 3. Inserting data into the Table in SQL (DML)
--------------------------------------------------
--Syntax:
INSERT INTO <TableName> (col1, col2, col3, col4) Values (col1, col2, col3, col4)
INSERT INTO tblEmployee (Empid,EmpName,EmpLocation,DOJ,Salary)
Values (1,'Smith','India', '2020-01-02',20000)
INSERT INTO tblEmployee (Empid,EmpName,EmpLocation,DOJ,Salary)
Values (2,'George Mark','US', '2019-04-28',50000)
INSERT INTO tblEmployee (Empid,EmpName,EmpLocation,DOJ,Salary)
Values (3,'Emp3','UK', '2018-04-28',25000),(4,'Emp4','UK', '2016-04-25',60000)
--> inserting data to specific columns
INSERT INTO tblEmployee (Empid,EmpName,DOJ)
Values (5,'Emp5','2011-04-28')
INSERT INTO tblEmployee (Empid,EmpName,DOJ)
Values (8,'Emp5','Emp3')
--> 4. Selecting data from the Table in SQL (DML)
--------------------------------------------------
--Syntax:
SELECT * FROM <Table Name>
SELECT * FROM tblEmployee
-- * - All columns
SELECT * FROM tblEmployee
SELECT Empid,EmpLocation, Salary FROM tblEmployee
No comments:
Post a Comment