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

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.