MSSQL syntax statement collection

Source: Internet
Author: User

Each object created in the database (constraints, default values, logs, rules, stored procedures, etc.) occupies one row in the table. OnlyTempdbInner,

Each temporary object occupies a row in the table.

Select * From sysobjects where type = 'U' select the user table

 

2. Begin ...... end

3 if aa <> 3 begin ...... end

4. While () Begin ......

5. Declare @ sqlstr varchar (10)

6. Set @ sqlstr = 'delete from [dnt_topictags] Where [TID] In ('+ @ tidlist + ')'

7. If exists (Select name from sysobjects
Where name = 'proc _ calculate_taxes 'and type = 'P ')

8.
Create procedure proc_calculate_taxes (@ P1 smallint = 42, @ P2 char (1 ),
@ P3 varchar (8) = 'car ')
As
Select *
From mytable

9. Execute the Stored Procedure

Declare @ C varchar (30)
Set @ C = 'processed'
Exec @ C

 

Declare @ se varchar (100)

Set @ Se = 'select * From table1'

Exec (@ SE)

'

10 put the values of the same field together declare @ A varchar (100)

Select @ A = @ A + ',' + loginid from account
Select @

11. alter table test add Columna int not null

Alter table test drop Columna

12. Dynamic stored procedures

Create proc test (@ V1 varchar (100 ))
As
Begin
Declare @ 55 varchar (100)

Set @ 55 = 'select * From tt' + @ V1
Exec (@ 55)
End
Go

13 random fetch records

Select top 10 *, newid () as random
From TT
Order by random

 

 

Example of randomly extracting 10 records:
SQL Server: Select top 10 * from Table order by newid ()

Access: Select top 10 * from Table order by RND (ID)
In RND (ID), the ID is an automatic number field, which can be completed using any other value, for example, the name field (username)
Select top 10 * from Table order by RND (LEN (username ))

MySQL: Select * from Table order by rand () limit 10
 

14. Case... When... else... end (http://lavasoft.blog.51cto.com/62575/23373)

Update e_ztbg set jddxh = (Case isnull (jddxh, '') when'' then isnull (jddxh,'') + '2017-0001 'else isnull (jddxh ,'') + ',' + '0001-080001' end)

Where lsh = '2017-0001'

15

Select Replace ('hello', 'E', 'xxx ')

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.