Question:
Help with T-SQL insert query?
John
2013-03-13 08:14:49 UTC
could someone please help me write a T-SQL insert query for the table below

USE ICA_NHS_GPdb
GO
IF OBJECT_ID('ICA_NHS_GPdbSchema.Address', 'U') IS NOT NULL
DROP TABLE ICA_NHS_GPdbSchema.Address
GO
CREATE TABLE ICA_NHS_GPdbSchema.Address
(
AddressID int identity(1,1) not null,
AddressLine1 nchar(6) null,
AddressLine2 nchar(20) null,
AddressLine3 nchar(20) null,
AddressLine4 nchar(20) null,
AddressLine5 nchar(20) null,
UpdatedLastIn VARCHAR(10) null,
Postcode VARCHAR(10) null
)
GO

how could i popular a single row onto the above table using T-SQL thank you
Four answers:
TheMadProfessor
2013-03-13 08:43:53 UTC
Since AddressID is defined as IDENTITY, you don't need to (or iirc, are even permitted to) specify a value for that column when inserting. Since all the others are specified as nullable, any of them could be omitted from an INSERT. One possible:



INSERT INTO Address (AddressLine2, AddressLine4, AddressLine5, Postcode)

VALUES ("1234 Main Street", "New York City", "NY", "10012")
2013-03-13 08:43:08 UTC
INSERT INTO ICA_NHS_GPdbSchema.Address(AddressLine1, AddressLine2,

      AddressLine3, AddressLine4, AddressLine5, UpdatedLastIn, PostCode)

      VALUES('Address 1', 'Address 2',

      'Address 3', 'Address 4', 'Address 5', '2013-03-13', '1111');



AddressID must be not populated because it is declared as identity field
teets
2016-12-17 21:28:03 UTC
MS get entry to would not permit you write distinctive instructions in a saved technique it extremely is what would be mandatory for this. you will would desire to write the code in a seperate programming language like VB.internet Or greater constructive nonetheless do no longer use MS get entry to apply sq. Server convey it extremely is loose and much greater robust then MS get entry to.
Serge M
2013-03-13 09:28:09 UTC
How to insert: http://www.sql-tutorial.ru/en/book_operator_insert.html


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...