Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I need help writing some basic Cursor
I want creating a table with 4/5 columns and insert into the table 1 Mil rows
I am not sure how to write the Cursor that's where I need my help with :/
The task you mention can be done by creating the table and using a simple t-sql procedure to insert the rows, like so -
DDL for create table -
CREATE TABLE Persons
(
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
t-sql to populate table -
DECLARE #cnt INT = 0;
WHILE #cnt < 1000000
insert into persons values(#cnt,'smith','gever','madison','barcelona');
SET #cnt = #cnt + 1;
end;
Was this what you meant? Cause it ain't a cursor.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 days ago.
Improve this question
I mistakenly deleted the first row of my table in SQL Server. Can I add it back still as the first row?
I tried using the INSERT INTO statement, but it will put it as the last column in the table while I want it to be the first.
You can use this script to insert
IF OBJECT_ID(N'MyBackupTable') IS NOT NULL
BEGIN
DROP TABLE MyBackupTable
END
select * into MyBackupTable from demo
SET IDENTITY_INSERT MyBackupTable ON;
INSERT INTO MyBackupTable (id, name) VALUES (1, 'My Value')
SET IDENTITY_INSERT MyBackupTable OFF;
DELETE FROM demo;
SET IDENTITY_INSERT demo ON;
INSERT INTO demo (id, name)
SELECT * FROM MyBackupTable
SET IDENTITY_INSERT demo OFF;
DROP TABLE MyBackupTable
SELECT * FROM demo
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have a table with a xml column, I need to modify a few fields in the XML for every row. The new values should be unique to that entry, I want to do that by appending the primary key (ID int) to the value in the fields.
For instance: I inserted the rows into a temp table. For simplicity, assume the table only has two columns: payload (XML), id (INT, primary key)
UPDATE #Temp
SET payloadXml.modify('replace value of (/abc/customer/contact/name[#part=("first")]/text())[1] with "hello"')
FROM #Temp
This will replace the first name field with hello. But I want to append the id of that row to this field. I tried sql:variable, but to no avail. Is this even possible?
You can use sql:column to reference a relational column in your XML DML, eg
drop table if exists #temp
go
create table #temp(id int identity primary key, payloadXML xml)
go
insert into #temp(payloadXml) values ('<abc><customer><contact><name part="first">foo</name></contact></customer></abc>');
insert into #temp(payloadXml) values ('<abc><customer><contact><name part="first">foo</name></contact></customer></abc>');
insert into #temp(payloadXml) values ('<abc><customer><contact><name part="first">foo</name></contact></customer></abc>');
WITH q as
(
select *, concat('hello ', id) new_name
from #Temp
)
UPDATE q
SET payloadXml.modify('replace value of (/abc/customer/contact/name[#part=("first")]/text())[1]
with sql:column("new_name")')
select payloadXML from #temp
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Good day what is the best data type to use for numbers in SQL Server
Test Your Data Types here
https://www.tutorialspoint.com/execute_sql_online.php
Run the Below t-sql for more your data types as below
BEGIN TRANSACTION;
/* Create a table called NAMES */
CREATE TABLE [Customer]
(
[CustomerKey] [int] IDENTITY(1,1) NOT NULL,
[Test_Number] [varchar](50) NULL
);
insert into Customer values (1,"25/08/2018");
insert into Customer values (2,15:06:59);
insert into Customer values (3,25.01);
insert into Customer values (4,"GL45R-2");
select * from Customer
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
A patient can select many tests, and a test can be selected by many patient.
Then what would be the structure of these tables and how the relationship can be established between them?
your table structure should be below
PatientTable
PatientId int Primary Key,
PatientName varchar(50),
EmailId varchar(50)
Password varchar(50)
TestTable
TestId int Primary key,
TestName varchar(50)
PatientTestTable
PatientId int FK(PatientTable)
TestId int FK (TestTable)
This way you can give relationship to two tables. you need to understand funamental of RDBMS.
You will probably need 3 tables, Patient table, Test Table and PatientTest Table
with PatientID as foreign key fro Patient table and TestId as foreign key from Test table and you can add any other column ( like TestDatetime, TestResult ...)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is it important for any of the reasons if I create column A before column B in SQL Server database? No other actions are presumed in between.
See this:
Your Table Structure:
create table test (id int, name varchar(100));
Table of your customer:
create table test (name varchar(100), id int);
If you use:
insert into test values (10, 'Roger')
without specifying the order of fields in the table will cause your customer conversion error.