Sample Header Ad - 728x90

Database Administrators

Q&A for database professionals who wish to improve their database skills

Latest Questions

6 votes
1 answers
818 views
When creating stored procedure, are the comments before the definition always preserved?
When I wrote some comments before the `CREATE PROCEDURE` command, those comments seem to be preserved as part of procedure definition. For example, when I create procedure like this ``` /*Comment header*/ CREATE OR ALTER PROCEDURE example_procedure AS SELECT 1 AS Id ``` The `/*Comment header*/` is s...
When I wrote some comments before the CREATE PROCEDURE command, those comments seem to be preserved as part of procedure definition. For example, when I create procedure like this
/*Comment header*/
CREATE OR ALTER PROCEDURE example_procedure
AS 
SELECT 1 AS Id
The /*Comment header*/ is stored as part of definition. [Fiddle](https://dbfiddle.uk/-CaBLVX6) Is that documented behavior, can I always count on that? Or is that just some unreliable SQL Server quirk? My naive understanding is that the procedure definition starts with CREATE keyword, so I am hesitant to rely on behavior that goes against my intuition.
Yano_of_Queenscastle (1998 rep)
Jan 29, 2025, 07:45 AM • Last activity: Jan 30, 2025, 12:00 PM
6 votes
2 answers
621 views
SQL Comments disappear with psql and `\e`
Is there anyway at all, ever to change the behavior of comments in `psql`. Take the query below. Execute it. CREATE TABLE foo AS SELECT x AS id, -- x AS id2, x AS id3 FROM generate_series(1,50) AS x; Run that in psql. Then run `\e`. Now at least, for me what I see in my editor is the line absent. Th...
Is there anyway at all, ever to change the behavior of comments in psql. Take the query below. Execute it. CREATE TABLE foo AS SELECT x AS id, -- x AS id2, x AS id3 FROM generate_series(1,50) AS x; Run that in psql. Then run \e. Now at least, for me what I see in my editor is the line absent. This is driving me crazy. Is there a way around this.. The comment is just absent from the buffer that gets passed to the editor. Often, it's commented and not deleted because I want to *uncomment* it at a later point. Comment gone
Evan Carroll (65502 rep)
Mar 9, 2017, 03:07 AM • Last activity: Sep 2, 2022, 12:33 PM
0 votes
1 answers
911 views
Can show the comments writing in the create table command?
We can write comment to create a table: create database `mytest`; use `mytest`; create table `mytest` ( /* mytest mytest */ `code` varchar(15) NOT NULL, `type` varchar(20) NOT NULL ); How can show the comment `/* mytest mytest */` in create table command? show create table mytest; +--------+--------...
We can write comment to create a table: create database mytest; use mytest; create table mytest ( /* mytest mytest */ code varchar(15) NOT NULL, type varchar(20) NOT NULL ); How can show the comment /* mytest mytest */ in create table command? show create table mytest; +--------+------------------------------------+ | Table | Create Table | +--------+------------------------------------+ | mytest | CREATE TABLE mytest ( code varchar(15) NOT NULL, type varchar(20) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
showkey (386 rep)
Aug 15, 2021, 01:54 PM • Last activity: Aug 16, 2021, 07:21 PM
42 votes
1 answers
38417 views
Changing mysql table comment
I know that mysql **table comment** can be defined at the creation with: `create table (...)comment='table_comment';` And you can display comments by: `show table status where name='table_name';` How do you change (alter?) *table comment* after it's been created. I mean wihtout dropping and recreati...
I know that mysql **table comment** can be defined at the creation with: create table (...)comment='table_comment'; And you can display comments by: show table status where name='table_name'; How do you change (alter?) *table comment* after it's been created. I mean wihtout dropping and recreating the table again.
v14t (523 rep)
Feb 25, 2014, 08:32 AM • Last activity: Apr 22, 2021, 08:15 AM
1 votes
1 answers
298 views
Is the "comments" field in pgAdmin 4 a pgAdmin thing, or is it a PostgreSQL feature?
If I right-click a table (or any object) in pgAdmin 4 and select "Properties", it brings up a GUI window which allows me to change the name of the table and many other things. One of the fields is called "Comment". The manual for pgAdmin 4 just states this useless description: > Store notes about th...
If I right-click a table (or any object) in pgAdmin 4 and select "Properties", it brings up a GUI window which allows me to change the name of the table and many other things. One of the fields is called "Comment". The manual for pgAdmin 4 just states this useless description: > Store notes about the table in the Comment field. Where exactly is this stored? In the actual PostgreSQL database? Or some separate, special pgAdmin storage? It seems to have nothing to do with the SQL comments such as: -- This is an SQL comment. Also, if I add such SQL comments inside my query, are they discarded by both PostgreSQL and pgAdmin, or added somewhere? For example, this query: CREATE TABLE blablabla ...; -- This table is so cool, dude. Would "This table is so cool, dude." just be stripped away by both pgAdmin and PG? I looked in the PG manual but found no special "COMMENTS" feature, where the comment is actually stored in PG. For example, something like this: CREATE TABLE blablabla ... WITH COMMENT 'This table is so cool, dude.'; Please clarify.
postgrrrsql (11 rep)
Nov 1, 2020, 08:11 AM • Last activity: Nov 1, 2020, 08:25 AM
0 votes
2 answers
1770 views
SQL SERVER: How to get the stored procedure text EXCLUDING comments?
I need to find all the stored procs that use Transactions, as I want to enable transaction abort to those procedures. However, --I didn't do this; it's inherited-- many of the stored procedures contain testing procedures with in comment blocks and most of the tests contain transaction blocks. I am o...
I need to find all the stored procs that use Transactions, as I want to enable transaction abort to those procedures. However, --I didn't do this; it's inherited-- many of the stored procedures contain testing procedures with in comment blocks and most of the tests contain transaction blocks. I am only interested in changing stored procs that actually use transactions. AND I want to be able to monitor when stored procs are updated so that I can make sure that this flag is set. SET XACT_ABORT ON; Addendum: based on comments, here're some examples from my system. /* -- clean up after tests BEGIN TRANSACTION EXEC dbo.AR_Cleanup_MoveEqualAndOppositeSBPLiabilities ROLLBACK TRANSACTION */ /* Use case: 147 BEGIN TRANSACTION .... */
Display name (103 rep)
Jul 29, 2019, 03:42 PM • Last activity: Jul 30, 2019, 01:12 PM
8 votes
1 answers
2901 views
What is the maximum length of a comment in PostgreSQL?
PostgreSQL has a special piece of a functionality called [`COMMENT`](https://www.postgresql.org/docs/current/sql-comment.html) which attaches metadata to an identifier or any type (schema, table, column, function, type, domain, etc). It looks like this, COMMENT ON TABLE mytable IS 'This is my table....
PostgreSQL has a special piece of a functionality called [COMMENT](https://www.postgresql.org/docs/current/sql-comment.html) which attaches metadata to an identifier or any type (schema, table, column, function, type, domain, etc). It looks like this, COMMENT ON TABLE mytable IS 'This is my table.'; Is there a maximum size for the comment?
Evan Carroll (65502 rep)
Feb 26, 2019, 05:43 AM • Last activity: Feb 26, 2019, 08:17 AM
9 votes
1 answers
10422 views
Comments in EXPDB parameter file
Is there a way to put comments in a data pump export parameter file?
Is there a way to put comments in a data pump export parameter file?
Leigh Riffel (23884 rep)
May 31, 2012, 06:18 PM • Last activity: Feb 21, 2018, 05:44 PM
2 votes
1 answers
6110 views
Line Comment in MongoDB config file
How to mark a line comment in mongodb configuration file? cpu=true #temporary for dev env Is this the right way? There is no clue about it in their website page about setting the configuration options.
How to mark a line comment in mongodb configuration file? cpu=true #temporary for dev env Is this the right way? There is no clue about it in their website page about setting the configuration options.
abhisekp (123 rep)
Jan 19, 2014, 02:58 PM • Last activity: Mar 9, 2017, 06:46 AM
2 votes
2 answers
2082 views
How can can I get object definitions stripped of all comments?
When I want to know if a stored procedure or views references a given name (table, view or column), I need a version of the object definition stripped of all comments. Is this possible by a SQL query in an usual DBMS system? **Edit:** For SQL Server I found this solution using [Microsoft.Data.Schema...
When I want to know if a stored procedure or views references a given name (table, view or column), I need a version of the object definition stripped of all comments. Is this possible by a SQL query in an usual DBMS system? **Edit:** For SQL Server I found this solution using [Microsoft.Data.Schema.ScriptDom.Sql]. Here is the minimal PowerShell Code: $sql = @' select * from PowerShell -- a comment where psRefnr = 1 '@ $options = new-object Microsoft.Data.Schema.ScriptDom.Sql.SqlScriptGeneratorOptions $sr = new-Object System.IO.StringReader($sql) $sg = new-object Microsoft.Data.Schema.ScriptDom.Sql.Sql100ScriptGenerator($options) $parser = new-object Microsoft.Data.Schema.ScriptDom.Sql.TSQL100parser($true) $errors = $null $fragment = $parser.Parse($sr,([ref]$errors)) $out = $null $sg.GenerateScript($fragment,([ref]$out)) $out The advantage of this approach is that it uses the official Microsoft parser. **3rd Edit:** The basic methods to get the procedure definitions in T-SQL are as mentioned [here] are 1. sp_help proc_name 2. SELECT [text] FROM sys.syscomments WHERE OBJECT_NAME(id) = 'proc_name' 3. SELECT OBJECT_DEFINITION(OBJECT_ID('proc_name')) The second and third option return columns of type varchar(max) which can be used in LIKE clauses. **Historical Note:** When '****=' and '=****' became obsolete, syscomments returned the definition in chunks of 255 characters and the two could be placed into different rows. But the second problem isn't resolved yet. Some faltering developers tended to keep old code as C - style comments, making scanning for code containing deprecated syntax difficult.
bernd_k (12389 rep)
Mar 10, 2011, 02:23 PM • Last activity: Mar 9, 2017, 03:40 AM
3 votes
1 answers
671 views
Can comments in stored procedures cause problems
We're running a webserver that calls stored procedures to compute complex queries. Using sp_who2, we've discovered a peculiar issue where an abnormal number of processes would be stuck on SELECT state for a long duration. I've ran [this sp][1] to track down what query is being ran by the processes a...
We're running a webserver that calls stored procedures to compute complex queries. Using sp_who2, we've discovered a peculiar issue where an abnormal number of processes would be stuck on SELECT state for a long duration. I've ran this sp to track down what query is being ran by the processes and to my surprise, the following is what we discovered: --EXECUTE SP_POS_SU01 'SU_INV_LIST_XML', '20110501', '0001031082', '104301775', '021', '2', '', '', '', '', '', '', '', '', '', '' --EXECUTE SP_POS_SU01 'IN_LIST_XML', '0001031086', '20110701', '20110725', ... Several more executes that are commented out Here's what our SP looks like: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO --EXECUTE SP_POS_SU01 'SU_INV_LIST_XML', '20110501', '0001031082', '104301775', '021', '2', '', '', '', '', '', '', '', '', '', '' --EXECUTE SP_POS_SU01 'IN_LIST_XML', '0001031086', '20110701', '20110725', ALTER PROCEDURE [SomeDB].[SP_POS_SU012_XML] @CRDATE VARCHAR(08) , @CUS_CD VARCHAR(10) , @PRODUCT_CD VARCHAR(13) , @ORDER_GB VARCHAR(03) , @CANCEL_YN VARCHAR(01) ... We weren't sure if the commented execute codes we defined for testing purposes in SP were actually being ran with the SP calls. From our internal testing, we couldn't reproduce the same behavior, but removing those commented lines of execute seemed to do the trick as sp_who2 no longed showed hundreds of processes stuck on SELECT. But since I have absolutely no way to tell if this was the real cause or not, I have to ask: could such comments actually produce side-effects described here? Or worse, could this have happened from a deliberate attempt to attack our server/database?
TtT23 (275 rep)
Apr 16, 2014, 04:18 AM • Last activity: Mar 9, 2017, 03:39 AM
Showing page 1 of 11 total questions