CREATE TABLE (Transact-SQL)
Creating a simple table means:
1. Give the table name what you wants that is uniquely identified in database.
Example:
Tm_Employee, Tm_Department, Tm_Salary etc.
2. Table contains Rows and Column.
3.Columns contain the name of the column, data type, and any other attributes for the column.
3. Rows contains the values or data of the table column.
Here is Simple Table Example:
Below table name is [dbo].[Employee] and contains the column Employee_id, First_name, Last_name, Salary, Joinning_date and Department.
The Employee_id contains the data-type int and it is identity increment column (means Employee_id value automatically increment by one),
First_name contains the data-type nvarchar(300),
Last_name contains the data-type nvarchar(300),
Salary contains the data-type decimal(20,2),
Joining_Date contains data-type datetime,
Department contains data-type nvarchar(300).
Create Table First in SQL Server
From the Windows Start Menu --> select “Microsoft SQL Server”--> Click on “SQL Server Management Studio”.
Right Click on your created database (TestDB) -> and Click on New Query -> write the table query as below -> and Click Execute.
CREATE TABLE [dbo].[Employee](
[Employee_id] [int] IDENTITY(1,1) NOT NULL,
[First_name] [nvarchar](300) NULL,
[Last_name] [nvarchar](300) NULL,
[Salary] [decimal](20, 2) NULL,
[Joining_date] [datetime] NULL,
[Department] [nvarchar](200) NULL
Insert Record
Write the table query as below -> and select all -> and Click Execute.
INSERT [dbo].[Employee] ([First_name],
[Last_name], [Salary],
[Joining_date], [Department]) VALUES ('John', 'Abraham', 1000000.00, 1905-06-07, 'Banking')
INSERT [dbo].[Employee] ([First_name],
[Last_name], [Salary],
[Joining_date], [Department]) VALUES ('Michael', 'Clarke', 800000.00, 1894-06-28, 'Insurance')
Show Records
Show Records
select * from [dbo].[Employee]
No comments :
Post a Comment
Ask a Question?