Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Query code associated with a table

Author  Topic 

samyer
Starting Member

15 Posts

Posted - 2013-03-04 : 10:35:27
Apologies if this is not the right area to ask this question. Is the script code associated with a table executed when the table is first created or everytime the table is accessed at runtime?

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-03-04 : 13:48:07
Not sure what you meant by "script code associated with a table". You would use a script (or the SSMS GUI, which behind the scenes uses a script) to create a table. For example:
CREATE TABLE dbo.MyTestTable (id INT, val VARCHAR(32));
You run that script only once - which creates the table object. Once that table object is created, it is there for you to use - you can insert, update, delete, and select data into/from it.

Think of a table as a container that you create. Then you may insert rows into that container, take them out, or look into it or modify them.

If that does not answer your question, can you explain what you meant?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-05 : 00:01:08
or are you referring to trigger code you created on the table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

samyer
Starting Member

15 Posts

Posted - 2013-03-05 : 10:13:30
If I right-click on a table and choose 'Script Table as..', then 'CREATE to', then 'New Query Editor Window' I will see code associated with the table. It appears that the code was used to create the table, and what gets executed when you select EXECUTE. I guess my question is, is this code executed whenever a program accesses the table or updates a table?

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-05 : 10:17:25
nope..this code was executed when table was first created. When a program accesses a table it executes SELECT,INSERT,UPDATE and DELETE statements (DML operations) and not CREATE (DDL operation)

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2013-03-05 : 10:18:01
No

Cheers
MIK
Go to Top of Page

samyer
Starting Member

15 Posts

Posted - 2013-03-05 : 10:37:43
Thanks guys!!!
Go to Top of Page
   

- Advertisement -