how to increment integer Columns value by 1 in SQL
To add one to every value in the table… UPDATE myTable SET ID = ID + 1 To create a new value, one more then the previous highest (usually), use a column with IDENTITY
To add one to every value in the table… UPDATE myTable SET ID = ID + 1 To create a new value, one more then the previous highest (usually), use a column with IDENTITY
get today no time: SELECT dateadd(day,datediff(day,0,GETDATE()),0) get yestersday no time: SELECT dateadd(day,datediff(day,1,GETDATE()),0) query for all of rows from only yesterday: select * from yourTable WHERE YourDate >= dateadd(day,datediff(day,1,GETDATE()),0) AND YourDate < dateadd(day,datediff(day,0,GETDATE()),0)
Collation can be simply thought of as sort order. In English (and it’s strange cousin, American), collation may be a pretty simple matter consisting of ordering by the ASCII code. Once you get into those strange European languages with all their accents and other features, collation changes. For example, though the different accented forms of … Read more
The insert statement actually has a syntax for doing just that. It’s a lot easier if you specify the column names rather than selecting “*” though: INSERT INTO new_table (Foo, Bar, Fizz, Buzz) SELECT Foo, Bar, Fizz, Buzz FROM initial_table — optionally WHERE … I’d better clarify this because for some reason this post is … Read more
Try this: insert into MyTable(field1, field2, id_backup) select field1, field2, uniqueId from MyTable where uniqueId = @Id; Any fields not specified should receive their default value (which is usually NULL when not defined).
I also wanted to convert a named instance to default – my reason was to access it with just the machine name from various applications. If you want to access a named instance from any connection string without using the instance name, and using only the server name and/or IP address, then you can do … Read more
You can create temp stored procedures like: create procedure #mytemp as begin select getdate() into #mytemptable; end in an SQL script, but not functions. You could have the proc store it’s result in a temp table though, then use that information later in the script ..
Some uses for APPLY are… 1) Top N per group queries (can be more efficient for some cardinalities) SELECT pr.name, pa.name FROM sys.procedures pr OUTER APPLY (SELECT TOP 2 * FROM sys.parameters pa WHERE pa.object_id = pr.object_id ORDER BY pr.name) pa ORDER BY pr.name, pa.name 2) Calling a Table Valued Function for each row in … Read more
How long should I expect ALTER DATABASE … SET ENABLE_BROKER to run? alter database [<dbname>] set enable_broker with rollback immediate;
You need to set identity_insert YourTable ON Then delete your row and reinsert it with different identity. Once you have done the insert don’t forget to turn identity_insert off set identity_insert YourTable OFF