SQL Queries Create Insert Update Delete

SQL Queries Create Insert Update Delete

Hello everyone, I am going to share the code sample for creating query for Create, Insert,  Update and Delete in SQL Server.

The Queries in detail as given below.

/****** THE SQL QUERY FOR CREATE, INSERT, SELECT, UPDATE AND DELATE  ******/

 --CRETAE TABLE QUERY

 --START QUERY
 CREATE TABLE [DBO].[TENANT](
            [TENANTID] [BIGINT] IDENTITY(1,1) NOT NULL,
            [NAME] [NVARCHAR](50) NOT NULL,
            [ADDRESS] [NVARCHAR](2000) NULL,
            [CONTACTNUMBER] [NVARCHAR](50) NULL,
            [WEBSITE] [NVARCHAR](80) NULL,
            [REGNID] [NVARCHAR](50) NULL,
            [CREATEDDATE] [DATETIME] NOT NULL,
            [CREATEDBY] [BIGINT] NOT NULL,
            [UPDATEDDATE] [DATETIME] NULL,
            [UPDATEDBY] [BIGINT] NULL,
            [ISACTIVE] [BIT] NOT NULL,
            [ISDELETED] [BIT] NOT NULL,
 CONSTRAINT [PK_TENANTS] PRIMARY KEY CLUSTERED
(
            [TENANTID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [DBO].[TENANT] ADD  CONSTRAINT [DF_TENANT_ISACTIVE]  DEFAULT ((0)) FOR [ISACTIVE]
GO

ALTER TABLE [DBO].[TENANT] ADD  CONSTRAINT [DF_TENANT_ISDELETED]  DEFAULT ((0)) FOR [ISDELETED]
GO
--END QUERY

 --INSERT TABLE QUERY

 --START QUERY
 INSERT  INTO [CORPORATEEMPLOYEE].[DBO].[TENANT](
       [NAME]
      ,[ADDRESS]
      ,[CONTACTNUMBER]
      ,[WEBSITE]
      ,[REGNID]
      ,[CREATEDDATE]
      ,[CREATEDBY]
      ,[UPDATEDDATE]
      ,[UPDATEDBY]
      ,[ISACTIVE]
      ,[ISDELETED]) VALUES('NOIDA, SEC 18', '1234567890', 'WWW.OPTUS.COM.AU',1,GETDATE(),1,GETDATE(),1,1,0)

--END QUERY

--SELECT TABLE QUERY

--START QUERY
SELECT TOP 1000 [TENANTID]
      ,[NAME]
      ,[ADDRESS]
      ,[CONTACTNUMBER]
      ,[WEBSITE]
      ,[REGNID]
      ,[CREATEDDATE]
      ,[CREATEDBY]
      ,[UPDATEDDATE]
      ,[UPDATEDBY]
      ,[ISACTIVE]
      ,[ISDELETED]
  FROM [CORPORATEEMPLOYEE].[DBO].[TENANT]
--END QUERY

--UPDATE TABLE QUERY

--START QUERY
UPDATE [CORPORATEEMPLOYEE].[DBO].[TENANT]
SET CONTACTNUMBER ='1234567800', UPDATEDDATE =GETDATE()
--END QUERY

--DELETE TABLE QUERY

--START QUERY
DELETE FROM [CORPORATEEMPLOYEE].[DBO].[TENANT] WHERE TENANTID=100
--END QUERY



ANIL SINGH

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Google Amazon and Flipkart Book Store!

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.
ASK Questions
SQL Server NodeJs TypeScript JavaScript Angular SQL Server My Book