AugForums.com

An Acumatica User Group

  • Free
    • Start Here
    • Rolodex
    • Podcast
    • Blog
    • Forums
  • Paid
    • AugSQL
    • GI Course
    • GI Library
    • Consulting
  • Register
Acumatica Forums

By using this website, you agree to our Terms of Use (click here)

Forums
AugSQL
AugSQL
CREATE OR ALTER Sta...
 
Notifications
Clear all

#AcumaticaTnT CREATE OR ALTER Statement

 
Votes Received: 1

AugSQL
Last Post by Tim Rodman 1 year ago
1 Posts
1 Users
1 Reactions
34 Views
RSS
Tim Rodman
Posts: 3193
 Tim Rodman
Admin
Topic starter
March 20, 2024 10:05 am
(@timrodman)
Famed Member
Joined: 10 years ago

I just learned about SQL syntax that apparently has been around since SQL Server 2016.

 

Previously, I would use this SQL code to create a VIEW:

DROP VIEW IF EXISTS dbo.MySQLSystemEvent
GO
CREATE VIEW dbo.MySQLSystemEvent AS
SELECT 2 AS CompanyID,ID,TenantName,[Date],[Level],Source,EventID,ScreenID,[User],Details,Properties
FROM SystemEvent

 

The reason for the first two lines is that I want to be able to run the same SQL Code whether the View already exists or not.

But there are two problems with it:

1. I can never remember the DROP VIEW IF EXISTS... part and always have to Google it.

2. The view gets a new Created date on it which I don't like. I'd like to know the date that the view was originally created.

 

Now, with my new discovery (that has existed for 8 year already apparently), I can write this instead:

CREATE OR ALTER VIEW dbo.MySQLSystemEvent AS
SELECT 2 AS CompanyID,ID,TenantName,[Date],[Level],Source,EventID,ScreenID,[User],Details,Properties
FROM SystemEvent

 

This is awesome! It solves both problems:

1. I can remember CREATE OR ALTER without having to Google it.

2. The Created date on the view doesn't change since an ALTER statement gets run if it already exists.

 

I love it!

Rob Neal reacted
Forum Jump:
  Previous Topic
Next Topic  
Forum Information
Recent Posts
Unread Posts
Tags
  • 12 Forums
  • 2,521 Topics
  • 10.9 K Posts
  • 12 Online
  • 2,321 Members
Our newest member: Courtney Wilder
Latest Post: Can UDFs be populated using an Import Scenario?
Forum Icons: Forum contains no unread posts Forum contains unread posts
Topic Icons: Not Replied Replied Active Hot Sticky Unapproved Solved Private Closed

Online Members

 No online members at the moment

Acumatica Forums

Terms of Use & Disclaimers :: Privacy Policy

Copyright © 2025 · AUG Forums, LLC. All rights reserved. This website is not owned, affiliated with, or endorsed by Acumatica, Inc.

‹›×

    ‹›×