将下面任务中的T-SQL代码形成一个脚本:在test_db数据库中创建表person并插入如下元祖, 使用整型局部变量mycount统计person中的行数,并将其另命名为数据表中的行数。
时间: 2024-04-08 08:30:27 浏览: 51
T-SQL数据库脚本
5星 · 资源好评率100%
Sure! Here's the T-SQL script to create the table "person" in the "test_db" database, insert the given tuples, and use a local integer variable "mycount" to count the number of rows in the "person" table and assign it to a variable named "row_count".
```sql
-- Create table "person"
USE test_db;
GO
CREATE TABLE person (
id INT,
name VARCHAR(50),
age INT
);
-- Insert tuples into "person" table
INSERT INTO person (id, name, age)
VALUES
(1, 'John', 25),
(2, 'Sarah', 30),
(3, 'Michael', 35);
-- Use local variable to count rows in "person" table
DECLARE @mycount INT;
SELECT @mycount = COUNT(*) FROM person;
-- Assign the row count to a variable named "row_count"
DECLARE @row_count INT;
SET @row_count = @mycount;
-- Display the row count
SELECT @row_count AS [Row Count];
```
Please note that this script assumes you have the necessary permissions to create a table and insert data into the database. Adjust the script accordingly if needed.
阅读全文